jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1374056 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: NodeDelegate.java NodeImpl.java SessionDelegate.java
Date Thu, 16 Aug 2012 21:04:05 GMT
Author: mduerig
Date: Thu Aug 16 21:04:04 2012
New Revision: 1374056

URL: http://svn.apache.org/viewvc?rev=1374056&view=rev
Log:
OAK-101: implement identifier handling (byUUID, byIdentifier, etc)
 simplify/refactor internalGetReferences

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

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=1374056&r1=1374055&r2=1374056&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 16 21:04:04 2012
@@ -326,6 +326,7 @@ public class NodeDelegate extends ItemDe
         return sessionDelegate.getTree(absPath);
     }
 
+    @Nonnull
     synchronized Tree getTree() throws InvalidItemStateException {
         resolve();
         if (tree == null) {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1374056&r1=1374055&r2=1374056&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Thu Aug 16 21:04:04 2012
@@ -55,7 +55,6 @@ import javax.jcr.version.VersionHistory;
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Iterators;
 import org.apache.jackrabbit.commons.ItemNameMatcher;
@@ -226,8 +225,8 @@ public class NodeImpl extends ItemImpl<N
                     String grandParentPath = PathUtils.getParentPath(parentPath);
                     NodeDelegate grandParent = dlg.getChild(grandParentPath);
                     if (grandParent != null) {
-                        String propname = PathUtils.getName(parentPath);
-                        if (grandParent.getProperty(propname) != null) {
+                        String propName = PathUtils.getName(parentPath);
+                        if (grandParent.getProperty(propName) != null) {
                             throw new ConstraintViolationException("Can't add new node to
property.");
                         }
                     }
@@ -750,37 +749,28 @@ public class NodeImpl extends ItemImpl<N
         return internalGetReferences(name, true);
     }
 
-    private PropertyIterator internalGetReferences(String name, boolean weak) throws RepositoryException
{
-        final Set<String> propertyOakPaths;
-        if (weak) {
-            propertyOakPaths = sessionDelegate.getIdManager().getWeakReferences(dlg.getTree(),
name);
-        } else {
-            propertyOakPaths = sessionDelegate.getIdManager().getReferences(dlg.getTree(),
name);
-        }
+    private PropertyIterator internalGetReferences(final String name, final boolean weak)
throws RepositoryException {
+        return sessionDelegate.perform(new SessionOperation<PropertyIterator>() {
+            @Override
+            public PropertyIterator perform() throws InvalidItemStateException {
+                IdentifierManager idManager = sessionDelegate.getIdManager();
 
-        final Iterable<Property> properties = Iterables.transform(
-                propertyOakPaths,
-                new Function<String, Property>() {
-                    @Override
-                    public Property apply(String oakPath) {
-                        // FIXME: should use sessionDelegate.getProperty(oakPath)
-                        // FIXME: avoid converting oak-path to jcr-path and back and to avoid
-                        // FIXME: using jcr-api calls internally.
-                        try {
-                            return sessionDelegate.getSession().getProperty(sessionDelegate.getNamePathMapper().getJcrPath(oakPath));
-                        } catch (RepositoryException e) {
-                            log.debug(e.getMessage());
-                            return null;
+                Set<String> propertyOakPaths = weak
+                    ? idManager.getWeakReferences(dlg.getTree(), name)
+                    : idManager.getReferences(dlg.getTree(), name);
+
+                Iterable<Property> properties = Iterables.transform(
+                    propertyOakPaths,
+                    new Function<String, Property>() {
+                        @Override
+                        public Property apply(String oakPath) {
+                            PropertyDelegate pd = sessionDelegate.getProperty(oakPath);
+                            return pd == null ? null : new PropertyImpl(pd);
                         }
                     }
-                }
-        );
+                );
 
-        return sessionDelegate.perform(new SessionOperation<PropertyIterator>() {
-            @Override
-            public PropertyIterator perform() {
-                return new PropertyIteratorAdapter(
-                        Iterables.filter(properties, Predicates.<Property>notNull()).iterator(),
propertyOakPaths.size());
+                return new PropertyIteratorAdapter(properties.iterator(), propertyOakPaths.size());
             }
         });
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1374056&r1=1374055&r2=1374056&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Thu Aug 16 21:04:04 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.jcr;
 
 import java.io.IOException;
 import java.util.concurrent.ScheduledExecutorService;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.ItemExistsException;
@@ -39,8 +40,9 @@ import org.apache.jackrabbit.oak.api.Cha
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ConflictHandler;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.api.SessionQueryEngine;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.SessionQueryEngine;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.DefaultConflictHandler;
@@ -193,6 +195,22 @@ public class SessionDelegate {
         return (tree == null) ? null : new NodeDelegate(this, tree);
     }
 
+    @CheckForNull
+    /**
+     * {@code PropertyDelegate} at the given path
+     * @param path Oak path
+     * @return  The {@code PropertyDelegate} at {@code path} or {@code null} if
+     * none exists or not accessible.
+     */
+    public PropertyDelegate getProperty(String path) {
+        String parentPath = PathUtils.getParentPath(path);
+        String name = PathUtils.getName(path);
+
+        Tree parent = getTree(parentPath);
+        PropertyState propertyState = parent == null ? null : parent.getProperty(name);
+        return propertyState == null ? null : new PropertyDelegate(this, parent, propertyState);
+    }
+
     @Nonnull
     public ValueFactoryImpl getValueFactory() {
         return valueFactory;



Mime
View raw message