jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1357314 - 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/test/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/main/java/org/apache/jackra...
Date Wed, 04 Jul 2012 15:43:21 GMT
Author: mduerig
Date: Wed Jul  4 15:43:21 2012
New Revision: 1357314

URL: http://svn.apache.org/viewvc?rev=1357314&view=rev
Log:
OAK-161: Refactor Tree#getChildStatus

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/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-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeDelegate.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=1357314&r1=1357313&r2=1357314&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 Wed
Jul  4 15:43:21 2012
@@ -146,13 +146,11 @@ public interface Tree {
     Tree getChild(String name);
 
     /**
-     * Get the {@code Status} of a child tree
-     * @param name  name of the child
-     * @return  the status of the child with the given {@code name} or {@code null} in
-     *          no such child exists.
+     * Get the {@code Status} of this tree
+     * @return  the status of this tree
      */
-    @CheckForNull
-    Status getChildStatus(String name);
+    @Nonnull
+    Status getStatus();
 
     /**
      * Determine if a child of this {@code Tree} instance exists.

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=1357314&r1=1357313&r2=1357314&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
Wed Jul  4 15:43:21 2012
@@ -115,12 +115,8 @@ public class ReadOnlyTree implements Tre
     }
 
     @Override
-    public Status getChildStatus(String name) {
-        if (hasChild(name)) {
-            return Status.EXISTING;
-        } else {
-            return null;
-        }
+    public Status getStatus() {
+        return Status.EXISTING;
     }
 
     @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=1357314&r1=1357313&r2=1357314&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  4 15:43:21 2012
@@ -195,42 +195,21 @@ public class TreeImpl implements Tree, P
     }
 
     @Override
-    public Status getChildStatus(String name) {
+    public Status getStatus() {
         NodeState baseState = getBaseState();
         if (baseState == null) {
-            // This instance is NEW...
-            if (hasChild(name)) {
-                // ...so all children are new
-                return Status.NEW;
-            } else {
-                // ...unless they don't exist.
-                return null;
-            }
-        } else {
-            if (hasChild(name)) {
-                // We have the child...
-                if (baseState.getChildNode(name) == null) {
-                    // ...but didn't have it before. So its NEW.
-                    return Status.NEW;
-                } else {
-                    // ... and did have it before. So...
-                    if (isSame(baseState.getChildNode(name), getNodeState().getChildNode(name)))
{
-                        // ...it's EXISTING if it hasn't changed
-                        return Status.EXISTING;
-                    } else {
-                        // ...and MODIFIED otherwise.
-                        return Status.MODIFIED;
-                    }
-                }
-            } else {
-                // We don't have the child
-                if (baseState.getChildNode(name) == null) {
-                    // ...and didn't have it before. So it doesn't exist.
-                    return null;
-                } else {
-                    // ...and didn't have it before. So it's REMOVED
-                    return Status.REMOVED;
-                }
+            // Did not exist before, so its NEW
+            return Status.NEW;
+        }
+        else {
+            // Did exit it before. So...
+            if (isSame(baseState, getNodeState())) {
+                // ...it's EXISTING if it hasn't changed
+                return Status.EXISTING;
+            }
+            else {
+                // ...and MODIFIED otherwise.
+                return Status.MODIFIED;
             }
         }
     }

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=1357314&r1=1357313&r2=1357314&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
Wed Jul  4 15:43:21 2012
@@ -363,27 +363,25 @@ public class RootImplTest extends Abstra
         Tree tree = root.getTree("/");
 
         tree.addChild("new");
-        assertEquals(Status.NEW, tree.getChildStatus("new"));
+        assertEquals(Status.NEW, tree.getChild("new").getStatus());
         root.commit(DefaultConflictHandler.OURS);
 
         tree = root.getTree("/");
-        assertEquals(Status.EXISTING, tree.getChildStatus("new"));
+        assertEquals(Status.EXISTING, tree.getChild("new").getStatus());
         Tree added = tree.getChild("new");
         added.addChild("another");
-        assertEquals(Status.MODIFIED, tree.getChildStatus("new"));
+        assertEquals(Status.MODIFIED, tree.getChild("new").getStatus());
         root.commit(DefaultConflictHandler.OURS);
 
         tree = root.getTree("/");
-        assertEquals(Status.EXISTING, tree.getChildStatus("new"));
+        assertEquals(Status.EXISTING, tree.getChild("new").getStatus());
         tree.getChild("new").getChild("another").remove();
-        assertEquals(Status.MODIFIED, tree.getChildStatus("new"));
-        assertEquals(Status.REMOVED, tree.getChild("new").getChildStatus("another"));
+        assertEquals(Status.MODIFIED, tree.getChild("new").getStatus());
         root.commit(DefaultConflictHandler.OURS);
 
         tree = root.getTree("/");
-        assertEquals(Status.EXISTING, tree.getChildStatus("new"));
+        assertEquals(Status.EXISTING, tree.getChild("new").getStatus());
         assertNull(tree.getChild("new").getChild("another"));
-        assertNull(tree.getChild("new").getChildStatus("another"));
     }
 
     @Test
@@ -422,8 +420,8 @@ public class RootImplTest extends Abstra
 
         tree = root.getTree("/");
         tree.getChild("one").getChild("two").addChild("three");
-        assertEquals(Status.EXISTING, tree.getChildStatus("one"));
-        assertEquals(Status.MODIFIED, tree.getChild("one").getChildStatus("two"));
+        assertEquals(Status.EXISTING, tree.getChild("one").getStatus());
+        assertEquals(Status.MODIFIED, tree.getChild("one").getChild("two").getStatus());
     }
 
     @Test

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=1357314&r1=1357313&r2=1357314&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  4 15:43:21 2012
@@ -63,7 +63,7 @@ public class NodeDelegate extends ItemDe
 
     @Override
     public NodeDelegate getParent() throws InvalidItemStateException {
-        Tree parent = getParentTree();
+        Tree parent = getTree().getParent();
         return parent == null ? null : new NodeDelegate(sessionDelegate, parent);
     }
 
@@ -75,16 +75,7 @@ public class NodeDelegate extends ItemDe
 
     @Override
     public Status getStatus() throws InvalidItemStateException {
-        Tree parent = getParentTree();
-        if (parent == null) {
-            return Status.EXISTING;  // FIXME: return correct status for root. See also OAK-161
-        } else {
-            Status childStatus = parent.getChildStatus(getName());
-            if (childStatus == null) {
-                throw new InvalidItemStateException("Node is stale");
-            }
-            return childStatus;
-        }
+        return getTree().getStatus();
     }
 
     @Override
@@ -230,11 +221,6 @@ public class NodeDelegate extends ItemDe
         return sessionDelegate.getTree(absPath);
     }
 
-    @CheckForNull
-    private Tree getParentTree() throws InvalidItemStateException {
-        return getTree().getParent();
-    }
-
     private synchronized Tree getTree() throws InvalidItemStateException {
         resolve();
         if (tree == null) {



Mime
View raw message