jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1365662 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Wed, 25 Jul 2012 16:39:49 GMT
Author: mduerig
Date: Wed Jul 25 16:39:49 2012
New Revision: 1365662

URL: http://svn.apache.org/viewvc?rev=1365662&view=rev
Log:
OAK-207: TreeImpl#getStatus() never returns REMOVED

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1365662&r1=1365661&r2=1365662&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Wed Jul 25 16:39:49 2012
@@ -47,7 +47,7 @@ public class TreeImpl implements Tree, P
     /** Underlying {@code Root} of this {@code Tree} instance */
     private final RootImpl root;
 
-    /** Parent of this tree */
+    /** Parent of this tree. Null for the root and this for removed trees. */
     private TreeImpl parent;
 
     /** Name of this tree */
@@ -197,6 +197,10 @@ public class TreeImpl implements Tree, P
 
     @Override
     public Status getStatus() {
+        if (isRemoved()) {
+            return Status.REMOVED;
+        }
+
         NodeState baseState = getBaseState();
         if (baseState == null) {
             // Did not exist before, so its NEW
@@ -255,11 +259,16 @@ public class TreeImpl implements Tree, P
 
     @Override
     public boolean remove() {
+        if (isRemoved()) {
+            throw new IllegalStateException("Cannot remove removed tree");
+        }
+
         if (!isRoot() && parent.hasChild(name)) {
             NodeStateBuilder builder = parent.getNodeStateBuilder();
             builder.removeNode(name);
             parent.children.remove(name);
-            parent.root.purge();
+            parent = this;
+            root.purge();
             return true;
         } else {
             return false;
@@ -304,6 +313,10 @@ public class TreeImpl implements Tree, P
 
     @CheckForNull
     protected NodeState getBaseState() {
+        if (isRemoved()) {
+            throw new IllegalStateException("Cannot get the base state of a removed tree");
+        }
+
         NodeState parentBaseState = parent.getBaseState();
         return parentBaseState == null
             ? null
@@ -312,6 +325,10 @@ public class TreeImpl implements Tree, P
 
     @Nonnull
     protected synchronized NodeStateBuilder getNodeStateBuilder() {
+        if (isRemoved()) {
+            throw new IllegalStateException("Cannot get a builder for a removed tree");
+        }
+
         if (nodeStateBuilder == null) {
             nodeStateBuilder = parent.getNodeStateBuilder().getChildBuilder(name);
             root.addListener(this);
@@ -329,6 +346,10 @@ public class TreeImpl implements Tree, P
      * @param destName  new name for this tree
      */
     void moveTo(TreeImpl destParent, String destName) {
+        if (isRemoved()) {
+            throw new IllegalStateException("Cannot move removed tree");
+        }
+
         parent.children.remove(name);
         destParent.children.put(destName, this);
 
@@ -343,7 +364,15 @@ public class TreeImpl implements Tree, P
 
     //------------------------------------------------------------< private >---
 
+    private boolean isRemoved() {
+        return parent == this;
+    }
+
     private void buildPath(StringBuilder sb) {
+        if (isRemoved()) {
+            throw new IllegalStateException("Cannot build the path of a removed tree");
+        }
+
         if (parent != null) {
             parent.buildPath(sb);
             if (sb.length() > 0) {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java?rev=1365662&r1=1365661&r2=1365662&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.java
Wed Jul 25 16:39:49 2012
@@ -175,11 +175,11 @@ public class NodeDelegate extends ItemDe
 
     /**
      * Returns an iterator for traversing all the children of this node.
-     * If the node is orderable (there is an "<code>oak:childOrder</code>"
+     * If the node is orderable (there is an "{@code oak:childOrder}"
      * property) then the iterator will return child nodes in the specified
      * order. Otherwise the ordering of the iterator is undefined.
      *
-     * @return  child nodes of the node
+     * @return child nodes of the node
      */
     @Nonnull
     public Iterator<NodeDelegate> getChildren() throws InvalidItemStateException {
@@ -346,7 +346,9 @@ public class NodeDelegate extends ItemDe
 
     private synchronized void resolve() {
         if (tree != null) {
-            tree = sessionDelegate.getTree(tree.getPath());
+            tree = tree.getStatus() == Status.REMOVED
+                ? null
+                : sessionDelegate.getTree(tree.getPath());
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java?rev=1365662&r1=1365661&r2=1365662&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyDelegate.java
Wed Jul 25 16:39:49 2012
@@ -278,7 +278,9 @@ public class PropertyDelegate extends It
 
     private synchronized void resolve() {
         if (parent != null) {
-            parent = sessionDelegate.getTree(parent.getPath());
+            parent = parent.getStatus() == Status.REMOVED
+                ? null
+                : sessionDelegate.getTree(parent.getPath());
 
             if (parent == null) {
                 propertyState = null;



Mime
View raw message