jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1456035 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/ oak-jcr/src/main/java/org/a...
Date Wed, 13 Mar 2013 16:29:13 GMT
Author: mduerig
Date: Wed Mar 13 16:29:12 2013
New Revision: 1456035

URL: http://svn.apache.org/r1456035
Log:
OAK-672: Avoid JCR APIs calling other JCR APIs
- Don't return implementation objects from SessionContext

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueFactoryImpl.java
    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/RepositoryImpl.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/WorkspaceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueFactoryImpl.java?rev=1456035&r1=1456034&r2=1456035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueFactoryImpl.java
Wed Mar 13 16:29:12 2013
@@ -81,26 +81,14 @@ public class ValueFactoryImpl implements
     }
 
     /**
-     * Utility method for creating a {@code Value} based on a {@code PropertyState}.
-     * @param property  The property state
-     * @return  New {@code Value} instance
-     * @throws IllegalArgumentException if {@code property.isArray()} is {@code true}.
-     */
-    public Value createValue(PropertyState property) {
-        return new ValueImpl(property, namePathMapper);
-    }
-
-    public static Value createValue(PropertyValue property, NamePathMapper namePathMapper)
{
-        return new ValueImpl(PropertyValues.create(property), namePathMapper);
-    }
-
-    /**
      * Utility method for creating a {@code Value} based on a {@code PropertyValue}.
      * @param property  The property value
+     * @param namePathMapper The name/path mapping used for converting JCR names/paths to
+     * the internal representation.
      * @return  New {@code Value} instance
      * @throws IllegalArgumentException if {@code property.isArray()} is {@code true}.
      */
-    public Value createValue(PropertyValue property) {
+    public static Value createValue(PropertyValue property, NamePathMapper namePathMapper)
{
         return new ValueImpl(PropertyValues.create(property), namePathMapper);
     }
 

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=1456035&r1=1456034&r2=1456035&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
Wed Mar 13 16:29:12 2013
@@ -22,6 +22,7 @@ import javax.jcr.Item;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.ValueFactory;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.ItemDefinition;
 import javax.jcr.nodetype.NodeTypeManager;
@@ -32,7 +33,6 @@ import org.apache.jackrabbit.oak.jcr.del
 import org.apache.jackrabbit.oak.jcr.delegate.SessionOperation;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.nodetype.DefinitionProvider;
-import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -237,7 +237,7 @@ abstract class ItemImpl<T extends ItemDe
      * @return the value factory
      */
     @Nonnull
-    ValueFactoryImpl getValueFactory() {
+    ValueFactory getValueFactory() {
         return sessionContext.getValueFactory();
     }
 

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=1456035&r1=1456034&r2=1456035&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
Wed Mar 13 16:29:12 2013
@@ -85,6 +85,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeTypeProvider;
 import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
+import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.util.TODO;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.slf4j.Logger;
@@ -997,7 +998,7 @@ public class NodeImpl<T extends NodeDele
                             JcrConstants.JCR_MIXINTYPES, Collections.singletonList(value)));
                 } else {
                     PropertyState property = mixins.getMultiState();
-                    List<Value> values = getValueFactory().createValues(property);
+                    List<Value> values = ValueFactoryImpl.createValues(property, sessionContext.getNamePathMapper());
                     if (!values.contains(value)) {
                         values.add(value);
                         nodeModified = true;

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=1456035&r1=1456034&r2=1456035&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
Wed Mar 13 16:29:12 2013
@@ -44,6 +44,7 @@ import org.apache.jackrabbit.oak.jcr.del
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionOperation;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -365,7 +366,7 @@ public class PropertyImpl extends ItemIm
 
             @Override
             public Value perform() throws RepositoryException {
-                return getValueFactory().createValue(dlg.getSingleState());
+                return ValueFactoryImpl.createValue(dlg.getSingleState(), sessionContext.getNamePathMapper());
             }
         });
     }
@@ -381,7 +382,7 @@ public class PropertyImpl extends ItemIm
 
             @Override
             public List<Value> perform() throws RepositoryException {
-                return getValueFactory().createValues(dlg.getMultiState());
+                return ValueFactoryImpl.createValues(dlg.getMultiState(), sessionContext.getNamePathMapper());
             }
         }).toArray(NO_VALUES);
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java?rev=1456035&r1=1456034&r2=1456035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
Wed Mar 13 16:29:12 2013
@@ -193,5 +193,4 @@ public class RepositoryImpl implements R
         return executor;
     }
 
