jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1421163 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/api/ main/java/org/apache/jackrabbit/oak/core/ main/java/org/apache/jackrabbit/oak/plugins/version/ main/java/org/apache/jackrabbit/oak/query/ main/java/o...
Date Thu, 13 Dec 2012 09:24:30 GMT
Author: thomasm
Date: Thu Dec 13 09:24:28 2012
New Revision: 1421163

URL: http://svn.apache.org/viewvc?rev=1421163&view=rev
Log:
OAK-355 Move QueryEngine reference from ContentSession to Root

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
      - copied, changed from r1420120, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/SimpleRoot.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
(from r1420120, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java&r1=1420120&r2=1421163&rev=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionQueryEngine.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
Thu Dec 13 09:24:28 2012
@@ -27,7 +27,7 @@ import org.apache.jackrabbit.oak.namepat
  * <p>
  * What query languages are supported depends on the registered query parsers.
  */
-public interface SessionQueryEngine {
+public interface QueryEngine {
 
     /**
      * Get the list of supported query languages.
@@ -63,7 +63,4 @@ public interface SessionQueryEngine {
             long limit, long offset, Map<String, ? extends PropertyValue> bindings,
             NamePathMapper namePathMapper) throws ParseException;
 
-    // TODO pass namespace mapping
-    // TODO pass node type information (select * from [xyz] is supposed to return at least
the mandatory columns for xyz)
-
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java?rev=1421163&r1=1421162&r2=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Root.java Thu
Dec 13 09:24:28 2012
@@ -130,7 +130,7 @@ public interface Root {
      * @return the query engine
      */
     @Nonnull
-    SessionQueryEngine getQueryEngine();
+    QueryEngine getQueryEngine();
 
     /**
      * Returns the blob factory (TODO: review if that really belongs to the OAK-API. see
also todos on BlobFactory)

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1421163&r1=1421162&r2=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Thu Dec 13 09:24:28 2012
@@ -31,11 +31,11 @@ import org.apache.jackrabbit.oak.api.Blo
 import org.apache.jackrabbit.oak.api.BlobFactory;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.api.SessionQueryEngine;
+import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.commit.DefaultConflictHandler;
-import org.apache.jackrabbit.oak.query.SessionQueryEngineImpl;
+import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
 import org.apache.jackrabbit.oak.spi.observation.ChangeExtractor;
 import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
@@ -288,18 +288,20 @@ public class RootImpl implements Root {
     }
 
     @Override
-    public SessionQueryEngine getQueryEngine() {
+    public QueryEngine getQueryEngine() {
         checkLive();
-        return new SessionQueryEngineImpl(indexProvider) {
+        return new QueryEngineImpl(indexProvider) {
+
             @Override
-            protected NodeState getRootNodeState() {
+            protected NodeState getRootState() {
                 return rootTree.getNodeState();
             }
-
+            
             @Override
-            protected Root getRoot() {
+            protected Root getRootTree() {
                 return RootImpl.this;
             }
+
         };
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/SimpleRoot.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/SimpleRoot.java?rev=1421163&r1=1421162&r2=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/SimpleRoot.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/SimpleRoot.java
Thu Dec 13 09:24:28 2012
@@ -22,8 +22,8 @@ import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.BlobFactory;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.api.SessionQueryEngine;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 
@@ -87,7 +87,7 @@ class SimpleRoot implements Root {
 
     @Nonnull
     @Override
-    public SessionQueryEngine getQueryEngine() {
+    public QueryEngine getQueryEngine() {
         throw new UnsupportedOperationException();
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java?rev=1421163&r1=1421162&r2=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
Thu Dec 13 09:24:28 2012
@@ -93,6 +93,7 @@ public class Query {
     private long size = -1;
     private boolean prepared;
     private Root rootTree;
+    private NodeState rootState;
     private NamePathMapper namePathMapper;
 
     Query(String statement, SourceImpl source, ConstraintImpl constraint, OrderingImpl[]
orderings,
@@ -299,11 +300,11 @@ public class Query {
         this.measure = measure;
     }
 
-    public ResultImpl executeQuery(NodeState rootState) {
-        return new ResultImpl(this, rootState);
+    public ResultImpl executeQuery() {
+        return new ResultImpl(this);
     }
 
-    Iterator<ResultRowImpl> getRows(NodeState rootState) {
+    Iterator<ResultRowImpl> getRows() {
         prepare();
         Iterator<ResultRowImpl> it;
         if (explain) {
@@ -589,12 +590,16 @@ public class Query {
     }
 
     public QueryIndex getBestIndex(Filter filter) {
-        return queryEngine.getBestIndex(this, filter);
+        return queryEngine.getBestIndex(this, rootState, filter);
     }
 
     public void setRootTree(Root rootTree) {
         this.rootTree = rootTree;
     }
+    
+    public void setRootState(NodeState rootState) {
+        this.rootState = rootState;
+    }
 
     public void setNamePathMapper(NamePathMapper namePathMapper) {
         this.namePathMapper = namePathMapper;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java?rev=1421163&r1=1421162&r2=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
Thu Dec 13 09:24:28 2012
@@ -23,6 +23,8 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.jackrabbit.oak.api.PropertyValue;
+import org.apache.jackrabbit.oak.api.QueryEngine;
+import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.query.index.TraversingIndex;
@@ -36,7 +38,7 @@ import org.slf4j.LoggerFactory;
 /**
  * The query engine implementation.
  */
-public class QueryEngineImpl {
+public abstract class QueryEngineImpl implements QueryEngine {
 
     static final String SQL2 = "JCR-SQL2";
     static final String SQL = "sql";
@@ -47,14 +49,27 @@ public class QueryEngineImpl {
 
     private static final Logger LOG = LoggerFactory.getLogger(QueryEngineImpl.class);
 
-    private final NodeState rootState;
     private final QueryIndexProvider indexProvider;
 
-    public QueryEngineImpl(NodeState rootState, QueryIndexProvider indexProvider) {
-        this.rootState = rootState;
+    public QueryEngineImpl(QueryIndexProvider indexProvider) {
         this.indexProvider = indexProvider;
     }
+    
+    /**
+     * Get the current root node state, to run the query against.
+     * 
+     * @return the node state
+     */
+    protected abstract NodeState getRootState();
+    
+    /**
+     * Get the current root tree, to run the query against.
+     * 
+     * @return the node state
+     */
+    protected abstract Root getRootTree();
 
+    @Override
     public List<String> getSupportedQueryLanguages() {
         return Arrays.asList(SQL2, SQL, XPATH, JQOM,
                 SQL2 + NO_LITERALS, SQL + NO_LITERALS, XPATH + NO_LITERALS);
@@ -68,12 +83,13 @@ public class QueryEngineImpl {
      * @return the list of bind variable names
      * @throws ParseException
      */
+    @Override
     public List<String> getBindVariableNames(String statement, String language) throws
ParseException {
         Query q = parseQuery(statement, language);
         return q.getBindVariableNames();
     }
 
-    private Query parseQuery(String statement, String language) throws ParseException {
+    private static Query parseQuery(String statement, String language) throws ParseException
{
         Query q;
         if (LOG.isDebugEnabled()) {
             LOG.debug(language + ": " + statement);
@@ -105,13 +121,14 @@ public class QueryEngineImpl {
         }
         return q;
     }
-
-    public ResultImpl executeQuery(String statement, String language, 
-            long limit, long offset, Map<String, ? extends PropertyValue> bindings,
-            Root rootTree,
+    
+    @Override
+    public Result executeQuery(String statement, String language, long limit,
+            long offset, Map<String, ? extends PropertyValue> bindings,
             NamePathMapper namePathMapper) throws ParseException {
         Query q = parseQuery(statement, language);
-        q.setRootTree(rootTree);
+        q.setRootTree(getRootTree());
+        q.setRootState(getRootState());
         q.setNamePathMapper(namePathMapper);
         q.setLimit(limit);
         q.setOffset(offset);
@@ -122,13 +139,13 @@ public class QueryEngineImpl {
         }
         q.setQueryEngine(this);
         q.prepare();
-        return q.executeQuery(this.rootState);
+        return q.executeQuery();
     }
 
-    public QueryIndex getBestIndex(Query query, Filter filter) {
+    public QueryIndex getBestIndex(Query query, NodeState rootState, Filter filter) {
         QueryIndex best = null;
         double bestCost = Double.MAX_VALUE;
-        for (QueryIndex index : getIndexes()) {
+        for (QueryIndex index : getIndexes(rootState)) {
             double cost = index.getCost(filter, rootState);
             if (LOG.isDebugEnabled()) {
                 LOG.debug("cost for " + index.getIndexName() + " is " + cost);
@@ -147,7 +164,7 @@ public class QueryEngineImpl {
         return best;
     }
 
-    private List<? extends QueryIndex> getIndexes() {
+    private List<? extends QueryIndex> getIndexes(NodeState rootState) {
         return indexProvider.getQueryIndexes(rootState);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultImpl.java?rev=1421163&r1=1421162&r2=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultImpl.java
Thu Dec 13 09:24:28 2012
@@ -18,11 +18,11 @@ package org.apache.jackrabbit.oak.query;
 
 import java.util.Iterator;
 import java.util.List;
+
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.ResultRow;
 import org.apache.jackrabbit.oak.query.ast.ColumnImpl;
 import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
  * A query result.
@@ -30,11 +30,9 @@ import org.apache.jackrabbit.oak.spi.sta
 public class ResultImpl implements Result {
 
     protected final Query query;
-    protected final NodeState rootState;
 
-    ResultImpl(Query query, NodeState rootState) {
+    ResultImpl(Query query) {
         this.query = query;
-        this.rootState = rootState;
     }
 
     @Override
@@ -63,7 +61,7 @@ public class ResultImpl implements Resul
 
             @Override
             public Iterator<ResultRowImpl> iterator() {
-                return query.getRows(rootState);
+                return query.getRows();
             }
 
         };

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java?rev=1421163&r1=1421162&r2=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserProvider.java
Thu Dec 13 09:24:28 2012
@@ -140,7 +140,7 @@ import static org.apache.jackrabbit.oak.
  * <h2>User and Group Access</h2>
  * <h3>By ID</h3>
  * Accessing authorizables by ID is achieved by calculating the ContentId
- * associated with that user/group and using {@link org.apache.jackrabbit.oak.api.SessionQueryEngine}
+ * associated with that user/group and using {@link org.apache.jackrabbit.oak.api.QueryEngine}
  * to find the corresponding {@code Tree}. The result is validated to really
  * represent a user/group tree.
  *
@@ -153,7 +153,7 @@ import static org.apache.jackrabbit.oak.
  * If the principal instance passed to {@link #getAuthorizableByPrincipal(java.security.Principal)}
  * is a {@code TreeBasedPrincipal} the lookup is equivalent to
  * {@link #getAuthorizableByPath(String)}. Otherwise the user/group is search
- * for using {@link org.apache.jackrabbit.oak.api.SessionQueryEngine} looking
+ * for using {@link org.apache.jackrabbit.oak.api.QueryEngine} looking
  * for a property {@link UserConstants#REP_PRINCIPAL_NAME} that matches the
  * name of the specified principal.
  */

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java?rev=1421163&r1=1421162&r2=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserQueryManager.java
Thu Dec 13 09:24:28 2012
@@ -29,7 +29,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.ResultRow;
 import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.api.SessionQueryEngine;
+import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.security.user.query.XPathQueryBuilder;
 import org.apache.jackrabbit.oak.security.user.query.XPathQueryEvaluator;
 import org.apache.jackrabbit.oak.spi.security.user.AuthorizableType;
@@ -104,7 +104,7 @@ class UserQueryManager {
                                              boolean exact, AuthorizableType type) throws
RepositoryException {
         // TODO: replace XPATH
         String statement = buildXPathStatement(relPath, value, exact, type);
-        SessionQueryEngine queryEngine = root.getQueryEngine();
+        QueryEngine queryEngine = root.getQueryEngine();
         try {
             Result result = queryEngine.executeQuery(statement, javax.jcr.query.Query.XPATH,
Long.MAX_VALUE, 0, null, userManager.getNamePathMapper());
             return Iterators.filter(Iterators.transform(result.getRows().iterator(), new
ResultRowToAuthorizable()), Predicates.<Object>notNull());

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java?rev=1421163&r1=1421162&r2=1421163&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
Thu Dec 13 09:24:28 2012
@@ -38,12 +38,11 @@ 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.api.Root;
-import org.apache.jackrabbit.oak.api.SessionQueryEngine;
+import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
@@ -61,7 +60,7 @@ public abstract class AbstractQueryTest 
 
     protected static final String TEST_INDEX_NAME = "test-index";
 
-    protected SessionQueryEngine qe;
+    protected QueryEngine qe;
     protected ContentSession session;
     protected Root root;
 



Mime
View raw message