jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1513050 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: ItemImpl.java NodeImpl.java PropertyImpl.java SessionContext.java SessionImpl.java query/QueryImpl.java version/VersionImpl.java
Date Mon, 12 Aug 2013 06:48:13 GMT
Author: jukka
Date: Mon Aug 12 06:48:13 2013
New Revision: 1513050

URL: http://svn.apache.org/r1513050
Log:
OAK-953: Allow sub-classing of SessionImpl

Move createNode() from SessionContext to NodeImpl to avoid overloading SessionContext

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.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/PropertyImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
    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/query/QueryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java?rev=1513050&r1=1513049&r2=1513050&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
Mon Aug 12 06:48:13 2013
@@ -189,7 +189,7 @@ abstract class ItemImpl<T extends ItemDe
         if (ancestor == dlg) {
             return this;
         } else if (ancestor instanceof NodeDelegate) {
-            return sessionContext.createNodeOrNull((NodeDelegate) ancestor);
+            return NodeImpl.createNode((NodeDelegate) ancestor, sessionContext);
         } else {
             throw new AccessDeniedException(
                     getPath() + ": Access denied to ancestor at depth " + depth);

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=1513050&r1=1513049&r2=1513050&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
Mon Aug 12 06:48:13 2013
@@ -55,6 +55,8 @@ import com.google.common.base.Predicate;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Iterators;
 import com.google.common.collect.Lists;
+
+import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.api.JackrabbitNode;
 import org.apache.jackrabbit.commons.ItemNameMatcher;
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
@@ -70,8 +72,11 @@ import org.apache.jackrabbit.oak.commons
 import org.apache.jackrabbit.oak.core.IdentifierManager;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
+import org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate;
 import org.apache.jackrabbit.oak.jcr.lock.LockImpl;
 import org.apache.jackrabbit.oak.jcr.operation.NodeOperation;
+import org.apache.jackrabbit.oak.jcr.version.VersionHistoryImpl;
+import org.apache.jackrabbit.oak.jcr.version.VersionImpl;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
 import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.oak.spi.security.authorization.permission.Permissions;
@@ -107,6 +112,34 @@ public class NodeImpl<T extends NodeDele
      */
     private static final Logger log = LoggerFactory.getLogger(NodeImpl.class);
 
+    public static NodeImpl<? extends NodeDelegate> createNodeOrNull(
+            NodeDelegate delegate, SessionContext context)
+            throws RepositoryException {
+        if (delegate != null) {
+            return createNode(delegate, context);
+        } else {
+            return null;
+        }
+    }
+
+    public static NodeImpl<? extends NodeDelegate> createNode(
+                NodeDelegate delegate, SessionContext context)
+                throws RepositoryException {
+        PropertyDelegate pd = delegate.getPropertyOrNull(JCR_PRIMARYTYPE);
+        String type = pd != null ? pd.getString() : null;
+        if (JcrConstants.NT_VERSION.equals(type)) {
+            VersionManagerDelegate vmd =
+                    VersionManagerDelegate.create(context.getSessionDelegate());
+            return new VersionImpl(vmd.createVersion(delegate), context);
+        } else if (JcrConstants.NT_VERSIONHISTORY.equals(type)) {
+            VersionManagerDelegate vmd =
+                    VersionManagerDelegate.create(context.getSessionDelegate());
+            return new VersionHistoryImpl(vmd.createVersionHistory(delegate), context);
+        } else {
+            return new NodeImpl<NodeDelegate>(delegate, context);
+        }
+    }
+
     public NodeImpl(T dlg, SessionContext sessionContext) {
         super(dlg, sessionContext);
     }
@@ -137,7 +170,7 @@ public class NodeImpl<T extends NodeDele
                     if (parent == null) {
                         throw new AccessDeniedException();
                     }
-                    return sessionContext.createNodeOrNull(parent);
+                    return NodeImpl.createNode(parent, sessionContext);
                 }
             }
         });
@@ -252,7 +285,7 @@ public class NodeImpl<T extends NodeDele
                 if (added == null) {
                     throw new ItemExistsException();
                 }
-                return sessionContext.createNodeOrNull(added);
+                return NodeImpl.createNode(added, sessionContext);
             }
         });
     }
@@ -489,7 +522,7 @@ public class NodeImpl<T extends NodeDele
                 if (nd == null) {
                     throw new PathNotFoundException(oakPath);
                 } else {
-                    return sessionContext.createNodeOrNull(nd);
+                    return NodeImpl.createNode(nd, sessionContext);
                 }
             }
         });

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1513050&r1=1513049&r2=1513050&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
Mon Aug 12 06:48:13 2013
@@ -74,7 +74,7 @@ public class PropertyImpl extends ItemIm
                 if (parent == null) {
                     throw new AccessDeniedException();
                 } else {
-                    return sessionContext.createNodeOrNull(parent);
+                    return NodeImpl.createNode(parent, sessionContext);
                 }
             }
         });

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java?rev=1513050&r1=1513049&r2=1513050&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionContext.java
Mon Aug 12 06:48:13 2013
@@ -39,7 +39,6 @@ import javax.jcr.observation.Observation
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.version.VersionManager;
 
