jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1376959 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/test/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/
Date Fri, 24 Aug 2012 15:22:06 GMT
Author: mduerig
Date: Fri Aug 24 15:22:05 2012
New Revision: 1376959

URL: http://svn.apache.org/viewvc?rev=1376959&view=rev
Log:
OAK-278: Tree.getStatus() and Tree.getPropertyStatus() fail for items whose parent has been
removed

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.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=1376959&r1=1376958&r2=1376959&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
Fri Aug 24 15:22:05 2012
@@ -50,9 +50,12 @@ public class TreeImpl implements Tree, P
     /** Underlying {@code Root} of this {@code Tree} instance */
     private final RootImpl root;
 
-    /** Parent of this tree. Null for the root and this for removed trees. */
+    /** Parent of this tree. Null for the root. */
     private TreeImpl parent;
 
+    /** Marker for removed trees */
+    private boolean removed;
+
     /** Name of this tree */
     private String name;
 
@@ -254,7 +257,7 @@ public class TreeImpl implements Tree, P
             NodeBuilder builder = parent.getNodeBuilder();
             builder.removeNode(name);
             parent.children.remove(name);
-            parent = this;
+            removed = true;
             root.purge();
             return true;
         } else {
@@ -390,6 +393,10 @@ public class TreeImpl implements Tree, P
     }
 
     private Status internalGetPropertyStatus(String name) {
+        if (isRemoved()) {
+            return Status.REMOVED;
+        }
+
         NodeState baseState = getBaseState();
         boolean exists = internalGetProperty(name) != null;
         if (baseState == null) {
@@ -433,14 +440,10 @@ public class TreeImpl implements Tree, P
     }
 
     private boolean isRemoved() {
-        return parent == this;
+        return removed || (parent != null && parent.isRemoved());
     }
 
     private void buildPath(StringBuilder sb) {
-        if (isRemoved()) {
-            throw new IllegalStateException("Cannot build the path of a removed tree");
-        }
-
         if (!isRoot()) {
             parent.buildPath(sb);
             sb.append('/').append(name);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java?rev=1376959&r1=1376958&r2=1376959&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
Fri Aug 24 15:22:05 2012
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+
 import javax.jcr.PropertyType;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
@@ -28,6 +29,7 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Tree.Status;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.junit.Test;
 
@@ -286,6 +288,12 @@ public class TreeImplTest extends Abstra
         tree = root.getTree("/");
         assertEquals(Tree.Status.EXISTING, tree.getChild("new").getStatus());
         assertNull(tree.getChild("new").getChild("another"));
+
+        Tree x = root.getTree("/x");
+        Tree y = x.addChild("y");
+        x.remove();
+        assertEquals(Status.REMOVED, x.getStatus());
+        assertEquals(Status.REMOVED, y.getStatus());
     }
 
     @Test
@@ -313,6 +321,11 @@ public class TreeImplTest extends Abstra
 
         tree = root.getTree("/");
         assertNull(tree.getPropertyStatus("new"));
+
+        Tree x = root.getTree("/x");
+        x.setProperty("y", value1);
+        x.remove();
+        assertEquals(Status.REMOVED, x.getPropertyStatus("y"));
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1376959&r1=1376958&r2=1376959&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Fri Aug 24 15:22:05 2012
@@ -984,6 +984,26 @@ public class RepositoryTest extends Abst
     }
 
     @Test
+    public void accessRemovedItem() throws RepositoryException {
+        Node foo = getNode("/foo");
+        Node bar = foo.addNode("bar");
+        Property p = bar.setProperty("name", "value");
+        foo.remove();
+        try {
+            bar.getPath();
+            fail("Expected InvalidItemStateException");
+        }
+        catch (InvalidItemStateException expected) {
+        }
+        try {
+            p.getPath();
+            fail("Expected InvalidItemStateException");
+        }
+        catch (InvalidItemStateException expected) {
+        }
+    }
+
+    @Test
     public void getReferences() throws RepositoryException {
         Session session = getAdminSession();
         Node referee = getNode("/foo");



Mime
View raw message