jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1404582 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ oak-core/src/main/java/or...
Date Thu, 01 Nov 2012 13:23:16 GMT
Author: mreutegg
Date: Thu Nov  1 13:23:15 2012
New Revision: 1404582

URL: http://svn.apache.org/viewvc?rev=1404582&view=rev
Log:
OAK-355: Move QueryEngine reference from ContentSession to Root
- remove Root parameter from SessionQueryEngine.executeQuery()
- use NodeState from Root associated with current ContentSession (ensure session isolation)

Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.java
  (with props)
Modified:
    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/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.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/SessionQueryEngineImpl.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/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java

Modified: 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/SessionQueryEngine.java?rev=1404582&r1=1404581&r2=1404582&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/SessionQueryEngine.java
Thu Nov  1 13:23:15 2012
@@ -54,7 +54,6 @@ public interface SessionQueryEngine {
      * @param limit the maximum result set size
      * @param offset the number of rows to skip
      * @param bindings the bind variable value bindings
-     * @param root the root to use
      * @param namePathMapper the name and path mapper to use
      * @return the result
      * @throws ParseException if the statement could not be parsed
@@ -62,7 +61,7 @@ public interface SessionQueryEngine {
      */
     Result executeQuery(String statement, String language,
             long limit, long offset, Map<String, ? extends PropertyValue> bindings,
-            Root root, NamePathMapper namePathMapper) throws ParseException;
+            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/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=1404582&r1=1404581&r2=1404582&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 Nov  1 13:23:15 2012
@@ -288,7 +288,17 @@ public class RootImpl implements Root {
     @Override
     public SessionQueryEngine getQueryEngine() {
         checkLive();
-        return new SessionQueryEngineImpl(store, indexProvider);
+        return new SessionQueryEngineImpl(indexProvider) {
+            @Override
+            protected NodeState getRootNodeState() {
+                return rootTree.getNodeState();
+            }
+
+            @Override
+            protected Root getRoot() {
+                return RootImpl.this;
+            }
+        };
     }
 
     @Nonnull

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java?rev=1404582&r1=1404581&r2=1404582&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/IdentifierManager.java
Thu Nov  1 13:23:15 2012
@@ -189,7 +189,7 @@ public class IdentifierManager {
 
                 Result result = root.getQueryEngine().executeQuery(
                         "SELECT * FROM [nt:base] WHERE PROPERTY([" + pName + "], '" + reference
+ "') = $uuid",
-                        Query.JCR_SQL2, Long.MAX_VALUE, 0, bindings, root, new NamePathMapper.Default());
+                        Query.JCR_SQL2, Long.MAX_VALUE, 0, bindings, new NamePathMapper.Default());
 
                 Iterable<String> paths = Iterables.transform(result.getRows(),
                         new Function<ResultRow, String>() {
@@ -288,7 +288,7 @@ public class IdentifierManager {
             Map<String, PropertyValue> bindings = Collections.singletonMap("id", PropertyValues.create(uuid));
             Result result = root.getQueryEngine().executeQuery(
                     "SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id", Query.JCR_SQL2,
-                    Long.MAX_VALUE, 0, bindings, root, new NamePathMapper.Default());
+                    Long.MAX_VALUE, 0, bindings, new NamePathMapper.Default());
 
             String path = null;
             for (ResultRow rr : result.getRows()) {

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=1404582&r1=1404581&r2=1404582&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 Nov  1 13:23:15 2012
@@ -29,7 +29,7 @@ import org.apache.jackrabbit.oak.query.i
 import org.apache.jackrabbit.oak.spi.query.Filter;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
  * The query engine implementation.
@@ -41,11 +41,11 @@ public class QueryEngineImpl {
     static final String XPATH = "xpath";
     static final String JQOM = "JCR-JQOM";
 
-    private final NodeStore store;
+    private final NodeState root;
     private final QueryIndexProvider indexProvider;
 
-    public QueryEngineImpl(NodeStore store, QueryIndexProvider indexProvider) {
-        this.store = store;
+    public QueryEngineImpl(NodeState root, QueryIndexProvider indexProvider) {
+        this.root = root;
         this.indexProvider = indexProvider;
     }
 
@@ -106,7 +106,7 @@ public class QueryEngineImpl {
         }
         q.setQueryEngine(this);
         q.prepare();
-        return q.executeQuery(store.getRoot());
+        return q.executeQuery(this.root);
     }
 
     public QueryIndex getBestIndex(Filter filter) {
@@ -126,7 +126,7 @@ public class QueryEngineImpl {
     }
 
     private List<? extends QueryIndex> getIndexes() {
-        return indexProvider.getQueryIndexes(store.getRoot());
+        return indexProvider.getQueryIndexes(root);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java?rev=1404582&r1=1404581&r2=1404582&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SessionQueryEngineImpl.java
Thu Nov  1 13:23:15 2012
@@ -20,43 +20,62 @@ import java.text.ParseException;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.SessionQueryEngine;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
  * The query engine implementation bound to a session.
  */
-public class SessionQueryEngineImpl implements SessionQueryEngine {
+public abstract class SessionQueryEngineImpl implements SessionQueryEngine {
 
-    private final QueryEngineImpl queryEngine;
+    private final QueryIndexProvider indexProvider;
 
-    public SessionQueryEngineImpl(NodeStore store,
-            QueryIndexProvider indexProvider) {
-        this.queryEngine = new QueryEngineImpl(store, indexProvider);
+    public SessionQueryEngineImpl(QueryIndexProvider indexProvider) {
+        this.indexProvider = indexProvider;
     }
 
+    /**
+     * The implementing class must return the current root {@link NodeState}
+     * associated with the {@link ContentSession}.
+     *
+     * @return the current root {@link NodeState}.
+     */
+    protected abstract NodeState getRootNodeState();
+
+    /**
+     * The implementing class must return the root associated with the
+     * {@link ContentSession}.
+     *
+     * @return the root associated with the {@link ContentSession}.
+     */
+    protected abstract Root getRoot();
+
     @Override
     public List<String> getSupportedQueryLanguages() {
-        return queryEngine.getSupportedQueryLanguages();
+        return createQueryEngine().getSupportedQueryLanguages();
     }
 
     @Override
     public List<String> getBindVariableNames(String statement, String language)
             throws ParseException {
-        return queryEngine.getBindVariableNames(statement, language);
+        return createQueryEngine().getBindVariableNames(statement, language);
     }
 
     @Override
     public Result executeQuery(String statement, String language, long limit,
-            long offset, Map<String, ? extends PropertyValue> bindings, Root root,
+            long offset, Map<String, ? extends PropertyValue> bindings,
             NamePathMapper namePathMapper) throws ParseException {
-        return queryEngine.executeQuery(statement, language, limit, offset,
-                bindings, root, namePathMapper);
+        return createQueryEngine().executeQuery(statement, language, limit,
+                offset, bindings, getRoot(), namePathMapper);
     }
 
+    private QueryEngineImpl createQueryEngine() {
+        return new QueryEngineImpl(getRootNodeState(), indexProvider);
+    }
 }

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=1404582&r1=1404581&r2=1404582&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 Nov  1 13:23:15 2012
@@ -197,7 +197,7 @@ class UserProvider extends AuthorizableB
             Result result = root.getQueryEngine().executeQuery(stmt.toString(),
                     Query.JCR_SQL2, 1, 0,
                     Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())),
-                    root, new NamePathMapper.Default());
+                    new NamePathMapper.Default());
 
             Iterator<? extends ResultRow> rows = result.getRows().iterator();
             if (rows.hasNext()) {

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=1404582&r1=1404581&r2=1404582&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 Nov  1 13:23:15 2012
@@ -114,7 +114,7 @@ class UserQueryManager {
         SessionQueryEngine queryEngine = root.getQueryEngine();
         try {
             Map<String,PropertyValue> bindings = (value != null) ? Collections.singletonMap("propValue",
PropertyValues.newString(value)) : null;
-            Result result = queryEngine.executeQuery(statement, javax.jcr.query.Query.XPATH,
Long.MAX_VALUE, 0, bindings, root, userManager.getNamePathMapper());
+            Result result = queryEngine.executeQuery(statement, javax.jcr.query.Query.XPATH,
Long.MAX_VALUE, 0, bindings, userManager.getNamePathMapper());
             return Iterators.filter(Iterators.transform(result.getRows().iterator(), new
ResultRowToAuthorizable()), Predicates.<Object>notNull());
         } catch (ParseException e) {
             throw new RepositoryException(e);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java?rev=1404582&r1=1404581&r2=1404582&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/XPathQueryEvaluator.java
Thu Nov  1 13:23:15 2012
@@ -294,7 +294,7 @@ public class XPathQueryEvaluator impleme
 
     @Nonnull
     private Iterator<Authorizable> findAuthorizables(long limit, long offset) throws
ParseException {
-        Iterable<? extends ResultRow> resultRows = root.getQueryEngine().executeQuery(xPath.toString(),
Query.XPATH, limit, offset, null, root, namePathMapper).getRows();
+        Iterable<? extends ResultRow> resultRows = root.getQueryEngine().executeQuery(xPath.toString(),
Query.XPATH, limit, offset, null, namePathMapper).getRows();
 
         Function<ResultRow, Authorizable> transformer = new Function<ResultRow,
Authorizable>() {
             public Authorizable apply(ResultRow resultRow) {

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.java?rev=1404582&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.java
Thu Nov  1 13:23:15 2012
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak.api;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.jcr.query.Query;
+
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * <code>QueryTest</code> contains query related tests.
+ */
+public class QueryTest {
+
+    private ContentRepository repository;
+
+    @Before
+    public void setUp() {
+        repository = new Oak().createContentRepository();
+    }
+
+    @After
+    public void tearDown() {
+        repository = null;
+    }
+
+    @Test
+    public void queryOnStableRevision() throws Exception {
+        ContentSession s = repository.login(null, null);
+        Root r = s.getLatestRoot();
+        Tree t = r.getTree("/");
+        t.addChild("node1").setProperty("jcr:primaryType", "nt:base");
+        t.addChild("node2").setProperty("jcr:primaryType", "nt:base");
+        t.addChild("node3").setProperty("jcr:primaryType", "nt:base");
+        r.commit();
+
+        ContentSession s2 = repository.login(null, null);
+        Root r2 = s2.getLatestRoot();
+
+        r.getTree("/").getChild("node2").remove();
+        r.commit();
+
+        Result result = r2.getQueryEngine().executeQuery(
+                "//element(*, nt:base)",
+                Query.XPATH, Long.MAX_VALUE, 0,
+                Collections.<String, PropertyValue>emptyMap(),
+                NamePathMapper.DEFAULT);
+        Set<String> paths = new HashSet<String>();
+        for (ResultRow rr : result.getRows()) {
+            paths.add(rr.getPath());
+        }
+        assertEquals(new HashSet<String>(Arrays.asList("/", "/node1", "/node2", "/node3")),
paths);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

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=1404582&r1=1404581&r2=1404582&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 Nov  1 13:23:15 2012
@@ -99,8 +99,7 @@ public abstract class AbstractQueryTest 
 
     protected Result executeQuery(String statement, String language,
             Map<String, PropertyValue> sv) throws ParseException {
-        return qe.executeQuery(statement, language, Long.MAX_VALUE, 0, sv,
-                session.getLatestRoot(), null);
+        return qe.executeQuery(statement, language, Long.MAX_VALUE, 0, sv, null);
     }
 
     @Test

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=1404582&r1=1404581&r2=1404582&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
Thu Nov  1 13:23:15 2012
@@ -118,7 +118,7 @@ public class QueryManagerImpl implements
             Map<String, PropertyValue> bindMap = convertMap(bindVariableMap);
             NamePathMapper namePathMapper = sessionDelegate.getNamePathMapper();
             Result r = queryEngine.executeQuery(statement, language, limit, offset,
-                    bindMap, sessionDelegate.getRoot(), namePathMapper);
+                    bindMap, namePathMapper);
             return new QueryResultImpl(sessionDelegate, r);
         } catch (IllegalArgumentException e) {
             throw new InvalidQueryException(e);



Mime
View raw message