jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r983708 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ query/ query/lucene/
Date Mon, 09 Aug 2010 16:14:22 GMT
Author: jukka
Date: Mon Aug  9 16:14:22 2010
New Revision: 983708

URL: http://svn.apache.org/viewvc?rev=983708&view=rev
Log:
JCR-890: concurrent read-only access to a session

Use the SessionContext and SessionOperations in search

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiColumnQueryResult.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingleColumnQueryResult.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java Mon Aug  9 16:14:22 2010
@@ -47,6 +47,7 @@ import org.apache.jackrabbit.core.query.
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
 import org.apache.jackrabbit.core.query.QueryHandlerFactory;
 import org.apache.jackrabbit.core.query.QueryObjectModelImpl;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.SharedItemStateManager;
@@ -227,10 +228,7 @@ public class SearchManager implements Sy
     /**
      * Creates a query object that can be executed on the workspace.
      *
-     * @param session   the session of the user executing the query.
-     * @param itemMgr   the item manager of the user executing the query. Needed
-     *                  to return <code>Node</code> instances in the result
-     *                  set.
+     * @param sessionContext component context of the current session
      * @param statement the actual query statement.
      * @param language  the syntax of the query statement.
      * @param node      a nt:query node where the query was read from or
@@ -240,21 +238,19 @@ public class SearchManager implements Sy
      *                               <code>language</code> is unknown.
      * @throws RepositoryException   if any other error occurs.
      */
-    public Query createQuery(SessionImpl session,
-                             ItemManager itemMgr,
-                             String statement,
-                             String language,
-                             Node node)
+    public Query createQuery(
+            SessionContext sessionContext,
+            String statement, String language, Node node)
             throws InvalidQueryException, RepositoryException {
         AbstractQueryImpl query = createQueryInstance();
-        query.init(session, itemMgr, handler, statement, language, node);
+        query.init(sessionContext, handler, statement, language, node);
         return query;
     }
 
     /**
      * Creates a query object model that can be executed on the workspace.
      *
-     * @param session   the session of the user executing the query.
+     * @param sessionContext component context of the current session
      * @param qomTree   the query object model tree, representing the query.
      * @param langugage the original language of the query statement.
      * @param node      a nt:query node where the query was read from or
@@ -265,13 +261,12 @@ public class SearchManager implements Sy
      *                               implementation.
      * @throws RepositoryException   if any other error occurs.
      */
-    public QueryObjectModel createQueryObjectModel(SessionImpl session,
-                                                   QueryObjectModelTree qomTree,
-                                                   String langugage,
-                                                   Node node)
+    public QueryObjectModel createQueryObjectModel(
+            SessionContext sessionContext, QueryObjectModelTree qomTree,
+            String langugage, Node node)
             throws InvalidQueryException, RepositoryException {
         QueryObjectModelImpl qom = new QueryObjectModelImpl();
-        qom.init(session, session.getItemManager(), handler, qomTree, langugage, node);
+        qom.init(sessionContext, handler, qomTree, langugage, node);
         return qom;
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/WorkspaceImpl.java Mon Aug  9 16:14:22 2010
@@ -772,7 +772,7 @@ public class WorkspaceImpl extends Abstr
                 log.debug(msg);
                 throw new RepositoryException(msg, nswe);
             }
-            queryManager = new QueryManagerImpl(session, session.getItemManager(), searchManager);
+            queryManager = new QueryManagerImpl(sessionContext, searchManager);
         }
         return queryManager;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryImpl.java Mon Aug  9 16:14:22 2010
@@ -20,19 +20,17 @@ import javax.jcr.Node;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.Query;
 
