jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1456022 [2/2] - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/m...
Date Wed, 13 Mar 2013 16:23:29 GMT
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=1456022&r1=1456021&r2=1456022&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 Mar 13 16:23:28 2013
@@ -17,27 +17,14 @@
 package org.apache.jackrabbit.oak.jcr.delegate;
 
 import java.io.IOException;
-import java.util.Map;
-import java.util.concurrent.ScheduledExecutorService;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.ItemExistsException;
 import javax.jcr.PathNotFoundException;
-import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.UnsupportedRepositoryOperationException;
-import javax.jcr.Workspace;
-import javax.jcr.lock.LockManager;
-import javax.jcr.nodetype.NodeTypeManager;
-import javax.jcr.observation.ObservationManager;
-import javax.jcr.security.AccessControlManager;
-import javax.jcr.version.VersionManager;
-
-import com.google.common.collect.Maps;
-import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
-import org.apache.jackrabbit.api.security.principal.PrincipalManager;
-import org.apache.jackrabbit.api.security.user.UserManager;
+
 import org.apache.jackrabbit.oak.api.AuthInfo;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentSession;
@@ -48,21 +35,7 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.IdentifierManager;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
-import org.apache.jackrabbit.oak.jcr.SessionImpl;
-import org.apache.jackrabbit.oak.jcr.WorkspaceImpl;
-import org.apache.jackrabbit.oak.namepath.LocalNameMapper;
-import org.apache.jackrabbit.oak.namepath.NameMapper;
-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;
-import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeTypeProvider;
-import org.apache.jackrabbit.oak.plugins.observation.ObservationManagerImpl;
-import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
-import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
-import org.apache.jackrabbit.oak.spi.security.authorization.AccessControlConfiguration;
-import org.apache.jackrabbit.oak.spi.security.authorization.PermissionProvider;
-import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -91,27 +64,10 @@ import static com.google.common.base.Pre
 public class SessionDelegate {
     static final Logger log = LoggerFactory.getLogger(SessionDelegate.class);
 
-    private final NamePathMapper namePathMapper;
-    private final Repository repository;
-    private final ScheduledExecutorService executor;
     private final ContentSession contentSession;
-    private final ValueFactoryImpl valueFactory;
-    private final Workspace workspace;
-    private final SessionImpl session;
     private final Root root;
-    private final boolean autoRefresh;
-
-    private final SecurityProvider securityProvider;
-
     private final IdentifierManager idManager;
 
-    private ObservationManagerImpl observationManager;
-    private PrincipalManager principalManager;
-    private UserManager userManager;
-    private PrivilegeManager privilegeManager;
-    private AccessControlManager accessControlManager;
-    private UserConfiguration userConfiguration;
-    private AccessControlConfiguration accessControlConfiguration;
     private boolean isAlive = true;
     private int sessionOpCount;
     private int revision;
@@ -133,39 +89,13 @@ public class SessionDelegate {
         }
     }
 
