jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1225820 - in /jackrabbit/sandbox/jackrabbit-microkernel/src: main/java/org/apache/jackrabbit/state/ChangeTree.java test/java/org/apache/jackrabbit/state/TransientSpaceTest.java
Date Fri, 30 Dec 2011 13:17:13 GMT
Author: mduerig
Date: Fri Dec 30 13:17:12 2011
New Revision: 1225820

URL: http://svn.apache.org/viewvc?rev=1225820&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- removing the parent of the target of a move operation results in the source of move operation
to not being removed: fixed

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java?rev=1225820&r1=1225819&r2=1225820&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
Fri Dec 30 13:17:12 2011
@@ -613,7 +613,15 @@ public class ChangeTree {
         }
 
         @Override
-        NodeDelta remove() {
+        NodeDelta remove() throws ItemNotFoundException {
+            // Propagate remove down the tree in order to convert move operations
+            // into this sub-tree to remove operations at the move's source node.
+            for (NodeDelta child : childNodes()) {
+                // Ignore removed and added nodes
+                if (!child.isRemoved() && (!child.isTransient() || child.isMoved()))
{
+                    child.remove();
+                }
+            }
             return parent.addChild(new Removed(parent, name, false));
         }
 

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java?rev=1225820&r1=1225819&r2=1225820&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/state/TransientSpaceTest.java
Fri Dec 30 13:17:12 2011
@@ -11,7 +11,12 @@ import org.apache.jackrabbit.mk.MicroKer
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.mk.store.NotFoundException;
+import org.apache.jackrabbit.state.ChangeTree.Added;
+import org.apache.jackrabbit.state.ChangeTree.Existing;
+import org.apache.jackrabbit.state.ChangeTree.Moved;
 import org.apache.jackrabbit.state.ChangeTree.NodeDelta;
+import org.apache.jackrabbit.state.ChangeTree.Removed;
+import org.apache.jackrabbit.state.ChangeTree.Visitor;
 import org.hamcrest.CoreMatchers;
 import org.hamcrest.Description;
 import org.hamcrest.Matcher;
@@ -724,6 +729,47 @@ public class TransientSpaceTest {
     }
 
     @Test
+    public void removeMoved() throws RepositoryException {
+        NodeDelta root = transientSpace.getNode(ROOT);
+        root.addNode("source").addNode("node");
+        root.addNode("target");
+        transientSpace.save();
+
+        root.getNode("source").moveNode("node", ROOT.concat("target/moved"));
+        root.removeNode("target");
+
+        assertNotNull(transientSpace.getNode(ROOT.concat("source")));
+        assertNull(transientSpace.getNode(ROOT.concat("source/node")));
+        assertNull(transientSpace.getNode(ROOT.concat("target")));
+
+        transientSpace.save();
+
+        assertNotNull(transientSpace.getNode(ROOT.concat("source")));
+        assertNull(transientSpace.getNode(ROOT.concat("source/node")));
+        assertNull(transientSpace.getNode(ROOT.concat("target")));
+    }
+
+    @Test
+    public void removeMovedTransient() throws RepositoryException {
+        NodeDelta root = transientSpace.getNode(ROOT);
+        root.addNode("source").addNode("node");
+        root.addNode("target");
+
+        root.getNode("source").moveNode("node", ROOT.concat("target/moved"));
+        root.removeNode("target");
+
+        assertNotNull(transientSpace.getNode(ROOT.concat("source")));
+        assertNull(transientSpace.getNode(ROOT.concat("source/node")));
+        assertNull(transientSpace.getNode(ROOT.concat("target")));
+
+        transientSpace.save();
+
+        assertNotNull(transientSpace.getNode(ROOT.concat("source")));
+        assertNull(transientSpace.getNode(ROOT.concat("source/node")));
+        assertNull(transientSpace.getNode(ROOT.concat("target")));
+    }
+
+    @Test
     public void setPropertyTest() throws RepositoryException {
         // Set property
         NodeDelta root = transientSpace.getNode(ROOT);
@@ -779,7 +825,9 @@ public class TransientSpaceTest {
         assertTrue(root.getNode("test").hasNode("c2"));
     }
 
-    public static class MicrokernelMatcher {
+    //------------------------------------------< internal >---
+    
+    static class MicrokernelMatcher {
         private MicrokernelMatcher() { }
 
         public static Matcher<MicroKernel> propertyHasValue(final Path path, final
int value) {
@@ -852,4 +900,45 @@ public class TransientSpaceTest {
         }
     }
 
+    /* Debugging */
+    @SuppressWarnings("UseOfSystemOutOrSystemErr")
+    private static void dump(NodeDelta delta) {
+        delta.accept(new Visitor() {
+            private String ident = "";
+            
+
+            @Override
+            public void visit(Existing delta) {
+                System.out.println(ident + delta.getName() + ":E");
+                visitChildren(delta);
+            }
+
+            @Override
+            public void visit(Added delta) {
+                System.out.println(ident + delta.getName() + ":A");
+                visitChildren(delta);
+            }
+
+            @Override
+            public void visit(Removed delta) {
+                System.out.println(ident + delta.getName() + (delta.isMoved() ? ":M-" : ":R"));
+                visitChildren(delta);
+            }
+
+            @Override
+            public void visit(Moved delta) {
+                System.out.println(ident + delta.getName() + ":M+");
+                visitChildren(delta);
+            }
+
+            private void visitChildren(NodeDelta delta) {
+                ident = ident + "  ";
+                for (NodeDelta child : delta.childNodes()) {
+                    child.accept(this);
+                }
+                ident = ident.substring(0, ident.length() - 2);
+            }
+            
+        });
+    }
 }



Mime
View raw message