jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1444031 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ oak-core/src/main/...
Date Fri, 08 Feb 2013 14:49:08 GMT
Author: mduerig
Date: Fri Feb  8 14:48:52 2013
New Revision: 1444031

URL: http://svn.apache.org/r1444031
Log:
OAK-617: Generalise Tree.Status.REMOVED to DISCONNECTED

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java?rev=1444031&r1=1444030&r2=1444031&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Tree.java Fri
Feb  8 14:48:52 2013
@@ -79,9 +79,9 @@ public interface Tree {
         MODIFIED,
 
         /**
-         * Item is removed
+         * Item is removed or has become disconnected otherwise (e.g. caused by a refresh).
          */
-        REMOVED
+        DISCONNECTED
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java?rev=1444031&r1=1444030&r2=1444031&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
Fri Feb  8 14:48:52 2013
@@ -85,7 +85,7 @@ abstract class AbstractNodeLocation<T ex
     @Override
     public boolean exists() {
         Status status = getStatus();
-        return status != null && status != Status.REMOVED && getTree() !=
null;
+        return status != null && status != Status.DISCONNECTED && getTree()
!= null;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java?rev=1444031&r1=1444030&r2=1444031&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractPropertyLocation.java
Fri Feb  8 14:48:52 2013
@@ -47,8 +47,8 @@ abstract class AbstractPropertyLocation<
 
     @Override
     public boolean exists() {
-        Status status = getStatus();
-        return status != null && status != Status.REMOVED && getProperty()
!= null;
+        Status status = parentLocation.tree.getPropertyStatus(name);
+        return status != null && status != Status.DISCONNECTED && getProperty()
!= null;
     }
 
     @Override

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=1444031&r1=1444030&r2=1444031&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 Feb  8 14:48:52 2013
@@ -149,8 +149,8 @@ public class TreeImpl implements Tree {
         Status nodeStatus = getStatus();
         if (nodeStatus == Status.NEW) {
             return (hasProperty(name)) ? Status.NEW : null;
-        } else if (nodeStatus == Status.REMOVED) {
-            return Status.REMOVED; // FIXME not correct if no property existed with that
name
+        } else if (nodeStatus == Status.DISCONNECTED) {
+            return Status.DISCONNECTED;
         } else {
             PropertyState head = internalGetProperty(name);
             if (head != null && !canRead(head)) {
@@ -161,7 +161,7 @@ public class TreeImpl implements Tree {
             NodeState parentBase = getBaseState();
             PropertyState base = parentBase == null ? null : parentBase.getProperty(name);
             if (head == null) {
-                return (base == null) ? null : Status.REMOVED;
+                return (base == null) ? null : Status.DISCONNECTED;
             } else {
                 if (base == null) {
                     return Status.NEW;
@@ -209,25 +209,25 @@ public class TreeImpl implements Tree {
         }
     }
 
-    private boolean isRemoved() {
+    private boolean isDisconnected() {
         if (isRoot()) {
             return false;
         }
         if (parent.nodeBuilder == null) {
             return false;
         }
-        if (parent.nodeBuilder.isRemoved()) {
+        if (!parent.nodeBuilder.isConnected()) {
             return true;
         }
-        return getNodeBuilder().isRemoved();
+        return !getNodeBuilder().isConnected();
     }
 
     @Override
     public Status getStatus() {
         root.checkLive();
 
-        if (isRemoved()) {
-            return Status.REMOVED;
+        if (isDisconnected()) {
+            return Status.DISCONNECTED;
         }
 
         NodeBuilder builder = getNodeBuilder();
@@ -300,8 +300,8 @@ public class TreeImpl implements Tree {
     @Override
     public boolean remove() {
         root.checkLive();
-        if (isRemoved()) {
-            throw new IllegalStateException("Cannot remove removed tree");
+        if (isDisconnected()) {
+            throw new IllegalStateException("Cannot remove a disconnected tree");
         }
 
         if (!isRoot() && parent.hasChild(name)) {
@@ -408,8 +408,8 @@ public class TreeImpl implements Tree {
 
     @CheckForNull
     protected NodeState getBaseState() {
-        if (isRemoved()) {
-            throw new IllegalStateException("Cannot get the base state of a removed tree");
+        if (isDisconnected()) {
+            throw new IllegalStateException("Cannot get the base state of a disconnected
tree");
         }
 
         NodeState parentBaseState = parent.getBaseState();
@@ -436,8 +436,8 @@ public class TreeImpl implements Tree {
      * @param destName   new name for this tree
      */
     void moveTo(TreeImpl destParent, String destName) {
-        if (isRemoved()) {
-            throw new IllegalStateException("Cannot move removed tree");
+        if (isDisconnected()) {
+            throw new IllegalStateException("Cannot move a disconnected tree");
         }
 
         name = destName;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java?rev=1444031&r1=1444030&r2=1444031&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/strategy/ContentMirrorStoreStrategy.java
Fri Feb  8 14:48:52 2013
@@ -102,7 +102,7 @@ public class ContentMirrorStoreStrategy 
     }
 
     private static void pruneNode(NodeBuilder parent) {
-        if (parent.isRemoved()) {
+        if (!parent.isConnected()) {
             return;
         }
         for (String name : parent.getChildNodeNames()) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1444031&r1=1444030&r2=1444031&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Fri Feb  8 14:48:52 2013
@@ -198,11 +198,16 @@ public class MemoryNodeBuilder implement
         return isRoot() || parent.writeState == null || parent.writeState.hasChildNode(name);
     }
 
-    @Nonnull
-    private NodeState read() {
+    /**
+     * Update the state of this builder for reading.
+     * @return  {@code true} is this reader is connected, {@code false} otherwise.
+     */
+    private boolean updateReadState() {
         if (revision != root.revision) {
             assert(!isRoot()); // root never gets here since revision == root.revision
-            checkState(existsOrDisconnected(), "This node has already been removed");
+            if (!existsOrDisconnected()) {
+                return false;
+            }
             parent.read();
 
             // The builder could have been reset, need to re-get base state
@@ -212,16 +217,15 @@ public class MemoryNodeBuilder implement
             writeState = parent.getWriteState(name);
 
             revision = root.revision;
-            checkState(baseState != null || writeState != null, "This node is disconnected");
         }
+        return writeState != null || baseState != null;
+    }
 
+    @Nonnull
+    private NodeState read() {
+        checkState(updateReadState(), "This node has been removed or is disconnected");
         assert classInvariants();
-
-        if (writeState != null) {
-            return writeState;
-        } else {
-            return baseState;
-        }
+        return writeState != null ? writeState : baseState;
     }
 
     @Nonnull
@@ -233,7 +237,7 @@ public class MemoryNodeBuilder implement
     private MutableNodeState write(long newRevision, boolean skipRemovedCheck) {
         // make sure that all revision numbers up to the root gets updated
         if (!isRoot()) {
-            checkState(skipRemovedCheck || existsOrDisconnected(), "This node has already
been removed");
+            checkState(skipRemovedCheck || existsOrDisconnected(), "This node has been removed");
             parent.write(newRevision, skipRemovedCheck);
         }
 
@@ -304,13 +308,8 @@ public class MemoryNodeBuilder implement
     }
 
     @Override
-    public boolean isRemoved() {
-        return !isRoot() && (parent.isRemoved() || parent.isRemoved(name));
-    }
-
-    private boolean isRemoved(String name) {
-        read();
-        return hasBaseState(name) && !hasChildNode(name);
+    public boolean isConnected() {
+        return updateReadState();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java?rev=1444031&r1=1444030&r2=1444031&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
Fri Feb  8 14:48:52 2013
@@ -53,10 +53,11 @@ public interface NodeBuilder {
     boolean isNew();
 
     /**
-     * Check whether this builder represents a removed node, which is present in the base
state.
-     * @return  {@code true} for a removed node
+     * Check whether this builder represents a disconnected node. A node is disconnected
when it has been
+     * part of a tree but has been subsequently removed.
+     * @return  {@code true} for a disconnected node
      */
-    boolean isRemoved();
+    boolean isConnected();
 
     /**
      * Check whether this builder represents a modified node, which has either modified properties

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java?rev=1444031&r1=1444030&r2=1444031&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
Fri Feb  8 14:48:52 2013
@@ -43,8 +43,8 @@ public class ReadOnlyBuilder implements 
     }
 
     @Override
-    public boolean isRemoved() {
-        return false;
+    public boolean isConnected() {
+        return true;
     }
 
     @Override

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=1444031&r1=1444030&r2=1444031&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 Feb  8 14:48:52 2013
@@ -293,8 +293,8 @@ public class TreeImplTest {
         Tree x = root.getTree("/x");
         Tree y = x.addChild("y");
         x.remove();
-        assertEquals(Status.REMOVED, x.getStatus());
-        assertEquals(Status.REMOVED, y.getStatus());
+        assertEquals(Status.DISCONNECTED, x.getStatus());
+        assertEquals(Status.DISCONNECTED, y.getStatus());
     }
 
     @Test
@@ -314,7 +314,7 @@ public class TreeImplTest {
         tree = root.getTree("/");
         assertEquals(Tree.Status.EXISTING, tree.getPropertyStatus("new"));
         tree.removeProperty("new");
-        assertEquals(Tree.Status.REMOVED, tree.getPropertyStatus("new"));
+        assertEquals(Tree.Status.DISCONNECTED, tree.getPropertyStatus("new"));
         root.commit();
 
         tree = root.getTree("/");
@@ -323,7 +323,7 @@ public class TreeImplTest {
         Tree x = root.getTree("/x");
         x.setProperty("y", "value1");
         x.remove();
-        assertEquals(Status.REMOVED, x.getPropertyStatus("y"));
+        assertEquals(Status.DISCONNECTED, x.getPropertyStatus("y"));
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java?rev=1444031&r1=1444030&r2=1444031&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemDelegate.java
Fri Feb  8 14:48:52 2013
@@ -84,7 +84,7 @@ public abstract class ItemDelegate {
      */
     public boolean isStale() {
         Status status = getLocationOrNull().getStatus();
-        return status == Status.REMOVED || status == null;
+        return status == Status.DISCONNECTED || status == null;
     }
 
     /**



Mime
View raw message