-
 }
\ No newline at end of file

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=1456035&r1=1456034&r2=1456035&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
Wed Mar 13 16:29:12 2013
@@ -5,7 +5,11 @@ import java.util.Map;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.PathNotFoundException;
+import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.ValueFactory;
+import javax.jcr.Workspace;
 import javax.jcr.lock.LockManager;
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.observation.ObservationManager;
@@ -20,6 +24,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.namepath.LocalNameMapper;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
 import org.apache.jackrabbit.oak.plugins.name.Namespaces;
 import org.apache.jackrabbit.oak.plugins.nodetype.DefinitionProvider;
@@ -36,8 +41,8 @@ import static com.google.common.base.Pre
 public abstract class SessionContext {
     private final RepositoryImpl repository;
     private final SessionDelegate delegate;
-    private final NamePathMapperImpl namePathMapper;
-    private final ValueFactoryImpl valueFactory;
+    private final NamePathMapper namePathMapper;
+    private final ValueFactory valueFactory;
 
     private AccessControlManager accessControlManager;
     private PrincipalManager principalManager;
@@ -48,7 +53,7 @@ public abstract class SessionContext {
     private ObservationManagerImpl observationManager;
 
     private SessionContext(RepositoryImpl repository, SessionDelegate delegate,
-            NamePathMapperImpl namePathMapper, ValueFactoryImpl valueFactory) {
+            NamePathMapper namePathMapper, ValueFactory valueFactory) {
         this.delegate = delegate;
         this.repository = repository;
         this.namePathMapper = namePathMapper;
@@ -74,18 +79,18 @@ public abstract class SessionContext {
             private final WorkspaceImpl workspace = new WorkspaceImpl(this);
 
             @Override
-            public SessionImpl getSession() {
+            public Session getSession() {
                 return session;
             }
 
             @Override
-            public WorkspaceImpl getWorkspace() {
+            public WorkspaceImpl getWorkspaceInternal() {
                 return workspace;
             }
         };
     }
 
-    public RepositoryImpl getRepository() {
+    public Repository getRepository() {
         return repository;
     }
 
@@ -93,39 +98,43 @@ public abstract class SessionContext {
         return delegate;
     }
 
-    public abstract SessionImpl getSession();
+    public abstract Session getSession();
 
-    public abstract WorkspaceImpl getWorkspace();
+    protected abstract WorkspaceImpl getWorkspaceInternal();
+
+    public Workspace getWorkspace() {
+        return getWorkspaceInternal();
+    }
 
     public QueryManager getQueryManager() throws RepositoryException {
-        return getWorkspace().getQueryManager();
+        return getWorkspaceInternal().getQueryManager();
     }
 
     public LockManager getLockManager() {
-        return getWorkspace().getLockManager();
+        return getWorkspaceInternal().getLockManager();
     }
 
     public NodeTypeManager getNodeTypeManager() {
-        return getWorkspace().getNodeTypeManager();
+        return getWorkspaceInternal().getNodeTypeManager();
     }
 
     public VersionManager getVersionManager() throws RepositoryException {
-        return getWorkspace().getVersionManager();
+        return getWorkspaceInternal().getVersionManager();
     }
 
     public EffectiveNodeTypeProvider getEffectiveNodeTypeProvider() {
-        return getWorkspace().getReadWriteNodeTypeManager();
+        return getWorkspaceInternal().getReadWriteNodeTypeManager();
     }
 
     public DefinitionProvider getDefinitionProvider() {
-        return getWorkspace().getReadWriteNodeTypeManager();
+        return getWorkspaceInternal().getReadWriteNodeTypeManager();
     }
 
-    public NamePathMapperImpl getNamePathMapper() {
+    public NamePathMapper getNamePathMapper() {
         return namePathMapper;
     }
 
-    public ValueFactoryImpl getValueFactory() {
+    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=1456035&r1=1456034&r2=1456035&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 Mar 13 16:29:12 2013
@@ -89,13 +89,17 @@ public class SessionImpl extends Abstrac
         this.namespaces = namespaces;
     }
 
-    public void checkProtectedNodes(String... absJcrPaths) throws RepositoryException {
+    public static void checkProtectedNodes(Session session, String... absJcrPaths) throws
RepositoryException {
         for (String absPath : absJcrPaths) {
-            NodeImpl<?> node = (NodeImpl<?>) getNode(absPath);
+            NodeImpl<?> node = (NodeImpl<?>) session.getNode(absPath);
             node.checkProtected();
         }
     }
 
+    public void checkProtectedNodes(String... absJcrPaths) throws RepositoryException {
+        checkProtectedNodes(this, absJcrPaths);
+    }
+
     //------------------------------------------------------------< Session >---
 
     @Override

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1456035&r1=1456034&r2=1456035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Wed Mar 13 16:29:12 2013
@@ -23,6 +23,7 @@ import javax.annotation.Nonnull;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.ValueFactory;
 import javax.jcr.lock.LockManager;
@@ -102,7 +103,7 @@ public class WorkspaceImpl implements Ja
     //----------------------------------------------------------< Workspace >---
     @Override
     @Nonnull
-    public SessionImpl getSession() {
+    public Session getSession() {
         return sessionContext.getSession();
     }
 
@@ -128,7 +129,8 @@ public class WorkspaceImpl implements Ja
             throw new UnsupportedRepositoryOperationException("Not implemented.");
         }
 
-        getSession().checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
+        SessionImpl.checkProtectedNodes(
+                getSession(), Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
 
         String oakPath = getOakPathKeepIndexOrThrowNotFound(destAbsPath);
         String oakName = PathUtils.getName(oakPath);
@@ -150,7 +152,8 @@ public class WorkspaceImpl implements Ja
     public void clone(String srcWorkspace, String srcAbsPath, String destAbsPath, boolean
removeExisting) throws RepositoryException {
         ensureIsAlive();
 
-        getSession().checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
+        SessionImpl.checkProtectedNodes(
+                getSession(), Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
 
         // TODO
         throw new UnsupportedRepositoryOperationException("Not implemented.");
@@ -160,7 +163,8 @@ public class WorkspaceImpl implements Ja
     public void move(String srcAbsPath, String destAbsPath) throws RepositoryException {
         ensureIsAlive();
 
-        getSession().checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
+        SessionImpl.checkProtectedNodes(
+                getSession(), Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
 
         String oakPath = getOakPathKeepIndexOrThrowNotFound(destAbsPath);
         String oakName = PathUtils.getName(oakPath);

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java?rev=1456035&r1=1456034&r2=1456035&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
Wed Mar 13 16:29:12 2013
@@ -38,6 +38,7 @@ import org.apache.jackrabbit.oak.jcr.Nod
 import org.apache.jackrabbit.oak.jcr.SessionContext;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
+import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 
 /**
  * The implementation of the corresponding JCR interface.
@@ -240,7 +241,7 @@ public class QueryResultImpl implements 
         if (value == null) {
             return null;
         } else {
-            return sessionContext.getValueFactory().createValue(value);
+            return ValueFactoryImpl.createValue(value, sessionContext.getNamePathMapper());
         }
     }
 

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=1456035&r1=1456034&r2=1456035&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
Wed Mar 13 16:29:12 2013
@@ -54,14 +54,10 @@ class VersionImpl extends NodeImpl<Versi
                 getVersionManagerDelegate().getVersionHistory(dlg.getParent()), sessionContext);
     }
 
-    private ValueFactoryImpl getValueFactory() {
-        return sessionContext.getValueFactory();
-    }
-
     @Override
     public Calendar getCreated() throws RepositoryException {
         PropertyDelegate dlg = getPropertyOrThrow(JcrConstants.JCR_CREATED);
-        return getValueFactory().createValue(dlg.getSingleState()).getDate();
+        return ValueFactoryImpl.createValue(dlg.getSingleState(), sessionContext.getNamePathMapper()).getDate();
     }
 
     @Override
@@ -75,7 +71,7 @@ class VersionImpl extends NodeImpl<Versi
     }
 
     private List<Value> getValues(PropertyDelegate p) throws InvalidItemStateException,
ValueFormatException {
-        return getValueFactory().createValues(p.getMultiState());
+        return ValueFactoryImpl.createValues(p.getMultiState(), sessionContext.getNamePathMapper());
     }
 
     @Override



Mime
View raw message