jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1226428 - in /jackrabbit/sandbox/jackrabbit-microkernel/src: main/java/org/apache/jackrabbit/state/ChangeTree.java test/java/org/apache/jackrabbit/state/TransientSpaceTest.java
Date Mon, 02 Jan 2012 14:09:49 GMT
Author: mduerig
Date: Mon Jan  2 14:09:48 2012
New Revision: 1226428

URL: http://svn.apache.org/viewvc?rev=1226428&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- remove after move causes exception: 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=1226428&r1=1226427&r2=1226428&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
Mon Jan  2 14:09:48 2012
@@ -29,7 +29,6 @@ import org.apache.jackrabbit.utils.Predi
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.PathNotFoundException;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -264,6 +263,9 @@ public class ChangeTree {
                     delta.movedTo.accept(this);
                 }
                 else {
+                    // Visit parents of removed before visiting remove
+                    visitParent(delta.removed);
+                    delta.removed.accept(this);
                     listener.removeNode(delta.getPath());
                     visited.add(delta);
                 }
@@ -633,25 +635,13 @@ public class ChangeTree {
 
         @Override
         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.
-            ArrayList<NodeDelta> r = new ArrayList<NodeDelta>();
-            for (NodeDelta child : childNodes()) {
-                // Ignore removed and added nodes
-                if (!child.isRemoved() && (!child.isTransient() || child.isMoved()))
{
-                    r.add(child);
-                }
-            }
-            for (NodeDelta child : r) {
-                child.remove();
-            }
-            return parent.addChild(new Removed(parent, name, null));
+            return parent.addChild(new Removed(parent, name, this, null));
         }
 
         @Override
         void moveTo(Path parentPath, String name) {
             Moved movedTo = new Moved(parent, name, this);
-            Removed removed = new Removed(parent, this.name, movedTo);
+            Removed removed = new Removed(parent, this.name, this, movedTo);
             parent.addChild(removed);
             NodeDelta parent = ChangeTree.this.getNode(parentPath);
             parent.addChild(movedTo);
@@ -795,10 +785,12 @@ public class ChangeTree {
      * Represents a transiently removed node.
      */
     public class Removed extends NodeDelta {
+        private final NodeDelta removed;
         private final NodeDelta movedTo;
 
-        Removed(NodeDelta parent, String name, NodeDelta movedTo) {
+        Removed(NodeDelta parent, String name, NodeDelta removed, NodeDelta movedTo) {
             super(parent, name);
+            this.removed = removed;
             this.movedTo = movedTo;
         }
 

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=1226428&r1=1226427&r2=1226428&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
Mon Jan  2 14:09:48 2012
@@ -22,6 +22,7 @@ import org.hamcrest.Description;
 import org.hamcrest.Matcher;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.internal.matchers.TypeSafeMatcher;
 
@@ -149,6 +150,75 @@ public class TransientSpaceTest {
         added.removeNode("added2");
     }
 
+    @Test @Ignore("WIP")
+    public void removeAndAddAgain() throws RepositoryException {
+        NodeDelta root = transientSpace.getNode(ROOT);
+        root.addNode("a").addNode("b");
+        transientSpace.save();
+
+        root.removeNode("a");
+        assertFalse(root.hasNode("a"));
+
+        root.addNode("a");
+        assertTrue(root.hasNode("a"));
+        assertFalse(root.getNode("a").hasNode("b"));
+
+        root.removeNode("a");
+        assertFalse(root.hasNode("a"));
+
+        root.addNode("a");
+        assertTrue(root.hasNode("a"));
+        assertFalse(root.getNode("a").hasNode("b"));
+
+        transientSpace.save();
+        assertTrue(root.hasNode("a"));
+        assertFalse(root.getNode("a").hasNode("b"));
+    }
+
+    @Test @Ignore("WIP")
+    public void moveAndAddAgain() throws RepositoryException {
+        NodeDelta root = transientSpace.getNode(ROOT);
+        root.addNode("a").addNode("b");
+        transientSpace.save();
+
+        root.moveNode("a", ROOT.concat("am1"));
+        assertFalse(root.hasNode("a"));
+
+        root.addNode("a");
+        assertTrue(root.hasNode("a"));
+        assertFalse(root.getNode("a").hasNode("b"));
+
+        root.moveNode("a", ROOT.concat("am2"));
+        assertFalse(root.hasNode("a"));
+
+        root.addNode("a");
+        assertTrue(root.hasNode("a"));
+        assertFalse(root.getNode("a").hasNode("b"));
+
+        transientSpace.save();
+        assertTrue(root.hasNode("a"));
+        assertFalse(root.getNode("a").hasNode("b"));
+    }
+
+    @Test
+    public void removeAfterMove() throws RepositoryException {
+        NodeDelta root = transientSpace.getNode(ROOT);
+        root.addNode("a").addNode("b");
+        root.addNode("x");
+        transientSpace.save();
+
+        root.getNode("a").moveNode("b", ROOT.concat("x/bm"));
+        root.removeNode("a");
+
+        assertNull(root.getNode("a"));
+        assertNotNull(transientSpace.getNode(ROOT.concat("x/bm")));
+
+        transientSpace.save();
+
+        assertNull(root.getNode("a"));
+        assertNotNull(transientSpace.getNode(ROOT.concat("x/bm")));
+    }
+
     @Test
     public void moveTransient() throws RepositoryException {
         NodeDelta root = transientSpace.getNode(ROOT);



Mime
View raw message