-import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.Authorizable;
@@ -49,15 +48,10 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
-import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
-import org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate;
 import org.apache.jackrabbit.oak.jcr.observation.ObservationManagerImpl;
 import org.apache.jackrabbit.oak.jcr.operation.SessionOperation;
 import org.apache.jackrabbit.oak.jcr.security.AccessManager;
-import org.apache.jackrabbit.oak.jcr.version.VersionHistoryImpl;
-import org.apache.jackrabbit.oak.jcr.version.VersionImpl;
 import org.apache.jackrabbit.oak.namepath.LocalNameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
@@ -84,6 +78,7 @@ import org.apache.jackrabbit.oak.spi.xml
  * {@code ValueFactory}, etc.).
  */
 public class SessionContext implements NamePathMapper {
+
     private final RepositoryImpl repository;
     private final Whiteboard whiteboard;
     private final SessionDelegate delegate;
@@ -169,23 +164,6 @@ public class SessionContext implements N
         return namespaces;
     }
 
-    public NodeImpl createNodeOrNull(NodeDelegate nd) throws RepositoryException {
-        if (nd == null) {
-            return null;
-        }
-        PropertyDelegate pd = nd.getPropertyOrNull(JcrConstants.JCR_PRIMARYTYPE);
-        String type = pd != null ? pd.getString() : null;
-        if (JcrConstants.NT_VERSION.equals(type)) {
-            VersionManagerDelegate delegate = VersionManagerDelegate.create(getSessionDelegate());
-            return new VersionImpl(delegate.createVersion(nd), this);
-        } else if (JcrConstants.NT_VERSIONHISTORY.equals(type)) {
-            VersionManagerDelegate delegate = VersionManagerDelegate.create(getSessionDelegate());
-            return new VersionHistoryImpl(delegate.createVersionHistory(nd), this);
-        } else {
-            return new NodeImpl<NodeDelegate>(nd, this);
-        }
-    }
-
     public ValueFactory getValueFactory() {
         return valueFactory;
     }

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=1513050&r1=1513049&r2=1513050&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
Mon Aug 12 06:48:13 2013
@@ -140,7 +140,7 @@ public class SessionImpl implements Jack
             throws RepositoryException {
         ItemDelegate item = sd.getItem(oakPath);
         if (item instanceof NodeDelegate) {
-            return sessionContext.createNodeOrNull((NodeDelegate) item);
+            return NodeImpl.createNodeOrNull((NodeDelegate) item, sessionContext);
         } else if (item instanceof PropertyDelegate) {
             return new PropertyImpl((PropertyDelegate) item, sessionContext);
         } else {
@@ -161,7 +161,7 @@ public class SessionImpl implements Jack
         return perform(new ReadOperation<Node>() {
             @Override
             public Node perform() throws RepositoryException {
-                return sessionContext.createNodeOrNull(sd.getNode(getOakPathOrThrow(absPath)));
+                return NodeImpl.createNodeOrNull(sd.getNode(getOakPathOrThrow(absPath)),
sessionContext);
             }
         });
     }
@@ -271,7 +271,7 @@ public class SessionImpl implements Jack
                 if (nd == null) {
                     throw new AccessDeniedException("Root node is not accessible.");
                 }
-                return sessionContext.createNodeOrNull(nd);
+                return NodeImpl.createNodeOrNull(nd, sessionContext);
             }
         });
     }
@@ -299,7 +299,7 @@ public class SessionImpl implements Jack
                 if (nd == null) {
                     throw new ItemNotFoundException("Node with id " + id + " does not exist.");
                 }
-                return sessionContext.createNodeOrNull(nd);
+                return NodeImpl.createNodeOrNull(nd, sessionContext);
             }
         });
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java?rev=1513050&r1=1513049&r2=1513050&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
Mon Aug 12 06:48:13 2013
@@ -34,6 +34,7 @@ import javax.jcr.version.VersionExceptio
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.jcr.NodeImpl;
 import org.apache.jackrabbit.oak.jcr.SessionContext;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 
@@ -139,7 +140,7 @@ public class QueryImpl implements Query 
         if (parentDelegate == null) {
             throw new PathNotFoundException("The specified path does not exist: " + parent);
         }
-        Node parentNode = sessionContext.createNodeOrNull(parentDelegate);
+        Node parentNode = NodeImpl.createNodeOrNull(parentDelegate, sessionContext);
         if (!parentNode.isCheckedOut()) {
             throw new VersionException("Cannot store query. Node at " +
                     absPath + " is checked in.");

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java?rev=1513050&r1=1513049&r2=1513050&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
Mon Aug 12 06:48:13 2013
@@ -124,8 +124,9 @@ public class VersionImpl extends NodeImp
         return perform(new SessionOperation<Node>() {
             @Override
             public Node perform() throws RepositoryException {
-                return sessionContext.createNodeOrNull(
-                        dlg.getChild(VersionConstants.JCR_FROZENNODE));
+                return NodeImpl.createNodeOrNull(
+                        dlg.getChild(VersionConstants.JCR_FROZENNODE),
+                        sessionContext);
             }
         });
     }



Mime
View raw message