jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1466868 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/ test/java/org/apache/jackrabbit/mongomk/
Date Thu, 11 Apr 2013 12:57:11 GMT
Author: thomasm
Date: Thu Apr 11 12:57:11 2013
New Revision: 1466868

URL: http://svn.apache.org/r1466868
Log:
OAK-619 MongoMK: rename operations on documents

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Commit.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoDocumentStore.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Node.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/UpdateOp.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/SimpleTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Commit.java?rev=1466868&r1=1466867&r2=1466868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Commit.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Commit.java
Thu Apr 11 12:57:11 2013
@@ -92,14 +92,14 @@ public class Commit {
     
     public void touchNode(String path) {
         UpdateOp op = getUpdateOperationForNode(path);
-        op.setMapEntry(UpdateOp.LAST_REV + "." + revision.getClusterId(), revision.toString());
       
+        op.setMapEntry(UpdateOp.LAST_REV, "" + revision.getClusterId(), revision.toString());
       
     }
     
     void updateProperty(String path, String propertyName, String value) {
         UpdateOp op = getUpdateOperationForNode(path);
         String key = Utils.escapePropertyName(propertyName);
-        op.addMapEntry(key + "." + revision.toString(), value);
-        op.setMapEntry(UpdateOp.LAST_REV + "." + revision.getClusterId(), revision.toString());
       
+        op.setMapEntry(key, revision.toString(), value);
+        op.setMapEntry(UpdateOp.LAST_REV, "" + revision.getClusterId(), revision.toString());
       
     }
 
     void addNode(Node n) {
@@ -175,14 +175,14 @@ public class Commit {
         UpdateOp commitRoot = getUpdateOperationForNode(commitRootPath);
         for (String p : operations.keySet()) {
             UpdateOp op = operations.get(p);
-            op.setMapEntry(UpdateOp.LAST_REV + "." + revision.getClusterId(), revision.toString());
+            op.setMapEntry(UpdateOp.LAST_REV, "" + revision.getClusterId(), revision.toString());
             if (op.isNew) {
-                op.addMapEntry(UpdateOp.DELETED + "." + revision.toString(), "false");
+                op.setMapEntry(UpdateOp.DELETED, revision.toString(), "false");
             }
             if (op == commitRoot) {
                 // apply at the end
             } else {
-                op.addMapEntry(UpdateOp.COMMIT_ROOT + "." + revision.toString(), commitRootDepth);
+                op.setMapEntry(UpdateOp.COMMIT_ROOT, revision.toString(), commitRootDepth);
                 if (op.isNew()) {
                     newNodes.add(op);
                 } else {
@@ -194,7 +194,7 @@ public class Commit {
             // no updates and root of commit is also new. that is,
             // it is the root of a subtree added in a commit.
             // so we try to add the root like all other nodes
-            commitRoot.addMapEntry(UpdateOp.REVISIONS + "." + revision.toString(), commitValue);
+            commitRoot.setMapEntry(UpdateOp.REVISIONS, revision.toString(), commitValue);
             newNodes.add(commitRoot);
         }
         try {
@@ -207,7 +207,7 @@ public class Commit {
                         if (op == commitRoot) {
                             // don't write the commit root just yet
                             // (because there might be a conflict)
-                            commitRoot.unset(UpdateOp.REVISIONS + "." + revision.toString());
+                            commitRoot.unsetMapEntry(UpdateOp.REVISIONS, revision.toString());
                         }
                         changedNodes.add(op);
                     }
@@ -216,7 +216,7 @@ public class Commit {
             }
             for (UpdateOp op : changedNodes) {
                 // set commit root on changed nodes
-                op.addMapEntry(UpdateOp.COMMIT_ROOT + "." + revision.toString(), commitRootDepth);
+                op.setMapEntry(UpdateOp.COMMIT_ROOT, revision.toString(), commitRootDepth);
                 done.add(op);
                 createOrUpdateNode(store, op);
             }
@@ -225,7 +225,7 @@ public class Commit {
             // first to check if there was a conflict, and only then to commit
             // the revision, with the revision property set)
             if (changedNodes.size() > 0 || !commitRoot.isNew) {
-                commitRoot.addMapEntry(UpdateOp.REVISIONS + "." + revision.toString(), commitValue);
+                commitRoot.setMapEntry(UpdateOp.REVISIONS, revision.toString(), commitValue);
                 done.add(commitRoot);
                 createOrUpdateNode(store, commitRoot);
                 operations.put(commitRootPath, commitRoot);
@@ -323,7 +323,7 @@ public class Commit {
                 // ok
             } else if (key.equals(UpdateOp.LAST_REV)) {
                 // only maintain the lastRev in the main document
-                main.setMapEntry(UpdateOp.LAST_REV + "." + revision.getClusterId(), revision.toString());
       
+                main.setMap(UpdateOp.LAST_REV, "" + revision.getClusterId(), revision.toString());
       
             } else {
                 // UpdateOp.DELETED,
                 // UpdateOp.REVISIONS,
@@ -341,9 +341,9 @@ public class Commit {
                     Revision propRev = Revision.fromString(r);
                     Object v = valueMap.get(r);
                     if (propRev.equals(latestRev)) {
-                        main.setMapEntry(key + "." + propRev.toString(), v);
+                        main.setMap(key, propRev.toString(), v);
                     } else {
-                        old.addMapEntry(key + "." + propRev.toString(), v);
+                        old.setMapEntry(key, propRev.toString(), v);
                     }
                 }
             }
@@ -431,8 +431,8 @@ public class Commit {
         removedNodes.add(path);
         UpdateOp op = getUpdateOperationForNode(path);
         op.setDelete(true);
-        op.addMapEntry(UpdateOp.DELETED + "." + revision.toString(), "true");
-        op.setMapEntry(UpdateOp.LAST_REV + "." + revision.getClusterId(), revision.toString());
+        op.setMapEntry(UpdateOp.DELETED, revision.toString(), "true");
+        op.setMapEntry(UpdateOp.LAST_REV, "" + revision.getClusterId(), revision.toString());
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java?rev=1466868&r1=1466867&r2=1466868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MemoryDocumentStore.java
Thu Apr 11 12:57:11 2013
@@ -164,7 +164,7 @@ public class MemoryDocumentStore impleme
                 target.put(k, ((Long) old) + x);
                 break;
             }
-            case ADD_MAP_ENTRY: {
+            case SET_MAP_ENTRY: {
                 Object old = target.get(kv[0]);
                 @SuppressWarnings("unchecked")
                 Map<String, Object> m = (Map<String, Object>) old;
@@ -184,7 +184,7 @@ public class MemoryDocumentStore impleme
                 }
                 break;
             }
-            case SET_MAP_ENTRY: {
+            case SET_MAP: {
                 Object old = target.get(kv[0]);
                 @SuppressWarnings("unchecked")
                 Map<String, Object> m = (Map<String, Object>) old;

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoDocumentStore.java?rev=1466868&r1=1466867&r2=1466868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoDocumentStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/MongoDocumentStore.java
Thu Apr 11 12:57:11 2013
@@ -226,7 +226,7 @@ public class MongoDocumentStore implemen
                     incUpdates.append(k, op.value);
                     break;
                 }
-                case ADD_MAP_ENTRY: {
+                case SET_MAP_ENTRY: {
                     setUpdates.append(k, op.value);
                     break;
                 }
@@ -234,7 +234,7 @@ public class MongoDocumentStore implemen
                     unsetUpdates.append(k, "1");
                     break;
                 }
-                case SET_MAP_ENTRY: {
+                case SET_MAP: {
                     String[] kv = k.split("\\.");
                     BasicDBObject sub = new BasicDBObject();
                     sub.put(kv[1], op.value);
@@ -309,8 +309,8 @@ public class MongoDocumentStore implemen
                         inserts[i].put(k, op.value);
                         break;
                     }
-                    case SET_MAP_ENTRY:
-                    case ADD_MAP_ENTRY: {
+                    case SET_MAP:
+                    case SET_MAP_ENTRY: {
                         String[] kv = k.split("\\.");
                         DBObject value = new BasicDBObject(kv[1], op.value);
                         inserts[i].put(kv[0], value);

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Node.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Node.java?rev=1466868&r1=1466867&r2=1466868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Node.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/Node.java
Thu Apr 11 12:57:11 2013
@@ -74,11 +74,11 @@ public class Node {
         String id = Utils.getIdFromPath(path);
         UpdateOp op = new UpdateOp(path, id, isNew);
         op.set(UpdateOp.ID, id);
-        op.addMapEntry(UpdateOp.DELETED + "." + rev.toString(), "false");
-        op.setMapEntry(UpdateOp.LAST_REV + "." + rev.getClusterId(), rev.toString());
+        op.setMapEntry(UpdateOp.DELETED, rev.toString(), "false");
+        op.setMapEntry(UpdateOp.LAST_REV, "" + rev.getClusterId(), rev.toString());
         for (String p : properties.keySet()) {
             String key = Utils.escapePropertyName(p);
-            op.addMapEntry(key + "." + rev.toString(), properties.get(p));
+            op.setMapEntry(key, rev.toString(), properties.get(p));
         }
         return op;
     }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/UpdateOp.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/UpdateOp.java?rev=1466868&r1=1466867&r2=1466868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/UpdateOp.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/UpdateOp.java
Thu Apr 11 12:57:11 2013
@@ -106,33 +106,50 @@ public class UpdateOp {
     }
     
     /**
-     * Add a new map entry for this revision.
+     * Add a new or update an existing map entry.
+     * The property is a map of sub-names / values.
      * 
      * @param property the property
+     * @param subName the entry name
      * @param value the value
      */
-    void addMapEntry(String property, Object value) {
+    void setMapEntry(String property, String subName, Object value) {
         Operation op = new Operation();
-        op.type = Operation.Type.ADD_MAP_ENTRY;
+        op.type = Operation.Type.SET_MAP_ENTRY;
         op.value = value;
-        changes.put(property, op);
+        changes.put(property + "." + subName, op);
     }
     
-    public void removeMapEntry(String property) {
+    /**
+     * Remove a map entry.
+     * The property is a map of sub-names / values.
+     * 
+     * @param property the property
+     * @param subName the entry name
+     */
+    public void removeMapEntry(String property, String subName) {
         Operation op = new Operation();
         op.type = Operation.Type.REMOVE_MAP_ENTRY;
-        changes.put(property, op);
+        changes.put(property + "." + subName, op);
     }
     
-    public void setMapEntry(String property, Object value) {
+    /**
+     * Set a map to a single key-value pair.
+     * The property is a map of sub-names / values.
+     * 
+     * @param property the property
+     * @param subName the entry name
+     * @param value the value
+     */
+    public void setMap(String property, String subName, Object value) {
         Operation op = new Operation();
-        op.type = Operation.Type.SET_MAP_ENTRY;
+        op.type = Operation.Type.SET_MAP;
         op.value = value;
-        changes.put(property, op);
+        changes.put(property + "." + subName, op);
     }
     
     /**
-     * Set the property.
+     * Set the property to the given value.
      * 
      * @param property the property name
      * @param value the value
@@ -152,6 +169,17 @@ public class UpdateOp {
     void unset(String property) {
         changes.remove(property);
     }
+    
+    /**
+     * Do not set the property entry (after it has been set).
+     * The property is a map of sub-names / values.
+     * 
+     * @param property the property name
+     * @param subName the entry name
+     */
+    void unsetMapEntry(String property, String subName) {
+        changes.remove(property + "." + subName);
+    }
 
     /**
      * Increment the value.
@@ -218,7 +246,7 @@ public class UpdateOp {
              * Add the sub-key / value pair.
              * The value in the stored node is a map.
              */ 
-             ADD_MAP_ENTRY, 
+             SET_MAP_ENTRY, 
              
              /**
               * Remove the sub-key / value pair.
@@ -230,7 +258,7 @@ public class UpdateOp {
               * Set the sub-key / value pair.
               * The value in the stored node is a map.
               */
-             SET_MAP_ENTRY,
+             SET_MAP,
              
          }
              
@@ -259,10 +287,10 @@ public class UpdateOp {
                 break;
             case SET:
             case REMOVE_MAP_ENTRY:
-            case SET_MAP_ENTRY:
+            case SET_MAP:
                 // nothing to do
                 break;
-            case ADD_MAP_ENTRY:
+            case SET_MAP_ENTRY:
                 reverse = new Operation();
                 reverse.type = Type.REMOVE_MAP_ENTRY;
                 break;

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java?rev=1466868&r1=1466867&r2=1466868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/MongoDocumentStoreTest.java
Thu Apr 11 12:57:11 2013
@@ -69,7 +69,7 @@ public class MongoDocumentStoreTest {
         DocumentStore docStore = openDocumentStore();
 
         UpdateOp updateOp = new UpdateOp("/", "/", true);
-        updateOp.addMapEntry("property1.key1", "value1");
+        updateOp.setMapEntry("property1", "key1", "value1");
         updateOp.increment("property2", 1);
         updateOp.set("property3", "value3");
         docStore.createOrUpdate(Collection.NODES, updateOp);
@@ -102,7 +102,7 @@ public class MongoDocumentStoreTest {
             String path = "/node" + i;
             UpdateOp updateOp = new UpdateOp(path, path, true);
             updateOp.set(UpdateOp.ID, "/node" + i);
-            updateOp.addMapEntry("property1.key1", "value1");
+            updateOp.setMapEntry("property1", "key1", "value1");
             updateOp.increment("property2", 1);
             updateOp.set("property3", "value3");
             updateOps.add(updateOp);
@@ -214,7 +214,7 @@ public class MongoDocumentStoreTest {
             for (int i = 0; i < nNodes; i++) {
                 String path = "/" + nodeName + i;
                 UpdateOp updateOp = new UpdateOp(path, path, true);
-                updateOp.addMapEntry("property1.key1", "value1");
+                updateOp.setMapEntry("property1", "key1", "value1");
                 updateOp.set("property3", "value3");
                 docStore.createOrUpdate(Collection.NODES, updateOp);
             }
@@ -224,7 +224,7 @@ public class MongoDocumentStoreTest {
             for (int i = 0; i < nNodes; i++) {
                 String path = "/" + nodeName + i;
                 UpdateOp updateOp = new UpdateOp(path, path, false);
-                updateOp.addMapEntry("property1.key2", "value2");
+                updateOp.setMapEntry("property1", "key2", "value2");
                 updateOp.set("property4", "value4");
                 docStore.createOrUpdate(Collection.NODES, updateOp);
             }

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/SimpleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/SimpleTest.java?rev=1466868&r1=1466867&r2=1466868&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/SimpleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/SimpleTest.java
Thu Apr 11 12:57:11 2013
@@ -27,6 +27,7 @@ import java.util.Map;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mongomk.DocumentStore.Collection;
 import org.apache.jackrabbit.mongomk.Node.Children;
+import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.common.collect.Lists;
@@ -86,7 +87,7 @@ public class SimpleTest {
         n.setProperty("name", "Hello");
         UpdateOp op = n.asOperation(true);
         // mark as commit root
-        op.addMapEntry(UpdateOp.REVISIONS + "." + rev, "true");
+        op.setMapEntry(UpdateOp.REVISIONS, rev.toString(), "true");
         DocumentStore s = mk.getDocumentStore();
         assertTrue(s.create(Collection.NODES, Lists.newArrayList(op)));
         Node n2 = mk.getNode("/test", rev);
@@ -268,7 +269,7 @@ public class SimpleTest {
     }
 
     @Test
-    public void testDeletion() {
+    public void delete() {
         MongoMK mk = createMK();
 
         mk.commit("/", "+\"testDel\":{\"name\": \"Hello\"}", null, null);
@@ -289,6 +290,31 @@ public class SimpleTest {
         Node n = mk.getNode("/testDel", Revision.fromString(r3));
         assertNull(n);
     }
+    
+    @Test
+    @Ignore
+    // OAK-771 (WIP)
+    public void nodeAndPropertyNames() {
+        MongoMK mk = createMK();
+
+        mk.commit("/", "+\"0\":{\"name\": \"Hello\"}", null, null);
+        mk.commit("/testDel", "+\"a\":{\"name\": \"World\"}", null, null);
+        mk.commit("/testDel", "+\"b\":{\"name\": \"!\"}", null, null);
+        String r1 = mk.commit("/testDel", "+\"c\":{\"name\": \"!\"}", null, null);
+
+        Children c = mk.getChildren("/testDel", Revision.fromString(r1),
+                Integer.MAX_VALUE);
+        assertEquals(3, c.children.size());
+
+        String r2 = mk.commit("/testDel", "-\"c\"", null, null);
+        c = mk.getChildren("/testDel", Revision.fromString(r2),
+                Integer.MAX_VALUE);
+        assertEquals(2, c.children.size());
+
+        String r3 = mk.commit("/", "-\"testDel\"", null, null);
+        Node n = mk.getNode("/testDel", Revision.fromString(r3));
+        assertNull(n);
+    }
 
     @Test
     public void addAndMove() {



Mime
View raw message