jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1376596 - 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-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Thu, 23 Aug 2012 17:11:12 GMT
Author: mduerig
Date: Thu Aug 23 17:11:12 2012
New Revision: 1376596

URL: http://svn.apache.org/viewvc?rev=1376596&view=rev
Log:
OAK-275: Introduce TreeLocation interface
use TreeLocation from NodeDelegate instead of directly using Tree

Modified:
    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/TreeImpl.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/TreeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java?rev=1376596&r1=1376595&r2=1376596&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 Aug 23 17:11:12 2012
@@ -26,12 +26,13 @@ public interface TreeLocation {
     TreeLocation getParent();
 
     /**
-     * Navigate to a child
-     * @param name  name of the child
+     * Navigate to a child through a relative path. A relative path consists of a
+     * possibly empty lists of names separated by forward slashes.
+     * @param relPath  relative path to the child
      * @return  a {@code TreeLocation} for a child with the given {@code name}.
      */
     @Nonnull
-    TreeLocation getChild(String name);
+    TreeLocation getChild(String relPath);
 
     /**
      * Get the underlying {@link org.apache.jackrabbit.oak.api.Tree} for this {@code TreeLocation}.

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=1376596&r1=1376595&r2=1376596&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 Aug 23 17:11:12 2012
@@ -561,16 +561,27 @@ public class TreeImpl implements Tree, P
         }
 
         @Override
-        public TreeLocation getChild(String name) {
-            PropertyState property = tree.internalGetProperty(name);
+        public TreeLocation getChild(String relPath) {
+            if (relPath.isEmpty()) {
+                return this;
+            }
+
+            TreeImpl child = tree;
+            String parentPath = PathUtils.getParentPath(relPath);
+            for (String name : PathUtils.elements(parentPath)) {
+                child = child.internalGetChild(name);
+            }
+
+            String name = PathUtils.getName(relPath);
+            PropertyState property = child.internalGetProperty(name);
             if (property != null) {
                 return new PropertyLocation(this, property);
             }
             else {
-                TreeImpl node = tree.internalGetChild(name);
-                return node == null
+                child = child.internalGetChild(name);
+                return child == null
                     ? NullLocation.INSTANCE
-                    : new NodeLocation(node);
+                    : new NodeLocation(child);
             }
         }
 
@@ -612,7 +623,7 @@ public class TreeImpl implements Tree, P
         }
 
         @Override
-        public TreeLocation getChild(String name) {
+        public TreeLocation getChild(String relPath) {
             return NullLocation.INSTANCE;
         }
 
@@ -648,7 +659,7 @@ public class TreeImpl implements Tree, P
         }
 
         @Override
-        public TreeLocation getChild(String name) {
+        public TreeLocation getChild(String relPath) {
             return this;
         }
 

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=1376596&r1=1376595&r2=1376596&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
Thu Aug 23 17:11:12 2012
@@ -39,6 +39,7 @@ import org.apache.jackrabbit.oak.api.Cor
 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;
 
 /**
@@ -49,16 +50,12 @@ import org.apache.jackrabbit.oak.commons
  */
 public class NodeDelegate extends ItemDelegate {
 
-    /**
-     * The underlying {@link Tree} instance. In order to ensure the instance
-     * is up to date, this field <em>should not be accessed directly</em> but
-     * rather the {@link #getTree()} method should be used.
-     */
-    private Tree tree;
+    /** The underlying {@link TreeLocation} of this node. */
+    private TreeLocation treeLocation;
 
     public NodeDelegate(SessionDelegate sessionDelegate, Tree tree) {
         super(sessionDelegate);
-        this.tree = tree;
+        this.treeLocation = tree.getLocation();
     }
 
     @Override
@@ -79,8 +76,7 @@ public class NodeDelegate extends ItemDe
 
     @Override
     public boolean isStale() {
-        resolve();
-        return tree == null;
+        return treeLocation.getStatus() == Status.REMOVED;
     }
 
     @Override
@@ -90,8 +86,8 @@ public class NodeDelegate extends ItemDe
 
     @Override
     public String toString() {
-        // don't disturb the state: avoid calling getTree()
-        return "NodeDelegate[" + tree.getPath() + ']';
+        // don't disturb the state: avoid resolving the tree
+        return "NodeDelegate[" + treeLocation.getPath() + ']';
     }
 
     @Nonnull
@@ -337,20 +333,15 @@ public class NodeDelegate extends ItemDe
 
     @Nonnull
     synchronized Tree getTree() throws InvalidItemStateException {
-        resolve();
-        if (tree == null) {
-            throw new InvalidItemStateException("Node is stale");
-        }
-
-        return tree;
-    }
-
-    private synchronized void resolve() {
-        if (tree != null) {
-            tree = tree.getStatus() == Status.REMOVED
-                ? null
-                : sessionDelegate.getTree(tree.getPath());
+        String path = treeLocation.getPath();
+        if (path != null) {
+            Tree tree = sessionDelegate.getTree(path);
+            if (tree != null) {
+                treeLocation = tree.getLocation();
+                return tree;
+            }
         }
+        throw new InvalidItemStateException("Node is stale");
     }
 
     private Iterator<NodeDelegate> nodeDelegateIterator(
@@ -382,7 +373,7 @@ public class NodeDelegate extends ItemDe
                 new Function<PropertyState, PropertyDelegate>() {
                     @Override
                     public PropertyDelegate apply(PropertyState propertyState) {
-                        return new PropertyDelegate(sessionDelegate, tree,
+                        return new PropertyDelegate(sessionDelegate, treeLocation.getTree(),
                                 propertyState);
                     }
                 });



Mime
View raw message