jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1173561 - in /jackrabbit/sandbox/microkernel/src: main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
Date Wed, 21 Sep 2011 10:32:37 GMT
Author: thomasm
Date: Wed Sep 21 10:32:37 2011
New Revision: 1173561

URL: http://svn.apache.org/viewvc?rev=1173561&view=rev
Log:
Support adding a property using the + syntax (as used in the diff)

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java?rev=1173561&r1=1173560&r2=1173561&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopBuilder.java
Wed Sep 21 10:32:37 2011
@@ -237,6 +237,9 @@ public class JsopBuilder {
      * @param buff   the target buffer
      */
     public static void escape(String s, int length, StringBuilder buff) {
+        // TODO only backslashes, double quotes, and characters < 32 need to be
+        // escaped - but currently all special characters are escaped, which
+        // needs more time, memory, and storage space
         for (int i = 0; i < length; i++) {
             char c = s.charAt(i);
             switch (c) {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1173561&r1=1173560&r2=1173561&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Wed Sep 21 10:32:37 2011
@@ -173,6 +173,9 @@ public class MemoryKernelImpl implements
         // would be possible if we don't (always) return the head revision
         // TODO metadata in storage (version)
         // TODO optional read / write version in json 'api' (as comments?)
+        // TODO possibly support two phase commit
+        // TODO getJournal and getRevision don't have a path,
+        // which means we can't implement access rights using path prefixes
         if (DEBUG) {
             log("commit " + rootPath + " " + jsonDiff + " " + message);
         }
@@ -204,11 +207,20 @@ public class MemoryKernelImpl implements
             case '+':
                 t.read(':');
                 diff.appendTag("+ ").key(path);
-                // TODO support adding a property?
-                t.read('{');
-                NodeImpl n = NodeImpl.parse(nodeMap, t, rev);
-                data = data.cloneAndAddChildNode(from, false, null, n, rev);
-                n.append(diff, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, false);
+                if (t.matches('{')) {
+                    NodeImpl n = NodeImpl.parse(nodeMap, t, rev);
+                    data = data.cloneAndAddChildNode(from, false, null, n, rev);
+                    n.append(diff, Integer.MAX_VALUE, 0, Integer.MAX_VALUE, false);
+                } else {
+                    String value = t.readRawValue().trim();
+                    String nodeName = PathUtils.getParentPath(from);
+                    String propertyName = PathUtils.getName(from);
+                    if (data.getNode(nodeName).hasProperty(propertyName)) {
+                        throw ExceptionFactory.get("Property already exists: " + propertyName);
+                    }
+                    data = data.cloneAndSetProperty(from, value, rev);
+                    diff.encodedValue(value);
+                }
                 diff.newline();
                 break;
             case '-':

Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java?rev=1173561&r1=1173560&r2=1173561&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
(original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/MoveNodeTest.java
Wed Sep 21 10:32:37 2011
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.mk;
 
 import junit.framework.Assert;
+import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.junit.Before;
 import org.junit.Test;
@@ -46,6 +47,27 @@ public class MoveNodeTest extends MultiM
     }
 
     @Test
+    public void addProperty() {
+        if (url.startsWith("fs:")) {
+            return;
+        }
+
+        // add a property /test/c
+        commit("/", "+ \"test/c\": 123");
+        Assert.assertEquals("{c:123,a,b,c}", getNode("/test"));
+        assertJournal("+ \"/test/c\":123");
+
+        // duplicate add property should fail
+        try {
+            commit("/", "+ \"test/c\": 123");
+            Assert.fail();
+        } catch (MicroKernelException e) {
+            // expected
+        }
+        Assert.assertEquals("{c:123,a,b,c}", getNode("/test"));
+    }
+
+    @Test
     public void order() {
         Assert.assertEquals("{a,b,c}", getNode("/test"));
     }
@@ -60,6 +82,7 @@ public class MoveNodeTest extends MultiM
         commit("/", "> \"test/b\": \"test/b1\"");
         Assert.assertEquals("{a,b1,c}", getNode("/test"));
         assertJournal("> \"/test/b\":\"/test/b1\"");
+
         // and back
         commit("/", "> \"test/b1\": \"test/b\"");
         Assert.assertEquals("{a,b,c}", getNode("/test"));
@@ -217,6 +240,7 @@ public class MoveNodeTest extends MultiM
         s = s.replaceAll("\"", "").replaceAll(":childNodeCount:.", "");
         s = s.replaceAll("\\{\\,", "\\{").replaceAll("\\,\\}", "\\}");
         s = s.replaceAll("\\:\\{\\}", "");
+        s = s.replaceAll(",,", ",");
         return s;
     }
 



Mime
View raw message