jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1504165 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: SessionImpl.java delegate/SessionDelegate.java
Date Wed, 17 Jul 2013 15:08:14 GMT
Author: jukka
Date: Wed Jul 17 15:08:14 2013
New Revision: 1504165

URL: http://svn.apache.org/r1504165
Log:
OAK-911: Optimize Session.getItem(String)

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.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/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1504165&r1=1504164&r2=1504165&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Wed Jul 17 15:08:14 2013
@@ -49,6 +49,7 @@ import org.apache.jackrabbit.commons.xml
 import org.apache.jackrabbit.commons.xml.SystemViewExporter;
 import org.apache.jackrabbit.commons.xml.ToXmlContentHandler;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.jcr.delegate.ItemDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
@@ -129,22 +130,17 @@ public class SessionImpl implements Jack
         return sessionContext.getOakPathOrThrowNotFound(absPath);
     }
 
-    private PropertyImpl createPropertyOrNull(PropertyDelegate pd) {
-        return pd == null ? null : new PropertyImpl(pd, sessionContext);
-    }
-
     @CheckForNull
     private ItemImpl<?> getItemInternal(@Nonnull String oakPath)
             throws RepositoryException {
-        NodeDelegate nd = sd.getNode(oakPath);
-        if (nd != null) {
-            return sessionContext.createNodeOrNull(nd);
-        }
-        PropertyDelegate pd = sd.getProperty(oakPath);
-        if (pd != null) {
-            return createPropertyOrNull(pd);
+        ItemDelegate item = sd.getItem(oakPath);
+        if (item instanceof NodeDelegate) {
+            return sessionContext.createNodeOrNull((NodeDelegate) item);
+        } else if (item instanceof PropertyDelegate) {
+            return new PropertyImpl((PropertyDelegate) item, sessionContext);
+        } else {
+            return null;
         }
-        return null;
     }
 
     /**
@@ -178,10 +174,16 @@ public class SessionImpl implements Jack
         if (absPath.equals("/")) {
             return null;
         } else {
+            final String oakPath = getOakPathOrThrow(absPath);
             return perform(new ReadOperation<Property>() {
                 @Override
                 public Property perform() throws RepositoryException {
-                    return createPropertyOrNull(sd.getProperty(getOakPathOrThrow(absPath)));
+                    PropertyDelegate pd = sd.getProperty(oakPath);
+                    if (pd != null) {
+                        return new PropertyImpl(pd, sessionContext);
+                    } else {
+                        return null;
+                    }
                 }
             });
         }

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=1504165&r1=1504164&r2=1504165&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 Jul 17 15:08:14 2013
@@ -208,6 +208,31 @@ public class SessionDelegate {
         return NodeDelegate.create(this, root.getTree(path));
     }
 
+    /**
+     * Returns the node or property delegate at the given path.
+     *
+     * @param path Oak path
+     * @return node or property delegate, or {@code null} if none exists
+     */
+    @CheckForNull
+    public ItemDelegate getItem(String path) {
+        String name = PathUtils.getName(path);
+        if (name.isEmpty()) {
+            return getRootNode();
+        } else {
+            Tree parent = root.getTree(PathUtils.getParentPath(path));
+            if (parent.hasProperty(name)) {
+                return PropertyDelegate.create(this, parent, name);
+            }
+            Tree child = parent.getChild(name);
+            if (child.exists()) {
+                return NodeDelegate.create(this, child);
+            } else {
+                return null;
+            }
+        }
+    }
+
     @CheckForNull
     public NodeDelegate getNodeByIdentifier(String id) {
         Tree tree = idManager.getTree(id);



Mime
View raw message