-    public SessionDelegate(@Nonnull Repository repository, @Nonnull ScheduledExecutorService
executor,
-                    @Nonnull ContentSession contentSession, @Nonnull SecurityProvider securityProvider,
-                    boolean autoRefresh) {
-
-        this.repository = checkNotNull(repository);
-        this.executor = executor;
+    public SessionDelegate(@Nonnull ContentSession contentSession) {
         this.contentSession = checkNotNull(contentSession);
-        this.securityProvider = checkNotNull(securityProvider);
-        this.autoRefresh = autoRefresh;
-
         this.root = contentSession.getLatestRoot();
-        // FIXME: do not pass partially initialized 'this'
-        this.workspace = new WorkspaceImpl(this);
-
-        Map<String, String> namespaces = Maps.newHashMap();
-        NameMapper mapper = new LocalNameMapper(namespaces) {
-            @Override
-            protected Map<String, String> getNamespaceMap() {
-                return Namespaces.getNamespaceMap(root.getTree("/"));
-            }
-        };
-        this.session = new SessionImpl(this, namespaces);
         this.idManager = new IdentifierManager(root);
-        this.namePathMapper = new NamePathMapperImpl(mapper, idManager);
-        this.valueFactory = new ValueFactoryImpl(root.getBlobFactory(), namePathMapper);
     }
 
-    private boolean needsRefresh() {
-        // Refresh is always needed if this is an auto refresh session. Otherwise
-        // refresh in only needed for non re-entrant session operations and only if
-        // observation events have actually been delivered
-        return autoRefresh ||
-                (sessionOpCount <= 1 && observationManager != null &&
observationManager.hasEvents());
+    protected void refresh() {
     }
 
     /**
@@ -182,10 +112,10 @@ public class SessionDelegate {
     public synchronized <T> T perform(SessionOperation<T> sessionOperation) throws
RepositoryException {
         // Synchronize to avoid conflicting refreshes from concurrent JCR API calls
         try {
-            if (needsRefresh()) {
-                refresh(true);
+            if (sessionOpCount == 0) {
+                // Refresh only for non re-entrant session operations
+                refresh();
             }
-
             sessionOpCount++;
             sessionOperation.checkPreconditions();
             return sessionOperation.perform();
@@ -204,6 +134,16 @@ public class SessionDelegate {
         }
     }
 
+    @Nonnull
+    public Root getRoot() {
+        return root;
+    }
+
+    @Nonnull
+    public ContentSession getContentSession() {
+        return contentSession;
+    }
+
     public boolean isAlive() {
         return isAlive;
     }
@@ -218,31 +158,11 @@ public class SessionDelegate {
         return false;
     }
 
-    /**
-     * Revision of this session. The revision is incremented each time a session is refreshed
or saved.
-     * This allows items to determine whether they need to re-resolve their underlying state
when the
-     * revision on which an item is based does not match the revision of the session any
more.
-     * @return  the current revision of this session
-     */
-    int getRevision() {
-        return revision;
-    }
-
-    @Nonnull
-    public Session getSession() {
-        return session;
-    }
-
     @Nonnull
     public AuthInfo getAuthInfo() {
         return contentSession.getAuthInfo();
     }
 
-    @Nonnull
-    public Repository getRepository() {
-        return repository;
-    }
-
     public void logout() {
         if (!isAlive) {
             // ignore
@@ -250,9 +170,6 @@ public class SessionDelegate {
         }
 
         isAlive = false;
-        if (observationManager != null) {
-            observationManager.dispose();
-        }
         // TODO
 
         try {
@@ -262,15 +179,20 @@ public class SessionDelegate {
         }
     }
 
+    @Nonnull
+    public IdentifierManager getIdManager() {
+        return idManager;
+    }
+
+    @Nonnull
+    public TreeLocation getLocation(String path) {
+        return root.getLocation(path);
+    }
+
     @CheckForNull
     public NodeDelegate getRootNode() {
         return getNode("/");
     }
-    
-    @CheckForNull
-    public Root getRoot() {
-        return root;
-    }
 
     /**
      * {@code NodeDelegate} at the given path
@@ -289,13 +211,13 @@ 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.
      */
+    @CheckForNull
     public PropertyDelegate getProperty(String path) {
         TreeLocation location = root.getLocation(path);
         return location.getProperty() == null
@@ -303,16 +225,6 @@ public class SessionDelegate {
             : new PropertyDelegate(this, location);
     }
 
-    @Nonnull
-    public ValueFactoryImpl getValueFactory() {
-        return valueFactory;
-    }
-
-    @Nonnull
-    public NamePathMapper getNamePathMapper() {
-        return namePathMapper;
-    }
-
     public boolean hasPendingChanges() {
         return root.hasPendingChanges();
     }
@@ -335,93 +247,9 @@ public class SessionDelegate {
         revision++;
     }
 
-    /**
-     * Returns the Oak name for the given JCR name, or throws a
-     * {@link RepositoryException} if the name is invalid or can
-     * otherwise not be mapped.
-     *
-     * @param jcrName JCR name
-     * @return Oak name
-     * @throws RepositoryException if the name is invalid
-     */
-    @Nonnull
-    public String getOakName(String jcrName) throws RepositoryException {
-        return getNamePathMapper().getOakName(jcrName);
-    }
-
-    /**
-     * Shortcut for {@code SessionDelegate.getNamePathMapper().getOakPath(jcrPath)}.
-     *
-     * @param jcrPath JCR path
-     * @return Oak path, or {@code null}
-     */
-    @CheckForNull
-    public String getOakPathOrNull(String jcrPath) {
-        return getNamePathMapper().getOakPath(jcrPath);
-    }
-
-    /**
-     * Shortcut for {@code SessionDelegate.getOakPathKeepIndex(jcrPath)}.
-     *
-     * @param jcrPath JCR path
-     * @return Oak path, or {@code null}, with indexes left intact
-     * @throws PathNotFoundException 
-     */
-    @Nonnull
-    public String getOakPathKeepIndexOrThrowNotFound(String jcrPath) throws PathNotFoundException
{
-        String oakPath = getNamePathMapper().getOakPathKeepIndex(jcrPath);
-        if (oakPath != null) {
-            return oakPath;
-        } else {
-            throw new PathNotFoundException(jcrPath);
-        }
-    }
-
-    /**
-     * Returns the Oak path for the given JCR path, or throws a
-     * {@link PathNotFoundException} if the path can not be mapped.
-     *
-     * @param jcrPath JCR path
-     * @return Oak path
-     * @throws PathNotFoundException if the path can not be mapped
-     */
-    @Nonnull
-    public String getOakPathOrThrowNotFound(String jcrPath) throws PathNotFoundException
{
-        String oakPath = getOakPathOrNull(jcrPath);
-        if (oakPath != null) {
-            return oakPath;
-        } else {
-            throw new PathNotFoundException(jcrPath);
-        }
-    }
-
-    /**
-     * Returns the Oak path for the given JCR path, or throws a
-     * {@link RepositoryException} if the path can not be mapped.
-     *
-     * @param jcrPath JCR path
-     * @return Oak path
-     * @throws RepositoryException if the path can not be mapped
-     */
-    @Nonnull
-    public String getOakPath(String jcrPath)
-            throws RepositoryException {
-        String oakPath = getOakPathOrNull(jcrPath);
-        if (oakPath != null) {
-            return oakPath;
-        } else {
-            throw new RepositoryException("Invalid name or path: " + jcrPath);
-        }
-    }
-
     //----------------------------------------------------------< Workspace >---
 
     @Nonnull
-    public Workspace getWorkspace() {
-        return workspace;
-    }
-
-    @Nonnull
     public String getWorkspaceName() {
         return contentSession.getWorkspaceName();
     }
@@ -504,44 +332,22 @@ public class SessionDelegate {
     }
 
     @Nonnull
-    public LockManager getLockManager() throws RepositoryException {
-        return workspace.getLockManager();
-    }
-
-    @Nonnull
     public QueryEngine getQueryEngine() {
         return root.getQueryEngine();
     }
 
-    @Nonnull
-    public NodeTypeManager getNodeTypeManager() throws RepositoryException {
-        return workspace.getNodeTypeManager();
-    }
-
-    @Nonnull
-    public VersionManager getVersionManager() throws RepositoryException {
-        return workspace.getVersionManager();
-    }
-
-    @Nonnull
-    public ObservationManager getObservationManager() {
-        if (observationManager == null) {
-            observationManager = new ObservationManagerImpl(getRoot(), getNamePathMapper(),
executor);
-        }
-        return observationManager;
-    }
-
-    public IdentifierManager getIdManager() {
-        return idManager;
-    }
+    //-----------------------------------------------------------< internal >---
 
-    @Nonnull
-    public ContentSession getContentSession() {
-        return contentSession;
+    /**
+     * Revision of this session. The revision is incremented each time a session is refreshed
or saved.
+     * This allows items to determine whether they need to re-resolve their underlying state
when the
+     * revision on which an item is based does not match the revision of the session any
more.
+     * @return  the current revision of this session
+     */
+    int getRevision() {
+        return revision;
     }
 
-    //-----------------------------------------------------------< internal >---
-
     /**
      * Get the {@code Tree} with the given path
      * @param path  oak path
@@ -549,80 +355,12 @@ public class SessionDelegate {
      * if the tree at {@code path} is not accessible.
      */
     @CheckForNull
-    Tree getTree(String path) {
+    private Tree getTree(String path) {
         return root.getTree(path);
     }
 
-    @Nonnull
-    public TreeLocation getLocation(String path) {
-        return root.getLocation(path);
-    }
-
-    @Nonnull
-    public AccessControlManager getAccessControlManager() throws RepositoryException {
-        if (accessControlManager == null) {
-            accessControlManager = securityProvider.getAccessControlConfiguration().getAccessControlManager(root,
getNamePathMapper());
-        }
-        return accessControlManager;
-    }
-
-    @Nonnull
-    public PermissionProvider getPermissionProvider() throws RepositoryException {
-        // TODO
-        return securityProvider.getAccessControlConfiguration().getPermissionProvider(root,
getAuthInfo().getPrincipals());
-    }
-
-    @Nonnull
-    public PrincipalManager getPrincipalManager() throws RepositoryException {
-        if (principalManager == null) {
-            principalManager = securityProvider.getPrincipalConfiguration().getPrincipalManager(root,
getNamePathMapper());
-        }
-        return principalManager;
-    }
-
-    @Nonnull
-    public UserManager getUserManager() throws UnsupportedRepositoryOperationException {
-        if (userManager == null) {
-            userManager = securityProvider.getUserConfiguration().getUserManager(root, getNamePathMapper());
-        }
-        return userManager;
-    }
-
-    @Nonnull
-    public PrivilegeManager getPrivilegeManager() throws UnsupportedRepositoryOperationException
{
-        if (privilegeManager == null) {
-            privilegeManager = securityProvider.getPrivilegeConfiguration().getPrivilegeManager(root,
getNamePathMapper());
-        }
-        return privilegeManager;
-    }
-
-    @Nonnull
-    public UserConfiguration getUserConfiguration() throws UnsupportedRepositoryOperationException
{
-        if (userConfiguration == null) {
-            userConfiguration = securityProvider.getUserConfiguration();
-        }
-        return userConfiguration;
-    }
-
-    @Nonnull
-    public AccessControlConfiguration getAccessControlConfiguration() throws UnsupportedRepositoryOperationException
{
-        if (accessControlConfiguration == null) {
-            accessControlConfiguration = securityProvider.getAccessControlConfiguration();
-        }
-        return accessControlConfiguration;
-    }
-
-    @Nonnull
-    public EffectiveNodeTypeProvider getEffectiveNodeTypeProvider() throws RepositoryException
{
-        return (EffectiveNodeTypeProvider) workspace.getNodeTypeManager();
-    }
-
-    @Nonnull
-    public DefinitionProvider getDefinitionProvider() throws RepositoryException {
-        return (DefinitionProvider) workspace.getNodeTypeManager();
-    }
-
     public void checkProtectedNodes(String... absJcrPaths) throws RepositoryException {
+        Session session = SessionContextProvider.getSession(this);
         for (String absPath : absJcrPaths) {
             NodeImpl<?> node = (NodeImpl<?>) session.getNode(absPath);
             node.checkProtected();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java?rev=1456022&r1=1456021&r2=1456022&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
Wed Mar 13 16:23:28 2013
@@ -26,6 +26,7 @@ import java.util.TreeMap;
 import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.RepositoryException;
+import javax.jcr.ValueFormatException;
 import javax.jcr.version.VersionException;
 
 import com.google.common.base.Function;
@@ -34,6 +35,8 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
+import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.plugins.version.VersionConstants;
 
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -123,11 +126,23 @@ public class VersionHistoryDelegate exte
         SortedMap<Calendar, String> versions = new TreeMap<Calendar, String>();
         for (Iterator<NodeDelegate> it = getChildren(); it.hasNext(); ) {
             NodeDelegate n = it.next();
-            String primaryType = n.getProperty(JcrConstants.JCR_PRIMARYTYPE).getValue().getString();
+            PropertyState propertyState = n.getProperty(JcrConstants.JCR_PRIMARYTYPE).getPropertyState();
+            if (propertyState == null) {
+                throw new InvalidItemStateException();
+            }
+            String primaryType = propertyState.getValue(Type.STRING);
             if (primaryType.equals(VersionConstants.NT_VERSION)) {
                 PropertyDelegate created = n.getProperty(JcrConstants.JCR_CREATED);
                 if (created != null) {
-                    versions.put(created.getValue().getDate(), n.getName());
+                    PropertyState property = created.getPropertyState();
+                    if (property == null) {
+                        throw new InvalidItemStateException();
+                    }
+                    if (property.isArray()) {
+                        throw new ValueFormatException(created + " is multi-valued.");
+                    }
+                    ValueFactoryImpl f = SessionContextProvider.getValueFactory(sessionDelegate);
+                    versions.put(f.createValue(property).getDate(), n.getName());
                 }
             }
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java?rev=1456022&r1=1456021&r2=1456022&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
Wed Mar 13 16:23:28 2013
@@ -20,6 +20,7 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.annotation.Nonnull;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -27,7 +28,7 @@ import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
 import javax.jcr.lock.LockManager;
 
-import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 
 /**
@@ -96,7 +97,8 @@ public class LockManagerImpl implements 
         getSession().getNode(absPath).unlock();
     }
 
+    @Nonnull
     private Session getSession() {
-        return sessionDelegate.getSession();
+        return SessionContextProvider.getSession(sessionDelegate);
     }
 }
\ No newline at end of file

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=1456022&r1=1456021&r2=1456022&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
Wed Mar 13 16:23:28 2013
@@ -33,10 +33,10 @@ import javax.jcr.version.VersionExceptio
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
-import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 
 /**
  * The implementation of the corresponding JCR interface.
@@ -133,7 +133,7 @@ public class QueryImpl implements Query 
     public Node storeAsNode(String absPath) throws RepositoryException {
         manager.ensureIsAlive();
         SessionDelegate sessionDelegate = manager.getSessionDelegate();
-        String oakPath = sessionDelegate.getOakPath(absPath);
+        String oakPath = SessionContextProvider.getOakPath(sessionDelegate, absPath);
         String parent = PathUtils.getParentPath(oakPath);
         NodeDelegate parentDelegate = sessionDelegate.getNode(parent);
         if (parentDelegate == null) {
@@ -145,7 +145,7 @@ public class QueryImpl implements Query 
                     absPath + " is checked in.");
         }
         String nodeName = PathUtils.getName(oakPath);
-        ValueFactory vf = sessionDelegate.getValueFactory();
+        ValueFactory vf = SessionContextProvider.getValueFactory(sessionDelegate);
         Node n = parentNode.addNode(nodeName, JcrConstants.NT_QUERY);
         n.setProperty(JcrConstants.JCR_STATEMENT, vf.createValue(statement));
         n.setProperty(JcrConstants.JCR_LANGUAGE, vf.createValue(language));

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java?rev=1456022&r1=1456021&r2=1456022&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
Wed Mar 13 16:23:28 2013
@@ -39,6 +39,7 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.QueryEngine;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.query.qom.QueryObjectModelFactoryImpl;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -57,7 +58,7 @@ public class QueryManagerImpl implements
 
     public QueryManagerImpl(SessionDelegate sessionDelegate) {
         this.sessionDelegate = sessionDelegate;
-        qomFactory = new QueryObjectModelFactoryImpl(this, sessionDelegate.getValueFactory());
+        qomFactory = new QueryObjectModelFactoryImpl(this, sessionDelegate);
         queryEngine = sessionDelegate.getQueryEngine();
         supportedQueryLanguages.addAll(queryEngine.getSupportedQueryLanguages());
     }
@@ -116,7 +117,7 @@ public class QueryManagerImpl implements
             long limit, long offset, HashMap<String, Value> bindVariableMap) throws
RepositoryException {
         try {
             Map<String, PropertyValue> bindMap = convertMap(bindVariableMap);
-            NamePathMapper namePathMapper = sessionDelegate.getNamePathMapper();
+            NamePathMapper namePathMapper = SessionContextProvider.getNamePathMapper(sessionDelegate);
             Result r = queryEngine.executeQuery(statement, language, limit, offset,
                     bindMap, namePathMapper);
             return new QueryResultImpl(sessionDelegate, r);

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=1456022&r1=1456021&r2=1456022&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:23:28 2013
@@ -34,12 +34,10 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.ResultRow;
 import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
-import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 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.
@@ -237,9 +235,11 @@ public class QueryResultImpl implements 
     }
 
     Value createValue(PropertyValue value) {
-        return value == null
-            ? null
-            : ValueFactoryImpl.createValue(value, sessionDelegate.getNamePathMapper());
+        if (value == null) {
+            return null;
+        } else {
+            return SessionContextProvider.getValueFactory(sessionDelegate).createValue(value);
+        }
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java?rev=1456022&r1=1456021&r2=1456022&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
Wed Mar 13 16:23:28 2013
@@ -15,7 +15,6 @@ package org.apache.jackrabbit.oak.jcr.qu
 
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
-import javax.jcr.ValueFactory;
 import javax.jcr.query.qom.ChildNode;
 import javax.jcr.query.qom.ChildNodeJoinCondition;
 import javax.jcr.query.qom.Column;
@@ -47,6 +46,9 @@ import javax.jcr.query.qom.Selector;
 import javax.jcr.query.qom.Source;
 import javax.jcr.query.qom.StaticOperand;
 import javax.jcr.query.qom.UpperCase;
+
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
+import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
 
 /**
@@ -55,11 +57,11 @@ import org.apache.jackrabbit.oak.jcr.que
 public class QueryObjectModelFactoryImpl implements QueryObjectModelFactory {
 
     private final QueryManagerImpl queryManager;
-    private final ValueFactory valueFactory;
+    private final SessionDelegate sessionDelegate;
 
-    public QueryObjectModelFactoryImpl(QueryManagerImpl queryManager, ValueFactory valueFactory)
{
+    public QueryObjectModelFactoryImpl(QueryManagerImpl queryManager, SessionDelegate sessionDelegate)
{
         this.queryManager = queryManager;
-        this.valueFactory = valueFactory;
+        this.sessionDelegate = sessionDelegate;
     }
 
     @Override
@@ -218,8 +220,9 @@ public class QueryObjectModelFactoryImpl
     @Override
     public QueryObjectModel createQuery(Source source, Constraint constraint, 
             Ordering[] orderings, Column[] columns) {
-        QueryObjectModelImpl qom = new QueryObjectModelImpl(queryManager, 
-                valueFactory, source, constraint, orderings, columns);
+        QueryObjectModelImpl qom = new QueryObjectModelImpl(queryManager,
+                SessionContextProvider.getValueFactory(sessionDelegate),
+                source, constraint, orderings, columns);
         qom.bindVariables();
         return qom;
     }
@@ -228,7 +231,7 @@ public class QueryObjectModelFactoryImpl
         if (jcrName == null) {
             return null;
         }
-        return queryManager.getSessionDelegate().getOakName(jcrName);
+        return SessionContextProvider.getOakName(queryManager.getSessionDelegate(), jcrName);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java?rev=1456022&r1=1456021&r2=1456022&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
Wed Mar 13 16:23:28 2013
@@ -34,6 +34,7 @@ import javax.jcr.version.VersionIterator
 import org.apache.jackrabbit.commons.iterator.FrozenNodeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.VersionIteratorAdapter;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionHistoryDelegate;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -102,7 +103,7 @@ public class VersionHistoryImpl extends 
     @Override
     public Version getVersionByLabel(String label)
             throws VersionException, RepositoryException {
-        String oakLabel = sessionDelegate.getOakName(label);
+        String oakLabel = SessionContextProvider.getOakName(sessionDelegate, label);
         return new VersionImpl(dlg.getVersionByLabel(oakLabel));
     }
 
@@ -134,7 +135,7 @@ public class VersionHistoryImpl extends 
 
     @Override
     public String[] getVersionLabels() throws RepositoryException {
-        NamePathMapper mapper = sessionDelegate.getNamePathMapper();
+        NamePathMapper mapper = SessionContextProvider.getNamePathMapper(sessionDelegate);
         List<String> labels = new ArrayList<String>();
         for (String label : dlg.getVersionLabels()) {
             labels.add(mapper.getJcrName(label));
@@ -149,7 +150,7 @@ public class VersionHistoryImpl extends 
             throw new VersionException("Version is not contained in this " +
                     "VersionHistory");
         }
-        NamePathMapper mapper = sessionDelegate.getNamePathMapper();
+        NamePathMapper mapper = SessionContextProvider.getNamePathMapper(sessionDelegate);
         List<String> labels = new ArrayList<String>();
         for (String label : dlg.getVersionLabels(version.getIdentifier())) {
             labels.add(mapper.getJcrName(label));

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=1456022&r1=1456021&r2=1456022&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:23:28 2013
@@ -21,18 +21,23 @@ import java.util.Calendar;
 import java.util.List;
 
 import javax.annotation.Nonnull;
+import javax.jcr.InvalidItemStateException;
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 
 import org.apache.jackrabbit.JcrConstants;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.VersionManagerDelegate;
+import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.plugins.version.VersionConstants;
 import org.apache.jackrabbit.oak.util.TODO;
 
@@ -50,9 +55,21 @@ class VersionImpl extends NodeImpl<Versi
                 getVersionManagerDelegate().getVersionHistory(dlg.getParent()));
     }
 
+    private ValueFactoryImpl getValueFactory() {
+        return SessionContextProvider.getValueFactory(sessionDelegate);
+    }
+
     @Override
     public Calendar getCreated() throws RepositoryException {
-        return getPropertyOrThrow(JcrConstants.JCR_CREATED).getValue().getDate();
+        PropertyDelegate dlg = getPropertyOrThrow(JcrConstants.JCR_CREATED);
+        PropertyState property = dlg.getPropertyState();
+        if (property == null) {
+            throw new InvalidItemStateException();
+        }
+        if (property.isArray()) {
+            throw new ValueFormatException(dlg + " is multi-valued.");
+        }
+        return getValueFactory().createValue(property).getDate();
     }
 
     @Override
@@ -65,12 +82,23 @@ class VersionImpl extends NodeImpl<Versi
         return TODO.unimplemented().returnValue(null);
     }
 
+    private List<Value> getValues(PropertyDelegate p) throws InvalidItemStateException,
ValueFormatException {
+        PropertyState property = p.getPropertyState();
+        if (property == null) {
+            throw new InvalidItemStateException();
+        }
+        if (!property.isArray()) {
+            throw new ValueFormatException(p + " is single-valued.");
+        }
+        return getValueFactory().createValues(property);
+    }
+
     @Override
     public Version[] getPredecessors() throws RepositoryException {
         PropertyDelegate p = getPropertyOrThrow(VersionConstants.JCR_PREDECESSORS);
         List<Version> predecessors = new ArrayList<Version>();
         VersionManagerDelegate vMgr = getVersionManagerDelegate();
-        for (Value v : p.getValues()) {
+        for (Value v : getValues(p)) {
             String id = v.getString();
             predecessors.add(new VersionImpl(vMgr.getVersionByIdentifier(id)));
         }
@@ -82,7 +110,7 @@ class VersionImpl extends NodeImpl<Versi
         PropertyDelegate p = getPropertyOrThrow(VersionConstants.JCR_SUCCESSORS);
         List<Version> successors = new ArrayList<Version>();
         VersionManagerDelegate vMgr = getVersionManagerDelegate();
-        for (Value v : p.getValues()) {
+        for (Value v : getValues(p)) {
             String id = v.getString();
             successors.add(new VersionImpl(vMgr.getVersionByIdentifier(id)));
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java?rev=1456022&r1=1456021&r2=1456022&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
Wed Mar 13 16:23:28 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.jcr.version;
 
+import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.ItemExistsException;
 import javax.jcr.Node;
@@ -24,12 +25,14 @@ import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.lock.LockException;
+import javax.jcr.lock.LockManager;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionException;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionManager;
 
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionOperation;
@@ -116,7 +119,7 @@ public class VersionManagerImpl implemen
         return sessionDelegate.perform(new SessionOperation<Boolean>() {
             @Override
             public Boolean perform() throws RepositoryException {
-                String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+                String oakPath = getOakPathOrThrowNotFound(sessionDelegate, absPath);
                 NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
                 if (nodeDelegate == null) {
                     throw new PathNotFoundException(absPath);
@@ -126,6 +129,11 @@ public class VersionManagerImpl implemen
         });
     }
 
+    private static String getOakPathOrThrowNotFound(SessionDelegate sessionDelegate, String
absPath)
+            throws PathNotFoundException {
+        return SessionContextProvider.getOakPathOrThrowNotFound(sessionDelegate, absPath);
+    }
+
     @Override
     public VersionHistory getVersionHistory(final String absPath)
             throws RepositoryException {
@@ -133,7 +141,7 @@ public class VersionManagerImpl implemen
         return sessionDelegate.perform(new SessionOperation<VersionHistory>() {
             @Override
             public VersionHistory perform() throws RepositoryException {
-                String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+                String oakPath = getOakPathOrThrowNotFound(sessionDelegate, absPath);
                 NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
                 if (nodeDelegate == null) {
                     throw new PathNotFoundException(absPath);
@@ -150,7 +158,7 @@ public class VersionManagerImpl implemen
         return sessionDelegate.perform(new SessionOperation<Version>() {
             @Override
             public Version perform() throws RepositoryException {
-                String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+                String oakPath = getOakPathOrThrowNotFound(sessionDelegate, absPath);
                 NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
                 if (nodeDelegate == null) {
                     throw new PathNotFoundException(absPath);
@@ -187,6 +195,11 @@ public class VersionManagerImpl implemen
         return TODO.unimplemented().returnValue(null);
     }
 
+    @Nonnull
+    private static LockManager getLockManager(SessionDelegate sessionDelegate) {
+        return SessionContextProvider.getLockManager(sessionDelegate);
+    }
+
     @Override
     public void checkout(final String absPath) throws RepositoryException {
         if (true) {
@@ -196,12 +209,12 @@ public class VersionManagerImpl implemen
         sessionDelegate.perform(new SessionOperation<Void>() {
             @Override
             public Void perform() throws RepositoryException {
-                String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+                String oakPath = getOakPathOrThrowNotFound(sessionDelegate, absPath);
                 NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
                 if (nodeDelegate == null) {
                     throw new PathNotFoundException(absPath);
                 }
-                if (sessionDelegate.getLockManager().isLocked(absPath)) {
+                if (getLockManager(sessionDelegate).isLocked(absPath)) {
                     throw new LockException("Node at " + absPath + " is locked");
                 }
                 versionManagerDelegate.checkout(nodeDelegate);
@@ -219,12 +232,12 @@ public class VersionManagerImpl implemen
         return sessionDelegate.perform(new SessionOperation<Version>() {
             @Override
             public Version perform() throws RepositoryException {
-                String oakPath = sessionDelegate.getOakPathOrThrowNotFound(absPath);
+                String oakPath = getOakPathOrThrowNotFound(sessionDelegate, absPath);
                 NodeDelegate nodeDelegate = sessionDelegate.getNode(oakPath);
                 if (nodeDelegate == null) {
                     throw new PathNotFoundException(absPath);
                 }
-                if (sessionDelegate.getLockManager().isLocked(absPath)) {
+                if (getLockManager(sessionDelegate).isLocked(absPath)) {
                     throw new LockException("Node at " + absPath + " is locked");
                 }
                 return new VersionImpl(versionManagerDelegate.checkin(nodeDelegate));

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SessionImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SessionImporter.java?rev=1456022&r1=1456021&r2=1456022&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SessionImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SessionImporter.java
Wed Mar 13 16:23:28 2013
@@ -40,7 +40,9 @@ import javax.jcr.nodetype.PropertyDefini
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.NamespaceHelper;
 import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.jcr.SessionContextProvider;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeTypeProvider;
 import org.apache.jackrabbit.oak.spi.security.authorization.AccessControlConfiguration;
 import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
@@ -107,13 +109,14 @@ public class SessionImporter implements 
         pItemImporters.clear();
 
         //TODO clarify how to provide ProtectedItemImporters
+        NamePathMapper namePathMapper = SessionContextProvider.getNamePathMapper(dlg);
         for (ProtectedItemImporter importer : userConfig.getProtectedItemImporters()) {
-            if (importer.init(session, root, dlg.getNamePathMapper(), false, uuidBehavior,
refTracker)) {
+            if (importer.init(session, root, namePathMapper, false, uuidBehavior, refTracker))
{
                 pItemImporters.add(importer);
             }
         }
         for (ProtectedItemImporter importer : accessControlConfig.getProtectedItemImporters())
{
-            if (importer.init(session, root, dlg.getNamePathMapper(), false, uuidBehavior,
refTracker)) {
+            if (importer.init(session, root, namePathMapper, false, uuidBehavior, refTracker))
{
                 pItemImporters.add(importer);
             }
         }



Mime
View raw message