jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1462212 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/api/ main/java/org/apache/jackrabbit/oak/core/ test/java/org/apache/jackrabbit/oak/core/
Date Thu, 28 Mar 2013 16:55:47 GMT
Author: mduerig
Date: Thu Mar 28 16:55:47 2013
New Revision: 1462212

URL: http://svn.apache.org/r1462212
Log:
OAK-729: Replace Tree.Status.DISCONNECTED with Tree.isConnected()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
    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/api/TreeLocation.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/ReadOnlyTree.java
    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/RootImplTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeImplTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java?rev=1462212&r1=1462211&r2=1462212&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java Thu
Mar 28 16:55:47 2013
@@ -34,7 +34,7 @@ import javax.annotation.Nonnull;
  * {@link Tree} instances may become disconnected after a call to {@link #refresh()},
  * {@link #rebase()} or {@link #commit()}. Any access to disconnected tree instances
  * - except for  {@link Tree#getName()}, {@link Tree#isRoot()}, {@link Tree#getPath()},
- * {@link Tree#getParent()} and {@link Tree#getStatus()} - will cause an
+ * {@link Tree#getParent()} and {@link Tree#isConnected()} - will cause an
  * {@code InvalidStateException}.
  */
 public interface Root {

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=1462212&r1=1462211&r2=1462212&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 Thu
Mar 28 16:55:47 2013
@@ -59,8 +59,8 @@ import javax.annotation.Nullable;
  * <p/>
  * {@link Tree} instances may become disconnected after a call to {@link Root#refresh()},
  * {@link Root#rebase()} or {@link Root#commit()}. Any access to disconnected tree instances
- * - except for  {@link Tree#getName()}, {@link Tree#isRoot()}, {@link Tree#getPath()},
- * {@link Tree#getParent()} and {@link Tree#getStatus()} - will cause an
+ * - except for {@link Tree#getName()}, {@link Tree#isRoot()}, {@link Tree#getPath()},
+ * {@link Tree#getParent()} and {@link Tree#isConnected()} - will cause an
  * {@code InvalidStateException}.
  */
 public interface Tree {
@@ -83,12 +83,7 @@ public interface Tree {
          * Item is modified: has added or removed children or added, removed or modified
          * properties.
          */
-        MODIFIED,
-
-        /**
-         * Item is removed or has become disconnected otherwise (e.g. caused by a refresh).
-         */
-        DISCONNECTED
+        MODIFIED
     }
 
     /**
@@ -117,6 +112,13 @@ public interface Tree {
     Status getStatus();
 
     /**
+     * Determine whether this tree has been removed or has become disconnected otherwise
+     * (e.g. caused by a refresh, rebase or commit).
+     * @return {@code false} if this tree has been disconnected and {@code true} otherwise.
+     */
+    boolean isConnected();
+
+    /**
      * @return the current location
      */
     @Nonnull

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java?rev=1462212&r1=1462211&r2=1462212&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
Thu Mar 28 16:55:47 2013
@@ -57,9 +57,8 @@ public interface TreeLocation {
      * Determine whether the underlying {@link org.apache.jackrabbit.oak.api.Tree} or
      * {@link org.apache.jackrabbit.oak.api.PropertyState} for this {@code TreeLocation}
      * is available.
-     * @return  {@code true} if either {@link #getTree()} or {@link #getProperty()} is non
{@code null}.
-     *          and {@link #getStatus()} is not {{@link Status#DISCONNECTED}}.
-     * {@code false} otherwise.
+     * @return  {@code true} if the underlying item is available and has not been disconnected.
+     * @see org.apache.jackrabbit.oak.api.Tree#isConnected()
      */
     boolean exists();
 

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=1462212&r1=1462211&r2=1462212&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
Thu Mar 28 16:55:47 2013
@@ -16,16 +16,15 @@
  */
 package org.apache.jackrabbit.oak.core;
 
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
 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.api.TreeLocation;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 
-import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * AbstractNodeLocation... TODO
  */
@@ -85,8 +84,7 @@ abstract class AbstractNodeLocation<T ex
 
     @Override
     public boolean exists() {
-        Status status = getStatus();
-        return status != null && status != Status.DISCONNECTED && getTree()
!= null;
+        return tree.isConnected() && 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=1462212&r1=1462211&r2=1462212&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
Thu Mar 28 16:55:47 2013
@@ -16,15 +16,15 @@
  */
 package org.apache.jackrabbit.oak.core;
 
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
 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.api.TreeLocation;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 
-import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * AbstractPropertyLocation... TODO
  */
@@ -48,8 +48,7 @@ abstract class AbstractPropertyLocation<
 
     @Override
     public boolean exists() {
-        Status status = parentLocation.tree.getPropertyStatus(name);
-        return status != null && status != Status.DISCONNECTED && getProperty()
!= null;
+        return parentLocation.tree.isConnected() && getProperty() != null;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java?rev=1462212&r1=1462211&r2=1462212&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
Thu Mar 28 16:55:47 2013
@@ -18,6 +18,11 @@
  */
 package org.apache.jackrabbit.oak.core;
 
+import static com.google.common.base.Objects.toStringHelper;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+
 import java.util.Iterator;
 
 import javax.annotation.Nonnull;
@@ -32,11 +37,6 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
-import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-
 public class ReadOnlyTree implements Tree {
 
     /**
@@ -144,6 +144,11 @@ public class ReadOnlyTree implements Tre
     }
 
     @Override
+    public boolean isConnected() {
+        return true;
+    }
+
+    @Override
     public TreeLocation getLocation() {
         return new NodeLocation(this);
     }

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=1462212&r1=1462211&r2=1462212&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
Thu Mar 28 16:55:47 2013
@@ -155,14 +155,11 @@ public class TreeImpl implements Tree {
     public Status getPropertyStatus(String name) {
         // TODO: see OAK-212
         Status nodeStatus = getStatus();
-        if (nodeStatus == Status.DISCONNECTED) {
-            return Status.DISCONNECTED;
-        }
         if (nodeStatus == Status.NEW) {
             return (hasProperty(name)) ? Status.NEW : null;
         }
         PropertyState head = internalGetProperty(name);
-        if (head != null && !canRead(head)) {
+        if (head == null || !canRead(head)) {
             // no permission to read status information for existing property
             return null;
         }
@@ -170,10 +167,6 @@ public class TreeImpl implements Tree {
         NodeState parentBase = nodeBuilder.getBaseState();
         PropertyState base = parentBase == null ? null : parentBase.getProperty(name);
 
-        if (head == null) {
-            return (base == null) ? null : Status.DISCONNECTED;
-        }
-
         if (base == null) {
             return Status.NEW;
         } else if (head.equals(base)) {
@@ -219,12 +212,14 @@ public class TreeImpl implements Tree {
         }
     }
 
-    private boolean isDisconnected() {
+    @Override
+    public boolean isConnected() {
+        enterNoStateCheck();
         if (parent == null || nodeBuilder.isConnected()) {
-            return false;
+            return true;
         }
 
-        return !reconnect();
+        return reconnect();
     }
 
     private boolean reconnect() {
@@ -243,11 +238,7 @@ public class TreeImpl implements Tree {
 
     @Override
     public Status getStatus() {
-        enterNoStateCheck();
-
-        if (isDisconnected()) {
-            return Status.DISCONNECTED;
-        }
+        enter();
 
         if (nodeBuilder.isNew()) {
             return Status.NEW;
@@ -329,9 +320,6 @@ public class TreeImpl implements Tree {
     @Override
     public boolean remove() {
         enter();
-        if (isDisconnected()) {
-            throw new IllegalStateException("Cannot remove a disconnected tree");
-        }
 
         if (!isRoot() && parent.hasChild(name)) {
             NodeBuilder parentBuilder = parent.nodeBuilder;
@@ -543,7 +531,7 @@ public class TreeImpl implements Tree {
 
     private void enter() {
         root.checkLive();
-        checkState(!isDisconnected());
+        checkState(isConnected());
         applyPendingMoves();
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java?rev=1462212&r1=1462211&r2=1462212&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/RootImplTest.java
Thu Mar 28 16:55:47 2013
@@ -126,7 +126,7 @@ public class RootImplTest {
         root.move("/z", "/x/z");
         root.getTree("/x/z").remove();
 
-        assertEquals(Status.DISCONNECTED, z.getStatus());
+        assertFalse(z.isConnected());
 
         x.addChild("z");
         assertEquals(Status.EXISTING, z.getStatus());

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=1462212&r1=1462211&r2=1462212&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
Thu Mar 28 16:55:47 2013
@@ -185,7 +185,7 @@ public class TreeImplTest {
         Tree t = tree.addChild("new");
 
         tree.getChild("new").remove();
-        assertEquals(Status.DISCONNECTED, t.getStatus());
+        assertFalse(t.isConnected());
 
         assertNull(tree.getChild("new"));
     }
@@ -298,8 +298,8 @@ public class TreeImplTest {
         Tree y = x.addChild("y");
         x.remove();
 
-        assertEquals(Status.DISCONNECTED, x.getStatus());
-        assertEquals(Status.DISCONNECTED, y.getStatus());
+        assertFalse(x.isConnected());
+        assertFalse(y.isConnected());
     }
 
     @Test
@@ -317,7 +317,7 @@ public class TreeImplTest {
 
         assertEquals(Tree.Status.EXISTING, tree.getPropertyStatus("new"));
         tree.removeProperty("new");
-        assertEquals(Tree.Status.DISCONNECTED, tree.getPropertyStatus("new"));
+        assertNull(tree.getPropertyStatus("new"));
         root.commit();
 
         assertNull(tree.getPropertyStatus("new"));
@@ -325,8 +325,6 @@ public class TreeImplTest {
         Tree x = root.getTree("/x");
         x.setProperty("y", "value1");
         x.remove();
-
-        assertEquals(Status.DISCONNECTED, x.getPropertyStatus("y"));
     }
 
     @Test
@@ -413,8 +411,7 @@ public class TreeImplTest {
 
         assertEquals(Status.EXISTING, x.getStatus());
         assertNull(x.getPropertyStatus("p"));
-        assertEquals(Status.DISCONNECTED, xx.getStatus());
-        assertEquals(Status.DISCONNECTED, xx.getPropertyStatus("q"));
+        assertFalse(xx.isConnected());
     }
 
     @Test
@@ -431,10 +428,8 @@ public class TreeImplTest {
 
         root.getTree("/x").remove();
 
-        assertEquals(Status.DISCONNECTED, x.getStatus());
-        assertEquals(Status.DISCONNECTED, x.getPropertyStatus("p"));
-        assertEquals(Status.DISCONNECTED, xx.getStatus());
-        assertEquals(Status.DISCONNECTED, xx.getPropertyStatus("q"));
+        assertFalse(x.isConnected());
+        assertFalse(xx.isConnected());
     }
 
 }
\ No newline at end of file



Mime
View raw message