jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1226146 - /jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
Date Sat, 31 Dec 2011 17:33:44 GMT
Author: mduerig
Date: Sat Dec 31 17:33:43 2011
New Revision: 1226146

URL: http://svn.apache.org/viewvc?rev=1226146&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- refactor move operation

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.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=1226146&r1=1226145&r2=1226146&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
Sat Dec 31 17:33:43 2011
@@ -487,28 +487,7 @@ public class ChangeTree {
                 throw new PathNotFoundException(destParentPath.toJcrPath());
             }
 
-            Removed removed;
-            if (source.isTransient()) {  // fixme: can't this go into the moveTo methods?
-                removed = null;
-                removeChild(name);
-            }
-            else {
-                removed = new Removed(this, name);
-                addChild(removed);
-            }
-
-            // Resolve destination only *after* source has been removed in order
-            // to make sure nodes on any common path prefix are already touched.
-            NodeDelta destParent = ChangeTree.this.getNode(destParentPath);
-            if (destParent == null) {
-                // fixme: throwing after tree modification leads to inconsistencies. check
upfront!
-                // can this even be null here? there seems to be a check above already
-                throw new PathNotFoundException(destination.toJcrPath());
-            }
-            NodeDelta movedTo = source.moveTo(destParent, destination.getName());
-            if (removed != null) {
-                removed.setMoved(movedTo);
-            }
+            source.moveTo(destParentPath, destination.getName());
         }
 
         /**
@@ -532,7 +511,7 @@ public class ChangeTree {
         void touch() { }
 
         abstract NodeDelta remove() throws ItemNotFoundException;
-        abstract NodeDelta moveTo(NodeDelta parent, String name);
+        abstract void moveTo(Path parentPath, String name);
 
         NodeDelta addChild(NodeDelta delta) {
             childNodes.put(delta.name, delta);
@@ -640,12 +619,16 @@ public class ChangeTree {
                     child.remove();
                 }
             }
-            return parent.addChild(new Removed(parent, name));
+            return parent.addChild(new Removed(parent, name, null));
         }
 
         @Override
-        NodeDelta moveTo(NodeDelta parent, String name) {
-            return parent.addChild(new Moved(parent, name, this));
+        void moveTo(Path parentPath, String name) {
+            Moved movedTo = new Moved(parent, name, this);
+            Removed removed = new Removed(parent, this.name, movedTo);
+            parent.addChild(removed);
+            NodeDelta parent = ChangeTree.this.getNode(parentPath);
+            parent.addChild(movedTo);
         }
     }
 
@@ -693,9 +676,11 @@ public class ChangeTree {
         }
 
         @Override
-        NodeDelta moveTo(NodeDelta parent, String name) {
+        void moveTo(Path parentPath, String name) {
+            parent.removeChild(this.name);
+            NodeDelta destParent = ChangeTree.this.getNode(parentPath);
             this.name = name;
-            return parent.addChild(this);
+            destParent.addChild(this);
         }
     }
 
@@ -795,9 +780,11 @@ public class ChangeTree {
         }
 
         @Override
-        NodeDelta moveTo(NodeDelta parent, String name) {
+        void moveTo(Path parentPath, String name) {
+            parent.removeChild(this.name);
+            NodeDelta destParent = ChangeTree.this.getNode(parentPath);
             this.name = name;
-            return parent.addChild(this);
+            destParent.addChild(this);
         }
     }
 
@@ -805,13 +792,10 @@ public class ChangeTree {
      * Represents a transiently removed node.
      */
     public class Removed extends NodeDelta {
-        private NodeDelta movedTo;
+        private final NodeDelta movedTo;
 
-        Removed(NodeDelta parent, String name) {
+        Removed(NodeDelta parent, String name, NodeDelta movedTo) {
             super(parent, name);
-        }
-
-        public void setMoved(NodeDelta movedTo) {
             this.movedTo = movedTo;
         }
 
@@ -866,7 +850,7 @@ public class ChangeTree {
         }
 
         @Override
-        NodeDelta moveTo(NodeDelta parent, String name) {
+        void moveTo(Path parentPath, String name) {
             throw new IllegalStateException("Removed");
         }
 



Mime
View raw message