-import org.apache.jackrabbit.core.ItemManager;
-import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.session.SessionContext;
 
 /**
- * Defines common initialization methods for all query implementations.
+ * Defines common initialisation methods for all query implementations.
  */
 public abstract class AbstractQueryImpl implements Query {
 
     /**
-     * Initializes a query instance from a query string.
+     * Initialises a query instance from a query string.
      *
-     * @param session   the session of the user executing this query.
-     * @param itemMgr   the item manager of the session executing this query.
+     * @param sessionContext component context of the current session
      * @param handler   the query handler of the search index.
      * @param statement the query statement.
      * @param language  the syntax of the query statement.
@@ -41,10 +39,8 @@ public abstract class AbstractQueryImpl 
      * @throws InvalidQueryException if the query statement is invalid according
      *                               to the specified <code>language</code>.
      */
-    public abstract void init(SessionImpl session,
-                              ItemManager itemMgr,
-                              QueryHandler handler,
-                              String statement,
-                              String language,
-                              Node node) throws InvalidQueryException;
+    public abstract void init(
+            SessionContext sessionContext, QueryHandler handler,
+            String statement, String language, Node node)
+            throws InvalidQueryException;
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java Mon Aug  9 16:14:22 2010
@@ -16,18 +16,17 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import org.apache.jackrabbit.core.ItemManager;
-import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.fs.FileSystem;
-import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.core.state.NodeState;
-import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
+import java.io.IOException;
+import java.util.Iterator;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.query.InvalidQueryException;
 
-import java.io.IOException;
-import java.util.Iterator;
+import org.apache.jackrabbit.core.fs.FileSystem;
+import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.session.SessionContext;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 
 /**
  * Defines an interface for the actual node indexing and query execution.
@@ -102,17 +101,14 @@ public interface QueryHandler {
      * string from among those returned by QueryManager.getSupportedQueryLanguages(); if it is not
      * then an <code>InvalidQueryException</code> is thrown.
      *
-     * @param session the session of the current user creating the query object.
-     * @param itemMgr the item manager of the current user.
+     * @param sessionContext component context of the current session
      * @param statement the query statement.
      * @param language the syntax of the query statement.
      * @throws InvalidQueryException if statement is invalid or language is unsupported.
      * @return A <code>Query</code> object.
      */
-    ExecutableQuery createExecutableQuery(SessionImpl session,
-                                          ItemManager itemMgr,
-                                          String statement,
-                                          String language)
+    ExecutableQuery createExecutableQuery(
+            SessionContext sessionContext, String statement, String language)
             throws InvalidQueryException;
 
     /**
@@ -120,16 +116,13 @@ public interface QueryHandler {
      * object model is considered invalid for the implementing class, an
      * InvalidQueryException is thrown.
      *
-     * @param session the session of the current user creating the query
-     *                object.
-     * @param itemMgr the item manager of the current user.
+     * @param sessionContext component context of the current session
      * @param qomTree query query object model tree.
      * @return A <code>Query</code> object.
      * @throws InvalidQueryException if the query object model tree is invalid.
      */
-    ExecutableQuery createExecutableQuery(SessionImpl session,
-                                          ItemManager itemMgr,
-                                          QueryObjectModelTree qomTree)
+    ExecutableQuery createExecutableQuery(
+            SessionContext sessionContext, QueryObjectModelTree qomTree)
             throws InvalidQueryException;
     
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java Mon Aug  9 16:14:22 2010
@@ -16,13 +16,11 @@
  */
 package org.apache.jackrabbit.core.query;
 
-import org.apache.jackrabbit.core.ItemManager;
-import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.spi.commons.conversion.NameException;
-import org.apache.jackrabbit.spi.Path;
-import org.apache.jackrabbit.spi.Name;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_LANGUAGE;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_STATEMENT;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.NT_QUERY;
+
+import java.text.NumberFormat;
 
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
@@ -35,10 +33,16 @@ import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.QueryResult;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
-
 import javax.jcr.version.VersionException;
-import java.text.NumberFormat;
+
+import org.apache.jackrabbit.core.session.SessionContext;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.conversion.NameException;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Provides the default implementation for a JCR query.
@@ -51,9 +55,9 @@ public class QueryImpl extends AbstractQ
     private static final Logger log = LoggerFactory.getLogger(QueryImpl.class);
 
     /**
-     * The session of the user executing this query
+     * Component context of the current session
      */
-    protected SessionImpl session;
+    protected SessionContext sessionContext;
 
     /**
      * The query statement
@@ -99,19 +103,17 @@ public class QueryImpl extends AbstractQ
     /**
      * @inheritDoc
      */
-    public void init(SessionImpl session,
-                     ItemManager itemMgr,
-                     QueryHandler handler,
-                     String statement,
-                     String language,
-                     Node node) throws InvalidQueryException {
+    public void init(
+            SessionContext sessionContext, QueryHandler handler,
+            String statement, String language, Node node)
+            throws InvalidQueryException {
         checkNotInitialized();
-        this.session = session;
+        this.sessionContext = sessionContext;
         this.statement = statement;
         this.language = language;
         this.handler = handler;
         this.node = node;
-        this.query = handler.createExecutableQuery(session, itemMgr, statement, language);
+        this.query = handler.createExecutableQuery(sessionContext, statement, language);
         setInitialized();
     }
 
@@ -177,18 +179,20 @@ public class QueryImpl extends AbstractQ
             RepositoryException {
 
         checkInitialized();
+        NamePathResolver resolver = sessionContext.getSessionImpl();
         try {
-            Path p = session.getQPath(absPath).getNormalizedPath();
+            Path p = resolver.getQPath(absPath).getNormalizedPath();
             if (!p.isAbsolute()) {
                 throw new RepositoryException(absPath + " is not an absolute path");
             }
 
-            String relPath = session.getJCRPath(p).substring(1);
-            Node queryNode = session.getRootNode().addNode(
-                    relPath, session.getJCRName(NameConstants.NT_QUERY));
+            String relPath = resolver.getJCRPath(p).substring(1);
+            Node queryNode =
+                sessionContext.getSessionImpl().getRootNode().addNode(
+                        relPath, resolver.getJCRName(NT_QUERY));
             // set properties
-            queryNode.setProperty(session.getJCRName(NameConstants.JCR_LANGUAGE), language);
-            queryNode.setProperty(session.getJCRName(NameConstants.JCR_STATEMENT), statement);
+            queryNode.setProperty(resolver.getJCRName(JCR_LANGUAGE), language);
+            queryNode.setProperty(resolver.getJCRName(JCR_STATEMENT), statement);
             node = queryNode;
             return node;
         } catch (NameException e) {
@@ -200,10 +204,11 @@ public class QueryImpl extends AbstractQ
      * {@inheritDoc}
      */
     public String[] getBindVariableNames() throws RepositoryException {
+        NameResolver resolver = sessionContext.getSessionImpl();
         Name[] names = query.getBindVariableNames();
         String[] strNames = new String[names.length];
         for (int i = 0; i < names.length; i++) {
-            strNames[i] = session.getJCRName(names[i]);
+            strNames[i] = resolver.getJCRName(names[i]);
         }
         return strNames;
     }
@@ -222,7 +227,7 @@ public class QueryImpl extends AbstractQ
             throws IllegalArgumentException, RepositoryException {
         checkInitialized();
         try {
-            query.bindValue(session.getQName(varName), value);
+            query.bindValue(sessionContext.getSessionImpl().getQName(varName), value);
         } catch (NameException e) {
             throw new RepositoryException(e.getMessage());
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java Mon Aug  9 16:14:22 2010
@@ -16,6 +16,10 @@
  */
 package org.apache.jackrabbit.core.query;
 
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_LANGUAGE;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.JCR_STATEMENT;
+import static org.apache.jackrabbit.spi.commons.name.NameConstants.NT_QUERY;
+
 import java.util.Arrays;
 import java.util.List;
 import java.util.ArrayList;
@@ -29,13 +33,13 @@ import javax.jcr.query.QueryManager;
 import javax.jcr.query.qom.QueryObjectModel;
 import javax.jcr.query.qom.QueryObjectModelFactory;
 
-import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SearchManager;
-import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.id.NodeId;
+import org.apache.jackrabbit.core.session.SessionContext;
+import org.apache.jackrabbit.core.session.SessionOperation;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelFactoryImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 
 /**
  * This class implements the {@link QueryManager} interface.
@@ -43,14 +47,9 @@ import org.apache.jackrabbit.spi.commons
 public class QueryManagerImpl implements QueryManager {
 
     /**
-     * The <code>Session</code> for this QueryManager.
-     */
-    private final SessionImpl session;
-
-    /**
-     * The <code>ItemManager</code> of for item retrieval in search results
+     * Component context of the current session.
      */
-    private final ItemManager itemMgr;
+    private final SessionContext sessionContext;
 
     /**
      * The <code>SearchManager</code> holding the search index.
@@ -66,24 +65,22 @@ public class QueryManagerImpl implements
      * Creates a new <code>QueryManagerImpl</code> for the passed
      * <code>session</code>
      *
-     * @param session   the session for this query manager.
-     * @param itemMgr   the item manager of the session.
+     * @param sessionContext component context of the current session
      * @param searchMgr the search manager of this workspace.
      * @throws RepositoryException if an error occurs while initializing the
      *                             query manager.
      */
-    public QueryManagerImpl(final SessionImpl session,
-                            final ItemManager itemMgr,
-                            final SearchManager searchMgr)
+    public QueryManagerImpl(
+            final SessionContext sessionContext, final SearchManager searchMgr)
             throws RepositoryException {
-        this.session = session;
-        this.itemMgr = itemMgr;
+        this.sessionContext = sessionContext;
         this.searchMgr = searchMgr;
-        this.qomFactory = new QueryObjectModelFactoryImpl(session) {
+        this.qomFactory = new QueryObjectModelFactoryImpl(
+                sessionContext.getSessionImpl()) {
             protected QueryObjectModel createQuery(QueryObjectModelTree qomTree)
                     throws InvalidQueryException, RepositoryException {
                 return searchMgr.createQueryObjectModel(
-                        session, qomTree, Query.JCR_JQOM, null);
+                        sessionContext, qomTree, Query.JCR_JQOM, null);
             }
         };
     }
@@ -91,27 +88,38 @@ public class QueryManagerImpl implements
     /**
      * {@inheritDoc}
      */
-    public Query createQuery(String statement, String language)
-            throws InvalidQueryException, RepositoryException {
-        sanityCheck();
-        QueryFactory qf = new QueryFactoryImpl(language);
-        return qf.createQuery(statement, language);
+    public Query createQuery(final String statement, final String language)
+            throws RepositoryException {
+        return perform(new SessionOperation<Query>() {
+            public Query perform(SessionContext context)
+                    throws RepositoryException {
+                QueryFactory qf = new QueryFactoryImpl(language);
+                return qf.createQuery(statement, language);
+            }
+        });
     }
 
     /**
      * {@inheritDoc}
      */
-    public Query getQuery(Node node)
-            throws InvalidQueryException, RepositoryException {
-        sanityCheck();
-        if (!node.isNodeType(session.getJCRName(NameConstants.NT_QUERY))) {
-            throw new InvalidQueryException("node is not of type nt:query");
-        }
-        String statement = node.getProperty(session.getJCRName(NameConstants.JCR_STATEMENT)).getString();
-        String language = node.getProperty(session.getJCRName(NameConstants.JCR_LANGUAGE)).getString();
+    public Query getQuery(final Node node) throws RepositoryException {
+        return perform(new SessionOperation<Query>() {
+            public Query perform(SessionContext context)
+                    throws RepositoryException {
+                NamePathResolver resolver = context.getSessionImpl();
+                if (!node.isNodeType(resolver.getJCRName(NT_QUERY))) {
+                    throw new InvalidQueryException(
+                            "Node is not of type nt:query: " + node);
+                }
+                String statement =
+                    node.getProperty(resolver.getJCRName(JCR_STATEMENT)).getString();
+                String language =
+                    node.getProperty(resolver.getJCRName(JCR_LANGUAGE)).getString();
 
-        QueryFactory qf = new QueryFactoryImpl(node, language);
-        return qf.createQuery(statement, language);
+                QueryFactory qf = new QueryFactoryImpl(node, language);
+                return qf.createQuery(statement, language);
+            }
+        });
     }
 
     /**
@@ -145,19 +153,23 @@ public class QueryManagerImpl implements
      * @return the referring nodes.
      * @throws RepositoryException if an error occurs.
      */
-    public Iterable<Node> getWeaklyReferringNodes(Node node)
+    public Iterable<Node> getWeaklyReferringNodes(final Node node)
             throws RepositoryException {
-        sanityCheck();
-        List<Node> nodes = new ArrayList<Node>();
-        try {
-            NodeId nodeId = new NodeId(node.getIdentifier());
-            for (NodeId id : searchMgr.getWeaklyReferringNodes(nodeId)) {
-                nodes.add(session.getNodeById(id));
+        return perform(new SessionOperation<Iterable<Node>>() {
+            public Iterable<Node> perform(SessionContext context)
+                    throws RepositoryException {
+                List<Node> nodes = new ArrayList<Node>();
+                try {
+                    NodeId nodeId = new NodeId(node.getIdentifier());
+                    for (NodeId id : searchMgr.getWeaklyReferringNodes(nodeId)) {
+                        nodes.add(sessionContext.getSessionImpl().getNodeById(id));
+                    }
+                } catch (IOException e) {
+                    throw new RepositoryException(e);
+                }
+                return nodes;
             }
-        } catch (IOException e) {
-            throw new RepositoryException(e);
-        }
-        return nodes;
+        });
     }
 
     //------------------------< testing only >----------------------------------
@@ -172,16 +184,11 @@ public class QueryManagerImpl implements
     //---------------------------< internal >-----------------------------------
 
     /**
-     * Checks if this <code>QueryManagerImpl</code> instance is still usable,
-     * otherwise throws a {@link javax.jcr.RepositoryException}.
-     *
-     * @throws RepositoryException if this query manager is not usable anymore,
-     *                             e.g. the corresponding session is closed.
+     * Performs the given session operation.
      */
-    private void sanityCheck() throws RepositoryException {
-        if (!session.isLive()) {
-            throw new RepositoryException("corresponding session has been closed");
-        }
+    private <T> T perform(SessionOperation<T> operation)
+            throws RepositoryException {
+        return sessionContext.getSessionState().perform(operation);
     }
 
     private class QueryFactoryImpl extends CompoundQueryFactory {
@@ -192,18 +199,22 @@ public class QueryManagerImpl implements
 
         public QueryFactoryImpl(final Node node, final String language) {
             super(Arrays.asList(
-                new QOMQueryFactory(new QueryObjectModelFactoryImpl(session) {
-                    protected QueryObjectModel createQuery(QueryObjectModelTree qomTree)
-                            throws InvalidQueryException, RepositoryException {
+                new QOMQueryFactory(new QueryObjectModelFactoryImpl(
+                        sessionContext.getSessionImpl()) {
+                    @Override
+                    protected QueryObjectModel createQuery(
+                            QueryObjectModelTree qomTree)
+                            throws RepositoryException {
                         return searchMgr.createQueryObjectModel(
-                                session, qomTree, language, node);
+                                sessionContext, qomTree, language, node);
                     }
-                }, session.getValueFactory()),
+                },
+                sessionContext.getSessionImpl().getValueFactory()),
                 new AQTQueryFactory() {
-                    public Query createQuery(String statement,
-                                             String language)
-                            throws InvalidQueryException, RepositoryException {
-                        return searchMgr.createQuery(session, itemMgr, statement, language, node);
+                    public Query createQuery(String statement, String language)
+                            throws RepositoryException {
+                        return searchMgr.createQuery(
+                                sessionContext, statement, language, node);
                     }
                 }));
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java Mon Aug  9 16:14:22 2010
@@ -26,8 +26,7 @@ import javax.jcr.query.qom.QueryObjectMo
 import javax.jcr.query.qom.Source;
 
 import org.apache.jackrabbit.commons.query.QueryObjectModelBuilderRegistry;
-import org.apache.jackrabbit.core.ItemManager;
-import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 
 /**
@@ -44,20 +43,18 @@ public class QueryObjectModelImpl extend
      * {@inheritDoc}
      * @throws UnsupportedOperationException always.
      */
-    public void init(SessionImpl session,
-                     ItemManager itemMgr,
-                     QueryHandler handler,
-                     String statement,
-                     String language,
-                     Node node) throws InvalidQueryException {
+    @Override
+    public void init(
+            SessionContext sessionContext, QueryHandler handler,
+            String statement, String language, Node node)
+            throws InvalidQueryException {
         throw new UnsupportedOperationException();
     }
 
     /**
      * Initializes a query instance from a query object model.
      *
-     * @param session  the session of the user executing this query.
-     * @param itemMgr  the item manager of the session executing this query.
+     * @param sessionContext component context of the current session
      * @param handler  the query handler of the search index.
      * @param qomTree  the query object model tree.
      * @param language the original query syntax from where the JQOM was
@@ -68,21 +65,18 @@ public class QueryObjectModelImpl extend
      *                               according to the given language.
      * @throws RepositoryException   if another error occurs
      */
-    public void init(SessionImpl session,
-                     ItemManager itemMgr,
-                     QueryHandler handler,
-                     QueryObjectModelTree qomTree,
-                     String language,
-                     Node node)
+    public void init(
+            SessionContext sessionContext, QueryHandler handler,
+            QueryObjectModelTree qomTree, String language, Node node)
             throws InvalidQueryException, RepositoryException {
         checkNotInitialized();
-        this.session = session;
+        this.sessionContext = sessionContext;
         this.language = language;
         this.handler = handler;
         this.qomTree = qomTree;
         this.node = node;
         this.statement = QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(language).toString(this);
-        this.query = handler.createExecutableQuery(session, itemMgr, qomTree);
+        this.query = handler.createExecutableQuery(sessionContext, qomTree);
         setInitialized();
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java Mon Aug  9 16:14:22 2010
@@ -18,12 +18,12 @@ package org.apache.jackrabbit.core.query
 
 import org.apache.jackrabbit.core.query.ExecutableQuery;
 import org.apache.jackrabbit.core.query.PropertyTypeRegistry;
-import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.ItemManager;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.Name;
 
 import javax.jcr.Value;
 import javax.jcr.RepositoryException;
+import javax.jcr.Workspace;
 import javax.jcr.query.qom.QueryObjectModelFactory;
 
 import java.util.Set;
@@ -39,14 +39,9 @@ import java.util.Collections;
 public abstract class AbstractQueryImpl implements ExecutableQuery {
 
     /**
-     * The session of the user executing this query
+     * Component context of the current session
      */
-    protected final SessionImpl session;
-
-    /**
-     * The item manager of the user executing this query
-     */
-    protected final ItemManager itemMgr;
+    protected final SessionContext sessionContext;
 
     /**
      * The actual search index
@@ -78,17 +73,14 @@ public abstract class AbstractQueryImpl 
     /**
      * Creates a new query instance from a query string.
      *
-     * @param session the session of the user executing this query.
-     * @param itemMgr the item manager of the session executing this query.
+     * @param sessionContext component context of the current session
      * @param index   the search index.
      * @param propReg the property type registry.
      */
-    public AbstractQueryImpl(SessionImpl session,
-                             ItemManager itemMgr,
-                             SearchIndex index,
-                             PropertyTypeRegistry propReg) {
-        this.session = session;
-        this.itemMgr = itemMgr;
+    public AbstractQueryImpl(
+            SessionContext sessionContext, SearchIndex index,
+            PropertyTypeRegistry propReg) {
+        this.sessionContext = sessionContext;
         this.index = index;
         this.propReg = propReg;
     }
@@ -169,7 +161,8 @@ public abstract class AbstractQueryImpl 
      */
     protected QueryObjectModelFactory getQOMFactory()
             throws RepositoryException {
-        return session.getWorkspace().getQueryManager().getQOMFactory();
+        Workspace workspace = sessionContext.getSessionImpl().getWorkspace();
+        return workspace.getQueryManager().getQOMFactory();
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiColumnQueryResult.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiColumnQueryResult.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiColumnQueryResult.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/MultiColumnQueryResult.java Mon Aug  9 16:14:22 2010
@@ -20,9 +20,7 @@ import java.io.IOException;
 
 import javax.jcr.RepositoryException;
 
-import org.apache.jackrabbit.core.ItemManager;
-import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.security.AccessManager;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
 
@@ -42,19 +40,13 @@ public class MultiColumnQueryResult exte
      */
     protected final Ordering[] orderings;
 
-    public MultiColumnQueryResult(SearchIndex index,
-                                  ItemManager itemMgr,
-                                  SessionImpl session,
-                                  AccessManager accessMgr,
-                                  AbstractQueryImpl queryImpl,
-                                  MultiColumnQuery query,
-                                  SpellSuggestion spellSuggestion,
-                                  ColumnImpl[] columns,
-                                  OrderingImpl[] orderings,
-                                  boolean documentOrder,
-                                  long offset,
-                                  long limit) throws RepositoryException {
-        super(index, itemMgr, session, accessMgr, queryImpl, spellSuggestion,
+    public MultiColumnQueryResult(
+            SearchIndex index, SessionContext sessionContext,
+            AbstractQueryImpl queryImpl, MultiColumnQuery query,
+            SpellSuggestion spellSuggestion,  ColumnImpl[] columns,
+            OrderingImpl[] orderings, boolean documentOrder,
+            long offset, long limit) throws RepositoryException {
+        super(index, sessionContext, queryImpl, spellSuggestion,
                 columns, documentOrder, offset, limit);
         this.query = query;
         this.orderings = index.createOrderings(orderings);
@@ -67,7 +59,9 @@ public class MultiColumnQueryResult exte
      */
     protected MultiColumnQueryHits executeQuery(long resultFetchHint)
             throws IOException {
-        return index.executeQuery(session, query, orderings, resultFetchHint);
+        return index.executeQuery(
+                sessionContext.getSessionImpl(),
+                query, orderings, resultFetchHint);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java Mon Aug  9 16:14:22 2010
@@ -16,8 +16,8 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.util.Map;
 import java.util.LinkedHashMap;
+import java.util.Map;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.PropertyDefinition;
@@ -25,15 +25,16 @@ import javax.jcr.query.InvalidQueryExcep
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.qom.QueryObjectModelFactory;
 
-import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
 import org.apache.jackrabbit.core.query.PropertyTypeRegistry;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.query.AndQueryNode;
 import org.apache.jackrabbit.spi.commons.query.DefaultQueryNodeVisitor;
 import org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode;
@@ -43,7 +44,6 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.query.QueryParser;
 import org.apache.jackrabbit.spi.commons.query.QueryRootNode;
 import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
-import org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl;
 import org.apache.lucene.search.Query;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -72,8 +72,7 @@ public class QueryImpl extends AbstractQ
     /**
      * Creates a new query instance from a query string.
      *
-     * @param session   the session of the user executing this query.
-     * @param itemMgr   the item manager of the session executing this query.
+     * @param sessionContext component context of the current session
      * @param index     the search index.
      * @param propReg   the property type registry.
      * @param statement the query statement.
@@ -82,17 +81,15 @@ public class QueryImpl extends AbstractQ
      * @throws InvalidQueryException if the query statement is invalid according
      *                               to the specified <code>language</code>.
      */
-    public QueryImpl(SessionImpl session,
-                     ItemManager itemMgr,
-                     SearchIndex index,
-                     PropertyTypeRegistry propReg,
-                     String statement,
-                     String language,
-                     QueryNodeFactory factory) throws InvalidQueryException {
-        super(session, itemMgr, index, propReg);
+    public QueryImpl(
+            SessionContext sessionContext, SearchIndex index,
+            PropertyTypeRegistry propReg, String statement, String language,
+            QueryNodeFactory factory) throws InvalidQueryException {
+        super(sessionContext, index, propReg);
         // parse query according to language
         // build query tree using the passed factory
-        this.root = QueryParser.parse(statement, language, session, factory);
+        this.root = QueryParser.parse(
+                statement, language, sessionContext.getSessionImpl(), factory);
     }
 
     /**
@@ -109,7 +106,8 @@ public class QueryImpl extends AbstractQ
         }
 
         // build lucene query
-        Query query = LuceneQueryBuilder.createQuery(root, session,
+        Query query = LuceneQueryBuilder.createQuery(
+                root, sessionContext.getSessionImpl(),
                 index.getContext().getItemStateManager(),
                 index.getNamespaceMappings(), index.getTextAnalyzer(),
                 propReg, index.getSynonymProvider(),
@@ -130,9 +128,9 @@ public class QueryImpl extends AbstractQ
             ascSpecs[i] = orderSpecs[i].isAscending();
         }
 
-        return new SingleColumnQueryResult(index, itemMgr,
-                session, session.getAccessManager(),
-                this, query, new SpellSuggestion(index.getSpellChecker(), root),
+        return new SingleColumnQueryResult(
+                index, sessionContext, this, query,
+                new SpellSuggestion(index.getSpellChecker(), root),
                 getColumns(), orderProperties, ascSpecs,
                 orderProperties.length == 0 && getRespectDocumentOrder(),
                 offset, limit);
@@ -145,6 +143,7 @@ public class QueryImpl extends AbstractQ
      * @throws RepositoryException if an error occurs.
      */
     protected ColumnImpl[] getColumns() throws RepositoryException {
+        SessionImpl session = sessionContext.getSessionImpl();
         QueryObjectModelFactory qomFactory = session.getWorkspace().getQueryManager().getQOMFactory();
         // get columns
         Map<Name, ColumnImpl> columns = new LinkedHashMap<Name, ColumnImpl>();
@@ -213,7 +212,9 @@ public class QueryImpl extends AbstractQ
      * @throws RepositoryException if an error occurs while creating the column.
      */
     protected ColumnImpl columnForName(Name propertyName) throws RepositoryException {
-        QueryObjectModelFactory qomFactory = session.getWorkspace().getQueryManager().getQOMFactory();
+        SessionImpl session = sessionContext.getSessionImpl();
+        QueryObjectModelFactory qomFactory =
+            session.getWorkspace().getQueryManager().getQOMFactory();
         String name = session.getJCRName(propertyName);
         return (ColumnImpl) qomFactory.column(
                 session.getJCRName(DEFAULT_SELECTOR_NAME), name, name);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java Mon Aug  9 16:14:22 2010
@@ -16,29 +16,29 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.PropertyDefinition;
-import javax.jcr.query.QueryResult;
 import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.QueryResult;
 import javax.jcr.query.qom.QueryObjectModelFactory;
 
-import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
+import org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl;
 import org.apache.jackrabbit.core.query.PropertyTypeRegistry;
 import org.apache.jackrabbit.core.query.lucene.constraint.Constraint;
 import org.apache.jackrabbit.core.query.lucene.constraint.ConstraintBuilder;
+import org.apache.jackrabbit.core.session.SessionContext;
+import org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor;
+import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 import org.apache.jackrabbit.spi.commons.query.qom.SelectorImpl;
-import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
-import org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl;
 
 /**
  * <code>QueryObjectModelImpl</code>...
@@ -53,20 +53,17 @@ public class QueryObjectModelImpl extend
     /**
      * Creates a new query instance from a query string.
      *
-     * @param session the session of the user executing this query.
-     * @param itemMgr the item manager of the session executing this query.
+     * @param sessionContext component context of the current session
      * @param index   the search index.
      * @param propReg the property type registry.
      * @param qomTree the query object model tree.
      * @throws InvalidQueryException if the QOM tree is invalid.
      */
-    public QueryObjectModelImpl(SessionImpl session,
-                                ItemManager itemMgr,
-                                SearchIndex index,
-                                PropertyTypeRegistry propReg,
-                                QueryObjectModelTree qomTree)
+    public QueryObjectModelImpl(
+            SessionContext sessionContext, SearchIndex index,
+            PropertyTypeRegistry propReg, QueryObjectModelTree qomTree)
             throws InvalidQueryException {
-        super(session, itemMgr, index, propReg);
+        super(sessionContext, index, propReg);
         this.qomTree = qomTree;
         checkNodeTypes();
         extractBindVariableNames();
@@ -96,9 +93,9 @@ public class QueryObjectModelImpl extend
      */
     public QueryResult execute(long offset, long limit)
             throws RepositoryException {
-
-        LuceneQueryFactory factory = new LuceneQueryFactoryImpl(session,
-                index.getSortComparatorSource(),
+        SessionImpl session = sessionContext.getSessionImpl();
+        LuceneQueryFactory factory = new LuceneQueryFactoryImpl(
+                session, index.getSortComparatorSource(),
                 index.getContext().getHierarchyManager(),
                 index.getNamespaceMappings(), index.getTextAnalyzer(),
                 index.getSynonymProvider(), index.getIndexFormatVersion(),
@@ -135,8 +132,8 @@ public class QueryObjectModelImpl extend
             }
         }
         OrderingImpl[] orderings = qomTree.getOrderings();
-        return new MultiColumnQueryResult(index, itemMgr,
-                session, session.getAccessManager(),
+        return new MultiColumnQueryResult(
+                index, sessionContext,
                 // TODO: spell suggestion missing
                 this, query, null, columns.toArray(new ColumnImpl[columns.size()]),
                 orderings, orderings.length == 0 && getRespectDocumentOrder(),
@@ -170,10 +167,12 @@ public class QueryObjectModelImpl extend
      */
     private void checkNodeTypes() throws InvalidQueryException {
         try {
+            final NodeTypeManagerImpl manager =
+                sessionContext.getSessionImpl().getNodeTypeManager();
             qomTree.accept(new DefaultTraversingQOMTreeVisitor() {
                 public Object visit(SelectorImpl node, Object data) throws Exception {
                     String ntName = node.getNodeTypeName();
-                    if (!session.getNodeTypeManager().hasNodeType(ntName)) {
+                    if (!manager.hasNodeType(ntName)) {
                         throw new Exception(ntName + " is not a known node type");
                     }
                     return super.visit(node, data);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java Mon Aug  9 16:14:22 2010
@@ -29,10 +29,9 @@ import javax.jcr.RepositoryException;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.RowIterator;
 
-import org.apache.jackrabbit.core.ItemManager;
-import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.security.AccessManager;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -53,19 +52,9 @@ public abstract class QueryResultImpl im
     protected final SearchIndex index;
 
     /**
-     * The item manager of the session executing the query
+     * Component context of the current session
      */
-    protected final ItemManager itemMgr;
-
-    /**
-     * The session executing the query
-     */
-    protected final SessionImpl session;
-
-    /**
-     * The access manager of the session that executes the query.
-     */
-    protected final AccessManager accessMgr;
+    protected final SessionContext sessionContext;
 
     /**
      * The query instance which created this query result.
@@ -134,11 +123,7 @@ public abstract class QueryResultImpl im
      * calling {@link #getResults(long)} after this constructor had been called.
      *
      * @param index           the search index where the query is executed.
-     * @param itemMgr         the item manager of the session executing the
-     *                        query.
-     * @param session         the session executing the query.
-     * @param accessMgr       the access manager of the session executiong the
-     *                        query.
+     * @param sessionContext component context of the current session
      * @param queryImpl       the query instance which created this query
      *                        result.
      * @param spellSuggestion the spell suggestion or <code>null</code> if none
@@ -153,20 +138,13 @@ public abstract class QueryResultImpl im
      * @throws IllegalArgumentException if any of the columns does not have a
      *                                  column name.
      */
-    public QueryResultImpl(SearchIndex index,
-                           ItemManager itemMgr,
-                           SessionImpl session,
-                           AccessManager accessMgr,
-                           AbstractQueryImpl queryImpl,
-                           SpellSuggestion spellSuggestion,
-                           ColumnImpl[] columns,
-                           boolean documentOrder,
-                           long offset,
-                           long limit) throws RepositoryException {
+    public QueryResultImpl(
+            SearchIndex index, SessionContext sessionContext,
+            AbstractQueryImpl queryImpl, SpellSuggestion spellSuggestion,
+            ColumnImpl[] columns, boolean documentOrder,
+            long offset, long limit) throws RepositoryException {
         this.index = index;
-        this.itemMgr = itemMgr;
-        this.session = session;
-        this.accessMgr = accessMgr;
+        this.sessionContext = sessionContext;
         this.queryImpl = queryImpl;
         this.spellSuggestion = spellSuggestion;
         this.docOrder = documentOrder;
@@ -186,9 +164,10 @@ public abstract class QueryResultImpl im
      * {@inheritDoc}
      */
     public String[] getSelectorNames() throws RepositoryException {
+        NameResolver resolver = sessionContext.getSessionImpl();
         String[] names = new String[selectorNames.length];
         for (int i = 0; i < selectorNames.length; i++) {
-            names[i] = session.getJCRName(selectorNames[i]);
+            names[i] = resolver.getJCRName(selectorNames[i]);
         }
         return names;
     }
@@ -204,7 +183,8 @@ public abstract class QueryResultImpl im
      * {@inheritDoc}
      */
     public NodeIterator getNodes() throws RepositoryException {
-        return new NodeIteratorImpl(itemMgr, getScoreNodes(), 0);
+        return new NodeIteratorImpl(
+                sessionContext.getItemManager(), getScoreNodes(), 0);
     }
 
     /**
@@ -218,9 +198,12 @@ public abstract class QueryResultImpl im
                 throw new RepositoryException(e);
             }
         }
-        return new RowIteratorImpl(getScoreNodes(), columns,
-                selectorNames, itemMgr,
-                index.getContext().getHierarchyManager(), session, session.getValueFactory(),
+        return new RowIteratorImpl(
+                getScoreNodes(), columns,
+                selectorNames, sessionContext.getItemManager(),
+                index.getContext().getHierarchyManager(),
+                sessionContext.getSessionImpl(), 
+                sessionContext.getSessionImpl().getValueFactory(),
                 excerptProvider, spellSuggestion);
     }
 
@@ -253,7 +236,8 @@ public abstract class QueryResultImpl im
      */
     private ScoreNodeIterator getScoreNodes() {
         if (docOrder) {
-            return new DocOrderScoreNodeIterator(itemMgr, resultNodes, 0);
+            return new DocOrderScoreNodeIterator(
+                    sessionContext.getItemManager(), resultNodes, 0);
         } else {
             return new LazyScoreNodeIteratorImpl();
         }
@@ -371,7 +355,8 @@ public abstract class QueryResultImpl im
             throws RepositoryException {
         for (ScoreNode node : nodes) {
             try {
-                if (node != null && !accessMgr.canRead(null, node.getNodeId())) {
+                if (node != null && !sessionContext.getAccessManager().canRead(
+                        null, node.getNodeId())) {
                     return false;
                 }
             } catch (ItemNotFoundException e) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java Mon Aug  9 16:14:22 2010
@@ -52,6 +52,7 @@ import org.apache.jackrabbit.core.query.
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
 import org.apache.jackrabbit.core.query.lucene.directory.DirectoryManager;
 import org.apache.jackrabbit.core.query.lucene.directory.FSDirectoryManager;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NodeState;
@@ -59,6 +60,7 @@ import org.apache.jackrabbit.core.state.
 import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.name.PathFactoryImpl;
 import org.apache.jackrabbit.spi.commons.query.DefaultQueryNodeFactory;
@@ -664,20 +666,18 @@ public class SearchIndex extends Abstrac
      * string from among those returned by QueryManager.getSupportedQueryLanguages(); if it is not
      * then an <code>InvalidQueryException</code> is thrown.
      *
-     * @param session the session of the current user creating the query object.
-     * @param itemMgr the item manager of the current user.
+     * @param sessionContext component context of the current session
      * @param statement the query statement.
      * @param language the syntax of the query statement.
      * @throws InvalidQueryException if statement is invalid or language is unsupported.
      * @return A <code>Query</code> object.
      */
-    public ExecutableQuery createExecutableQuery(SessionImpl session,
-                                             ItemManager itemMgr,
-                                             String statement,
-                                             String language)
+    public ExecutableQuery createExecutableQuery(
+            SessionContext sessionContext, String statement, String language)
             throws InvalidQueryException {
-        QueryImpl query = new QueryImpl(session, itemMgr, this,
-                getContext().getPropertyTypeRegistry(), statement, language, getQueryNodeFactory());
+        QueryImpl query = new QueryImpl(
+                sessionContext, this, getContext().getPropertyTypeRegistry(),
+                statement, language, getQueryNodeFactory());
         query.setRespectDocumentOrder(documentOrder);
         return query;
     }
@@ -687,9 +687,7 @@ public class SearchIndex extends Abstrac
      * object model is considered invalid for the implementing class, an
      * InvalidQueryException is thrown.
      *
-     * @param session the session of the current user creating the query
-     *                object.
-     * @param itemMgr the item manager of the current user.
+     * @param sessionContext component context of the current session
      * @param qomTree query query object model tree.
      * @return A <code>Query</code> object.
      * @throws javax.jcr.query.InvalidQueryException
@@ -697,11 +695,11 @@ public class SearchIndex extends Abstrac
      * @see QueryHandler#createExecutableQuery(SessionImpl, ItemManager, QueryObjectModelTree)
      */
     public ExecutableQuery createExecutableQuery(
-            SessionImpl session,
-            ItemManager itemMgr,
-            QueryObjectModelTree qomTree) throws InvalidQueryException {
-        QueryObjectModelImpl query = new QueryObjectModelImpl(session, itemMgr, this,
-                getContext().getPropertyTypeRegistry(), qomTree);
+            SessionContext sessionContext, QueryObjectModelTree qomTree)
+            throws InvalidQueryException {
+        QueryObjectModelImpl query = new QueryObjectModelImpl(
+                sessionContext, this, getContext().getPropertyTypeRegistry(),
+                qomTree);
         query.setRespectDocumentOrder(documentOrder);
         return query;
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingleColumnQueryResult.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingleColumnQueryResult.java?rev=983708&r1=983707&r2=983708&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingleColumnQueryResult.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SingleColumnQueryResult.java Mon Aug  9 16:14:22 2010
@@ -20,11 +20,9 @@ import java.io.IOException;
 
 import javax.jcr.RepositoryException;
 
-import org.apache.jackrabbit.core.ItemManager;
-import org.apache.jackrabbit.core.SessionImpl;
-import org.apache.jackrabbit.core.security.AccessManager;
-import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
+import org.apache.jackrabbit.core.session.SessionContext;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
 import org.apache.lucene.search.Query;
 
 /**
@@ -48,20 +46,13 @@ public class SingleColumnQueryResult ext
      */
     protected final boolean[] orderSpecs;
 
-    public SingleColumnQueryResult(SearchIndex index,
-                                   ItemManager itemMgr,
-                                   SessionImpl session,
-                                   AccessManager accessMgr,
-                                   AbstractQueryImpl queryImpl,
-                                   Query query,
-                                   SpellSuggestion spellSuggestion,
-                                   ColumnImpl[] columns,
-                                   Path[] orderProps,
-                                   boolean[] orderSpecs,
-                                   boolean documentOrder,
-                                   long offset,
-                                   long limit) throws RepositoryException {
-        super(index, itemMgr, session, accessMgr, queryImpl, spellSuggestion,
+    public SingleColumnQueryResult(
+            SearchIndex index, SessionContext sessionContext,
+            AbstractQueryImpl queryImpl, Query query,
+            SpellSuggestion spellSuggestion, ColumnImpl[] columns,
+            Path[] orderProps, boolean[] orderSpecs, boolean documentOrder,
+            long offset, long limit) throws RepositoryException {
+        super(index, sessionContext, queryImpl, spellSuggestion,
                 columns, documentOrder, offset, limit);
         this.query = query;
         this.orderProps = orderProps;
@@ -75,7 +66,8 @@ public class SingleColumnQueryResult ext
      */
     protected MultiColumnQueryHits executeQuery(long resultFetchHint)
             throws IOException {
-        return index.executeQuery(session, queryImpl, query,
+        return index.executeQuery(
+                sessionContext.getSessionImpl(), queryImpl, query,
                 orderProps, orderSpecs, resultFetchHint);
     }
 



Mime
View raw message