jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1526146 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate: NodeDelegate.java PropertyDelegate.java SessionDelegate.java
Date Wed, 25 Sep 2013 09:47:29 GMT
Author: alexparvulescu
Date: Wed Sep 25 09:47:29 2013
New Revision: 1526146

URL: http://svn.apache.org/r1526146
Log:
OAK-1030 Simplify SessionDelegate#getItem

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java?rev=1526146&r1=1526145&r2=1526146&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
Wed Sep 25 09:47:29 2013
@@ -98,19 +98,6 @@ public class NodeDelegate extends ItemDe
     /** The underlying {@link org.apache.jackrabbit.oak.api.Tree} of this node. */
     private final Tree tree;
 
-    /**
-     * Create a new {@code NodeDelegate} instance for an existing {@code Tree}. That
-     * is for one where {@code exists() == true}.
-     *
-     * @param sessionDelegate
-     * @param tree
-     * @return  A new {@code NodeDelegate} instance or {@code null} if {@code tree}
-     *          doesn't exist.
-     */
-    static NodeDelegate create(SessionDelegate sessionDelegate, Tree tree) {
-        return tree.exists() ? new NodeDelegate(sessionDelegate, tree) : null;
-    }
-
     protected NodeDelegate(SessionDelegate sessionDelegate, Tree tree) {
         super(sessionDelegate);
         this.tree = tree;
@@ -131,9 +118,9 @@ public class NodeDelegate extends ItemDe
     @Override
     @CheckForNull
     public NodeDelegate getParent() {
-        return tree.isRoot()
+        return tree.isRoot() || !tree.getParent().exists() 
             ? null
-            : create(sessionDelegate, tree.getParent());
+            : new NodeDelegate(sessionDelegate, tree.getParent());
     }
 
     @Override
@@ -264,9 +251,9 @@ public class NodeDelegate extends ItemDe
     @CheckForNull
     public PropertyDelegate getPropertyOrNull(String relPath) throws RepositoryException
{
         Tree parent = getTree(PathUtils.getParentPath(relPath));
-        if (parent != null) {
-            String name = PathUtils.getName(relPath);
-            return PropertyDelegate.create(sessionDelegate, parent, name);
+        String name = PathUtils.getName(relPath);
+        if (parent != null && parent.hasProperty(name)) {
+            return new PropertyDelegate(sessionDelegate, parent, name);
         } else {
             return null;
         }
@@ -336,7 +323,7 @@ public class NodeDelegate extends ItemDe
     @CheckForNull
     public NodeDelegate getChild(String relPath) throws RepositoryException {
         Tree tree = getTree(relPath);
-        return tree == null ? null : create(sessionDelegate, tree);
+        return tree == null || !tree.exists() ? null : new NodeDelegate(sessionDelegate,
tree);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java?rev=1526146&r1=1526145&r2=1526146&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PropertyDelegate.java
Wed Sep 25 09:47:29 2013
@@ -42,21 +42,6 @@ public class PropertyDelegate extends It
 
     private final String name;
 
-    /**
-     * Create a new property delegate for an existing parent.
-     * @param sessionDelegate
-     * @param parent  parent tree
-     * @param name  property name
-     * @return  {@code PropertyDelegate} instance or {@code null} if either {@code parent}
-     *          does not exist or does not have a property {@code name}.
-     */
-    @CheckForNull
-    static PropertyDelegate create(SessionDelegate sessionDelegate, Tree parent, String name)
{
-        return parent.hasProperty(name)
-            ? new PropertyDelegate(sessionDelegate, parent, name)
-            : null;
-    }
-
     PropertyDelegate(SessionDelegate sessionDelegate, Tree parent, String name) {
         super(sessionDelegate);
         this.parent = parent;
@@ -78,7 +63,7 @@ public class PropertyDelegate extends It
     @Override
     @CheckForNull
     public NodeDelegate getParent() {
-        return NodeDelegate.create(sessionDelegate, parent);
+        return parent.exists() ? new NodeDelegate(sessionDelegate, parent) : null;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java?rev=1526146&r1=1526145&r2=1526146&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
Wed Sep 25 09:47:29 2013
@@ -239,7 +239,8 @@ public class SessionDelegate {
      */
     @CheckForNull
     public NodeDelegate getNode(String path) {
-        return NodeDelegate.create(this, root.getTree(path));
+        Tree tree = root.getTree(path);
+        return tree.exists() ? new NodeDelegate(this, tree) : null;
     }
 
     /**
@@ -256,11 +257,11 @@ public class SessionDelegate {
         } else {
             Tree parent = root.getTree(PathUtils.getParentPath(path));
             if (parent.hasProperty(name)) {
-                return PropertyDelegate.create(this, parent, name);
+                return new PropertyDelegate(this, parent, name);
             }
             Tree child = parent.getChild(name);
             if (child.exists()) {
-                return NodeDelegate.create(this, child);
+                return new NodeDelegate(this, child);
             } else {
                 return null;
             }
@@ -283,7 +284,8 @@ public class SessionDelegate {
     public PropertyDelegate getProperty(String path) {
         Tree parent = root.getTree(PathUtils.getParentPath(path));
         String name = PathUtils.getName(path);
-        return PropertyDelegate.create(this, parent, name);
+        return parent.hasProperty(name) ? new PropertyDelegate(this, parent,
+                name) : null;
     }
 
     public boolean hasPendingChanges() {



Mime
View raw message