jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1455226 - in /jackrabbit/oak/trunk/oak-mongomk/src: main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
Date Mon, 11 Mar 2013 16:39:29 GMT
Author: thomasm
Date: Mon Mar 11 16:39:29 2013
New Revision: 1455226

URL: http://svn.apache.org/r1455226
Log:
OAK-619 Lock-free MongoMK implementation (support the copy operation)

Modified:
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
    jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
    jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java?rev=1455226&r1=1455225&r2=1455226&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/Commit.java
Mon Mar 11 16:39:29 2013
@@ -317,6 +317,10 @@ public class Commit {
     public void moveNode(String sourcePath, String targetPath) {
         diff.tag('>').key(sourcePath).value(targetPath);
     }
+    
+    public void copyNode(String sourcePath, String targetPath) {
+        diff.tag('*').key(sourcePath).value(targetPath);
+    }
 
     public JsopWriter getDiff() {
         return diff;

Modified: jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java?rev=1455226&r1=1455225&r2=1455226&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/main/java/org/apache/jackrabbit/mongomk/prototype/MongoMK.java
Mon Mar 11 16:39:29 2013
@@ -538,6 +538,7 @@ public class MongoMK implements MicroKer
                 commit.updatePropertyDiff(p, propertyName, value);
                 break;
             case '>': {
+                // TODO support moving nodes that were modified within this commit
                 t.read(':');
                 String sourcePath = path;
                 String targetPath = t.readString();
@@ -549,14 +550,15 @@ public class MongoMK implements MicroKer
                 break;
             }
             case '*': {
-                // TODO possibly support target position notation
+                // TODO support copying nodes that were modified within this commit
                 t.read(':');
-                String target = t.readString();
-                if (!PathUtils.isAbsolute(target)) {
-                    target = PathUtils.concat(rootPath, target);
+                String sourcePath = path;
+                String targetPath = t.readString();
+                if (!PathUtils.isAbsolute(targetPath)) {
+                    targetPath = PathUtils.concat(path, targetPath);
                 }
-                String to = PathUtils.relativize("/", target);
-                // TODO support copy operations
+                commit.copyNode(sourcePath, targetPath);
+                copyNode(sourcePath, targetPath, commit);
                 break;
             }
             default:
@@ -581,7 +583,15 @@ public class MongoMK implements MicroKer
         return rev.toString();
     }
 
+    private void copyNode(String sourcePath, String targetPath, Commit commit) {
+        moveOrCopyNode(false, sourcePath, targetPath, commit);
+    }
+    
     private void moveNode(String sourcePath, String targetPath, Commit commit) {
+        moveOrCopyNode(true, sourcePath, targetPath, commit);
+    }
+    
+    private void moveOrCopyNode(boolean move, String sourcePath, String targetPath, Commit
commit) {
         // TODO Optimize - Move logic would not work well with very move of very large subtrees
         // At minimum we can optimize by traversing breadth wise and collect node id
         // and fetch them via '$in' queries
@@ -601,13 +611,15 @@ public class MongoMK implements MicroKer
         n.copyTo(newNode);
 
         commit.addNode(newNode);
-        markAsDeleted(sourcePath, commit, false);
+        if (move) {
+            markAsDeleted(sourcePath, commit, false);
+        }
         Node.Children c = readChildren(sourcePath, n.getId(),
                 commit.getRevision(), Integer.MAX_VALUE);
         for (String srcChildPath : c.children) {
             String childName = PathUtils.getName(srcChildPath);
             String destChildPath = PathUtils.concat(targetPath, childName);
-            moveNode(srcChildPath, destChildPath, commit);
+            moveOrCopyNode(move, srcChildPath, destChildPath, commit);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java?rev=1455226&r1=1455225&r2=1455226&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
(original)
+++ jackrabbit/oak/trunk/oak-mongomk/src/test/java/org/apache/jackrabbit/mongomk/prototype/SimpleTest.java
Mon Mar 11 16:39:29 2013
@@ -135,6 +135,30 @@ public class SimpleTest {
         assertEquals("{\":childNodeCount\":0}", test);
         mk.dispose();
     }
+    
+    @Test
+    public void move() {
+        MongoMK mk = createMK();
+        String rev = mk.commit("/", "+\"test\":{\"x\":\"1\",\"child\": {}}", null, null);
+        rev = mk.commit("/", ">\"test\": \"/test2\"", rev, null);
+        String test = mk.getNodes("/test2", rev, 0, 0, Integer.MAX_VALUE, null);
+        assertEquals("{\"x\":\"1\",\"child\":{},\":childNodeCount\":1}", test);
+        test = mk.getNodes("/test", rev, 0, 0, Integer.MAX_VALUE, null);
+        assertNull(test);
+        mk.dispose();
+    }
+    
+    @Test
+    public void copy() {
+        MongoMK mk = createMK();
+        String rev = mk.commit("/", "+\"test\":{\"x\":\"1\",\"child\": {}}", null, null);
+        rev = mk.commit("/", "*\"test\": \"/test2\"", rev, null);
+        String test = mk.getNodes("/test2", rev, 0, 0, Integer.MAX_VALUE, null);
+        assertEquals("{\"x\":\"1\",\"child\":{},\":childNodeCount\":1}", test);
+        test = mk.getNodes("/test", rev, 0, 0, Integer.MAX_VALUE, null);
+        assertEquals("{\"x\":\"1\",\"child\":{},\":childNodeCount\":1}", test);
+        mk.dispose();
+    }
 
     @Test
     public void escapePropertyName() {



Mime
View raw message