jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1560446 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/identifier/ oak-core/src/main/jav...
Date Wed, 22 Jan 2014 18:06:38 GMT
Author: jukka
Date: Wed Jan 22 18:06:37 2014
New Revision: 1560446

URL: http://svn.apache.org/r1560446
Log:
OAK-1285: QueryEngine#executeQuery takes NamePathMapper which is not part of oak-api

Replace the NamePathMapper argument with the set of local namespace
mappings, which is used to construct a NamePathMapper instance for
the query.

Pass that instance directly as a constructor argument to QueryImpl instead
of having the setter in the Query interface.

Replace Name(Path)Mapper.hasSessionLocalMappings() with .getSessionLocalMappings()
so that we can access those mappings in UserQueryManager.

Add NO_BINDINGS and NO_MAPPINGS constants to QueryEngine to make null
arguments more readable.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.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/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/QueryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/UnionQueryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.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/query/UserQueryManager.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.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
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
Wed Jan 22 18:06:37 2014
@@ -16,13 +16,13 @@
  */
 package org.apache.jackrabbit.oak.api;
 
+import static java.util.Collections.emptyMap;
+
 import java.text.ParseException;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-
 /**
  * The query engine allows to parse and execute queries.
  * <p>
@@ -40,14 +40,15 @@ public interface QueryEngine {
     /**
      * Parse the query (check if it's valid) and get the list of bind variable names.
      *
-     * @param statement
-     * @param language
-     * @param namePathMapper the name and path mapper to use
+     * @param statement query statement
+     * @param language query language
+     * @param mappings namespace prefix mappings
      * @return the list of bind variable names
      * @throws ParseException
      */
-    List<String> getBindVariableNames(String statement, String language,
-            NamePathMapper namePathMapper) throws ParseException;
+    List<String> getBindVariableNames(
+            String statement, String language, Map<String, String> mappings)
+            throws ParseException;
 
     /**
      * Execute a query and get the result.
@@ -57,13 +58,29 @@ public interface QueryEngine {
      * @param limit the maximum result set size (may not be negative)
      * @param offset the number of rows to skip (may not be negative)
      * @param bindings the bind variable value bindings
-     * @param namePathMapper the name and path mapper to use
+     * @param mappings namespace prefix mappings
      * @return the result
      * @throws ParseException if the statement could not be parsed
      * @throws IllegalArgumentException if there was an error executing the query
      */
-    Result executeQuery(String statement, String language,
-            long limit, long offset, Map<String, ? extends PropertyValue> bindings,
-            NamePathMapper namePathMapper) throws ParseException;
+    Result executeQuery(
+            String statement, String language, long limit, long offset,
+            Map<String, ? extends PropertyValue> bindings,
+            Map<String, String> mappings) throws ParseException;
+
+    /**
+     * Empty set of variables bindings. Useful as an argument to
+     * {@link #executeQuery(String, String, long, long, Map, Map)} when
+     * there are no variables in a query.
+     */
+    Map<String, PropertyValue> NO_BINDINGS = emptyMap();
+
+    /**
+     * Empty set of namespace prefix mappings. Useful as an argument to
+     * {@link #getBindVariableNames(String, String, Map)} and
+     * {@link #executeQuery(String, String, long, long, Map, Map)} when
+     * there are no local namespace mappings.
+     */
+    Map<String, String> NO_MAPPINGS = emptyMap();
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
Wed Jan 22 18:06:37 2014
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
+import java.util.Collections;
+import java.util.Map;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
@@ -90,8 +93,8 @@ public class GlobalNameMapper implements
     }
 
     @Override
-    public boolean hasSessionLocalMappings() {
-        return false;
+    public Map<String, String> getSessionLocalMappings() {
+        return Collections.emptyMap();
     }
 
     @CheckForNull

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
Wed Jan 22 18:06:37 2014
@@ -41,7 +41,8 @@ public abstract class LocalNameMapper ex
         checkArgument(!oakName.startsWith(":"), oakName); // hidden name
         checkArgument(!isExpandedName(oakName), oakName); // expanded name
 
-        if (hasSessionLocalMappings()) {
+        Map<String, String> local = getSessionLocalMappings();
+        if (!local.isEmpty()) {
             int colon = oakName.indexOf(':');
             if (colon > 0) {
                 String oakPrefix = oakName.substring(0, colon);
@@ -51,7 +52,6 @@ public abstract class LocalNameMapper ex
                             "No namespace mapping found for " + oakName);
                 }
 
-                Map<String, String> local = getSessionLocalMappings();
                 for (Map.Entry<String, String> entry : local.entrySet()) {
                     if (uri.equals(entry.getValue())) {
                         String jcrPrefix = entry.getKey();
@@ -87,10 +87,10 @@ public abstract class LocalNameMapper ex
             return getOakNameFromExpanded(jcrName);
         }
 
-        if (hasSessionLocalMappings()) {
+        Map<String, String> local = getSessionLocalMappings();
+        if (!local.isEmpty()) {
             int colon = jcrName.indexOf(':');
             if (colon > 0) {
-                Map<String, String> local = getSessionLocalMappings();
                 String jcrPrefix = jcrName.substring(0, colon);
                 String uri = local.get(jcrPrefix);
                 if (uri != null) {
@@ -115,10 +115,4 @@ public abstract class LocalNameMapper ex
         return jcrName;
     }
 
-    @Override
-    public boolean hasSessionLocalMappings() {
-        return !getSessionLocalMappings().isEmpty();
-    }
-
-    protected abstract Map<String, String> getSessionLocalMappings();
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
Wed Jan 22 18:06:37 2014
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
+import java.util.Map;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
@@ -48,14 +50,14 @@ public interface NameMapper {
     @Nonnull
     String getOakName(@Nonnull String jcrName) throws RepositoryException;
 
-
     /**
-     * Returns whether the mapper has prefix remappings; when there aren't
-     * any, prefixed names do not need to be converted at all
-     * 
-     * @return {@code true} if prefixes have been remapped
+     * Returns the local namespace prefix mappings, or an empty map if
+     * there aren't any local mappings.
+     *
+     * @return local namespace prefix to URI mappings
      */
-    boolean hasSessionLocalMappings();
+    @Nonnull
+    Map<String, String> getSessionLocalMappings();
 
     /**
      * Returns the JCR name for the given Oak name. The given name is

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
Wed Jan 22 18:06:37 2014
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
+import java.util.Collections;
+import java.util.Map;
+
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
 
@@ -45,8 +48,8 @@ public interface NamePathMapper extends 
         }
 
         @Override
-        public boolean hasSessionLocalMappings() {
-            return false;
+        public Map<String, String> getSessionLocalMappings() {
+            return Collections.emptyMap();
         }
 
         @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
Wed Jan 22 18:06:37 2014
@@ -18,6 +18,8 @@ package org.apache.jackrabbit.oak.namepa
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
 
@@ -67,9 +69,9 @@ public class NamePathMapperImpl implemen
         return nameMapper.getJcrName(oakName);
     }
 
-    @Override
-    public boolean hasSessionLocalMappings() {
-        return nameMapper.hasSessionLocalMappings();
+    @Override @Nonnull
+    public Map<String, String> getSessionLocalMappings() {
+        return nameMapper.getSessionLocalMappings();
     }
 
     //---------------------------------------------------------< PathMapper >---
@@ -279,7 +281,7 @@ public class NamePathMapperImpl implemen
             }
         }
 
-        return colon != -1 && hasSessionLocalMappings();
+        return colon != -1 && !getSessionLocalMappings().isEmpty();
     }
 
     //------------------------------------------------------------< PathListener >---

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=1560446&r1=1560445&r2=1560446&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
Wed Jan 22 18:06:37 2014
@@ -21,6 +21,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.UUID;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.PropertyType;
@@ -29,6 +30,7 @@ import javax.jcr.query.Query;
 import com.google.common.base.Charsets;
 import com.google.common.base.Function;
 import com.google.common.collect.Iterators;
+
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.PropertyValue;
@@ -52,6 +54,7 @@ import static com.google.common.collect.
 import static com.google.common.collect.Iterators.filter;
 import static com.google.common.collect.Iterators.singletonIterator;
 import static com.google.common.collect.Iterators.transform;
+import static org.apache.jackrabbit.oak.api.QueryEngine.NO_MAPPINGS;
 
 /**
  * TODO document
@@ -217,7 +220,7 @@ public class IdentifierManager {
         try {
             Result result = root.getQueryEngine().executeQuery(
                     "SELECT * FROM [nt:base] WHERE PROPERTY([" + pName + "], '" + reference
+ "') = $uuid",
-                    Query.JCR_SQL2, Long.MAX_VALUE, 0, bindings, new NamePathMapper.Default());
+                    Query.JCR_SQL2, Long.MAX_VALUE, 0, bindings, NO_MAPPINGS);
             return findPaths(result, uuid, propertyName, nodeTypeNames,
                     weak ? Type.WEAKREFERENCE : Type.REFERENCE,
                     weak ? Type.WEAKREFERENCES : Type.REFERENCES
@@ -308,7 +311,7 @@ public class IdentifierManager {
             Map<String, PropertyValue> bindings = Collections.singletonMap("id", uuid);
             Result result = root.getQueryEngine().executeQuery(
                     "SELECT * FROM [nt:base] WHERE [jcr:uuid] = $id", Query.JCR_SQL2,
-                    Long.MAX_VALUE, 0, bindings, new NamePathMapper.Default());
+                    Long.MAX_VALUE, 0, bindings, NO_MAPPINGS);
 
             String path = null;
             for (ResultRow rr : result.getRows()) {

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=1560446&r1=1560445&r2=1560446&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
Wed Jan 22 18:06:37 2014
@@ -19,7 +19,6 @@ import java.util.List;
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.query.ast.ColumnImpl;
 import org.apache.jackrabbit.oak.query.ast.OrderingImpl;
 
@@ -34,8 +33,6 @@ public interface Query {
 
     void setExecutionContext(ExecutionContext context);
 
-    void setNamePathMapper(NamePathMapper namePathMapper);
-
     void setLimit(long limit);
 
     void setOffset(long offset);

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=1560446&r1=1560445&r2=1560446&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
Wed Jan 22 18:06:37 2014
@@ -29,7 +29,9 @@ import java.util.Set;
 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.namepath.LocalNameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
+import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
 import org.apache.jackrabbit.oak.query.xpath.XPathToSQL2Converter;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.slf4j.Logger;
@@ -75,24 +77,38 @@ public abstract class QueryEngineImpl im
     /**
      * Parse the query (check if it's valid) and get the list of bind variable names.
      *
-     * @param statement
-     * @param language
+     * @param statement query statement
+     * @param language query language
+     * @param mappings namespace prefix mappings
      * @return the list of bind variable names
      * @throws ParseException
      */
     @Override
-    public List<String> getBindVariableNames(String statement, String language, NamePathMapper
namePathMapper) throws ParseException {
-        Query q = parseQuery(statement, language, getExecutionContext(), namePathMapper);
+    public List<String> getBindVariableNames(
+            String statement, String language, Map<String, String> mappings)
+            throws ParseException {
+        Query q = parseQuery(statement, language, getExecutionContext(), mappings);
         return q.getBindVariableNames();
     }
 
-    private static Query parseQuery(String statement, String language, 
-            ExecutionContext context, NamePathMapper namePathMapper) throws ParseException
{
+    private static Query parseQuery(
+            String statement, String language, ExecutionContext context,
+            final Map<String, String> mappings) throws ParseException {
         LOG.debug("Parsing {} statement: {}", language, statement);
+
+        NamePathMapper mapper = new NamePathMapperImpl(
+                new LocalNameMapper(context.getRootTree()) {
+                    @Override
+                    public Map<String, String> getSessionLocalMappings() {
+                        return mappings;
+                    }
+                });
+
         NodeState types = context.getBaseState()
                 .getChildNode(JCR_SYSTEM)
                 .getChildNode(JCR_NODE_TYPES);
-        SQL2Parser parser = new SQL2Parser(namePathMapper, types);
+
+        SQL2Parser parser = new SQL2Parser(mapper, types);
         if (language.endsWith(NO_LITERALS)) {
             language = language.substring(0, language.length() - NO_LITERALS.length());
             parser.setAllowNumberLiterals(false);
@@ -123,9 +139,10 @@ public abstract class QueryEngineImpl im
     }
     
     @Override
-    public Result executeQuery(String statement, String language, long limit,
-            long offset, Map<String, ? extends PropertyValue> bindings,
-            NamePathMapper namePathMapper) throws ParseException {
+    public Result executeQuery(
+            String statement, String language, long limit, long offset,
+            Map<String, ? extends PropertyValue> bindings,
+            Map<String, String> mappings) throws ParseException {
         if (limit < 0) {
             throw new IllegalArgumentException("Limit may not be negative, is: " + limit);
         }
@@ -133,10 +150,17 @@ public abstract class QueryEngineImpl im
             throw new IllegalArgumentException("Offset may not be negative, is: " + offset);
         }
 
+        // avoid having to deal with null arguments
+        if (bindings == null) {
+            bindings = NO_BINDINGS;
+        }
+        if (mappings == null) {
+            mappings = NO_MAPPINGS;
+        }
+
         ExecutionContext context = getExecutionContext();
-        Query q = parseQuery(statement, language, context, namePathMapper);
+        Query q = parseQuery(statement, language, context, mappings);
         q.setExecutionContext(context);
-        q.setNamePathMapper(namePathMapper);
         q.setLimit(limit);
         q.setOffset(offset);
         if (bindings != null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryImpl.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryImpl.java
Wed Jan 22 18:06:37 2014
@@ -111,13 +111,16 @@ public class QueryImpl implements Query 
     private long size = -1;
     private boolean prepared;
     private ExecutionContext context;
-    private NamePathMapper namePathMapper;
 
-    QueryImpl(String statement, SourceImpl source, ConstraintImpl constraint, ColumnImpl[]
columns) {
+    private final NamePathMapper namePathMapper;
+
+    QueryImpl(String statement, SourceImpl source, ConstraintImpl constraint,
+            ColumnImpl[] columns, NamePathMapper mapper) {
         this.statement = statement;
         this.source = source;
         this.constraint = constraint;
         this.columns = columns;
+        this.namePathMapper = mapper;
     }
 
     @Override
@@ -632,11 +635,6 @@ public class QueryImpl implements Query 
         this.orderings = orderings;
     }
 
-    @Override
-    public void setNamePathMapper(NamePathMapper namePathMapper) {
-        this.namePathMapper = namePathMapper;
-    }
-
     public NamePathMapper getNamePathMapper() {
         return namePathMapper;
     }
@@ -660,9 +658,6 @@ public class QueryImpl implements Query 
         if (!JcrPathParser.validate(path)) {
             throw new IllegalArgumentException("Invalid path: " + path);
         }
-        if (namePathMapper == null) {
-            return path;
-        }
         String p = namePathMapper.getOakPath(path);
         if (p == null) {
             throw new IllegalArgumentException("Invalid path or namespace prefix: " + path);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
Wed Jan 22 18:06:37 2014
@@ -182,7 +182,8 @@ public class SQL2Parser {
         if (readIf("WHERE")) {
             constraint = parseConstraint();
         }
-        QueryImpl q = new QueryImpl(statement, source, constraint, columnArray);
+        QueryImpl q = new QueryImpl(
+                statement, source, constraint, columnArray, namePathMapper);
         q.setDistinct(distinct);
         return q;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/UnionQueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/UnionQueryImpl.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/UnionQueryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/UnionQueryImpl.java
Wed Jan 22 18:06:37 2014
@@ -23,7 +23,6 @@ import java.util.List;
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.query.ast.ColumnImpl;
 import org.apache.jackrabbit.oak.query.ast.OrderingImpl;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
@@ -81,12 +80,6 @@ public class UnionQueryImpl implements Q
     }
 
     @Override
-    public void setNamePathMapper(NamePathMapper namePathMapper) {
-        left.setNamePathMapper(namePathMapper);
-        right.setNamePathMapper(namePathMapper);
-    }
-
-    @Override
     public void setLimit(long limit) {
         this.limit = limit;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/accesscontrol/AccessControlManagerImpl.java
Wed Jan 22 18:06:37 2014
@@ -52,7 +52,6 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.commons.iterator.AccessControlPolicyIteratorAdapter;
 import org.apache.jackrabbit.commons.jackrabbit.authorization.AccessControlUtils;
 import org.apache.jackrabbit.oak.api.PropertyState;
-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.ResultRow;
@@ -509,7 +508,9 @@ public class AccessControlManagerImpl ex
 
         try {
             QueryEngine queryEngine = root.getQueryEngine();
-            return queryEngine.executeQuery(stmt.toString(), Query.XPATH, Long.MAX_VALUE,
0, Collections.<String, PropertyValue>emptyMap(), NamePathMapper.DEFAULT);
+            return queryEngine.executeQuery(
+                    stmt.toString(), Query.XPATH, Long.MAX_VALUE, 0,
+                    QueryEngine.NO_BINDINGS, QueryEngine.NO_MAPPINGS);
         } catch (ParseException e) {
             String msg = "Error while collecting effective policies.";
             log.error(msg, e.getMessage());

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=1560446&r1=1560445&r2=1560446&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
Wed Jan 22 18:06:37 2014
@@ -20,6 +20,7 @@ import java.security.Principal;
 import java.text.ParseException;
 import java.util.Collections;
 import java.util.Iterator;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.AccessDeniedException;
@@ -33,7 +34,6 @@ import org.apache.jackrabbit.oak.api.Res
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
 import org.apache.jackrabbit.oak.spi.security.user.AuthorizableNodeName;
@@ -45,6 +45,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.api.QueryEngine.NO_MAPPINGS;
 
 /**
  * User provider implementation and manager for group memberships with the
@@ -211,7 +212,7 @@ class UserProvider extends AuthorizableB
             Result result = root.getQueryEngine().executeQuery(stmt.toString(),
                     Query.JCR_SQL2, 1, 0,
                     Collections.singletonMap("principalName", PropertyValues.newString(principal.getName())),
-                    new NamePathMapper.Default());
+                    NO_MAPPINGS);
 
             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/query/UserQueryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManager.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/query/UserQueryManager.java
Wed Jan 22 18:06:37 2014
@@ -16,10 +16,13 @@
  */
 package org.apache.jackrabbit.oak.security.user.query;
 
+import static org.apache.jackrabbit.oak.api.QueryEngine.NO_BINDINGS;
+
 import java.text.ParseException;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
+
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.jcr.RepositoryException;
@@ -28,11 +31,12 @@ import javax.jcr.Value;
 import com.google.common.base.Predicate;
 import com.google.common.base.Strings;
 import com.google.common.collect.Iterators;
+
 import org.apache.jackrabbit.api.security.user.Authorizable;
 import org.apache.jackrabbit.api.security.user.Query;
 import org.apache.jackrabbit.api.security.user.QueryBuilder;
 import org.apache.jackrabbit.api.security.user.UserManager;
-import org.apache.jackrabbit.oak.api.QueryEngine;
+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.commons.PathUtils;
@@ -276,8 +280,10 @@ public class UserQueryManager {
                                                      long offset,
                                                      @Nullable AuthorizableType type) throws
RepositoryException {
         try {
-            QueryEngine queryEngine = root.getQueryEngine();
-            Iterable<? extends ResultRow> resultRows = queryEngine.executeQuery(statement,
javax.jcr.query.Query.XPATH, limit, offset, null, namePathMapper).getRows();
+            Result query = root.getQueryEngine().executeQuery(
+                    statement, javax.jcr.query.Query.XPATH, limit, offset,
+                    NO_BINDINGS, namePathMapper.getSessionLocalMappings());
+            Iterable<? extends ResultRow> resultRows = query.getRows();
             Iterator<Authorizable> authorizables = Iterators.transform(resultRows.iterator(),
new ResultRowToAuthorizable(userManager, root, type));
             return Iterators.filter(authorizables, new UniqueResultPredicate());
         } catch (ParseException e) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java
Wed Jan 22 18:06:37 2014
@@ -60,7 +60,7 @@ public final class TestNameMapper extend
     }
 
     @Override
-    protected Map<String, String> getSessionLocalMappings() {
+    public Map<String, String> getSessionLocalMappings() {
         return local;
     }
 }
\ No newline at end of file

Modified: 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=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/api/QueryTest.java
Wed Jan 22 18:06:37 2014
@@ -21,14 +21,12 @@ package org.apache.jackrabbit.oak.api;
 import static junit.framework.Assert.assertEquals;
 
 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.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
 import org.junit.After;
@@ -69,10 +67,8 @@ public class QueryTest {
         r.commit();
 
         Result result = r2.getQueryEngine().executeQuery(
-                "test//element(*, nt:base)",
-                Query.XPATH, Long.MAX_VALUE, 0,
-                Collections.<String, PropertyValue>emptyMap(),
-                NamePathMapper.DEFAULT);
+                "test//element(*, nt:base)", Query.XPATH, Long.MAX_VALUE, 0,
+                QueryEngine.NO_BINDINGS, QueryEngine.NO_MAPPINGS);
         Set<String> paths = new HashSet<String>();
         for (ResultRow rr : result.getRows()) {
             paths.add(rr.getPath());

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=1560446&r1=1560445&r2=1560446&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
Wed Jan 22 18:06:37 2014
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.oak.query;
 
+import static org.apache.jackrabbit.oak.api.QueryEngine.NO_BINDINGS;
+import static org.apache.jackrabbit.oak.api.QueryEngine.NO_MAPPINGS;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
@@ -41,6 +43,7 @@ import java.util.Map;
 import javax.jcr.PropertyType;
 
 import com.google.common.collect.Lists;
+
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
@@ -108,7 +111,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, null);
+        return qe.executeQuery(statement, language, Long.MAX_VALUE, 0, sv, NO_MAPPINGS);
     }
 
     protected void test(String file) throws Exception {
@@ -227,7 +230,7 @@ public abstract class AbstractQueryTest 
         long time = System.currentTimeMillis();
         List<String> lines = new ArrayList<String>();
         try {
-            Result result = executeQuery(query, language, null);
+            Result result = executeQuery(query, language, NO_BINDINGS);
             for (ResultRow row : result.getRows()) {
                 lines.add(readRow(row, pathsOnly));
             }

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=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
Wed Jan 22 18:06:37 2014
@@ -108,7 +108,9 @@ public class QueryManagerImpl implements
      */
     public List<String> parse(String statement, String language) throws InvalidQueryException
{
         try {
-            return queryEngine.getBindVariableNames(statement, language, sessionContext);
+            return queryEngine.getBindVariableNames(
+                    statement, language,
+                    sessionContext.getSessionLocalMappings());
         } catch (ParseException e) {
             throw new InvalidQueryException(e);
         }
@@ -118,8 +120,9 @@ public class QueryManagerImpl implements
             long limit, long offset, HashMap<String, Value> bindVariableMap) throws
RepositoryException {
         try {
             Map<String, PropertyValue> bindMap = convertMap(bindVariableMap);
-            Result r = queryEngine.executeQuery(statement, language, limit, offset,
-                    bindMap, sessionContext);
+            Result r = queryEngine.executeQuery(
+                    statement, language, limit, offset, bindMap,
+                    sessionContext.getSessionLocalMappings());
             return new QueryResultImpl(sessionContext, r);
         } catch (IllegalArgumentException e) {
             throw new InvalidQueryException(e);

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
Wed Jan 22 18:06:37 2014
@@ -120,9 +120,8 @@ public class SessionContext implements N
 
         this.namespaces = new SessionNamespaces(this);
         LocalNameMapper nameMapper = new LocalNameMapper(delegate.getRoot().getTree("/"))
{
-
             @Override
-            protected Map<String, String> getSessionLocalMappings() {
+            public Map<String, String> getSessionLocalMappings() {
                 return namespaces.getSessionLocalMappings();
             }
         };
@@ -186,6 +185,11 @@ public class SessionContext implements N
         return namespaces;
     }
 
+    @Nonnull
+    public Map<String, String> getSessionLocalMappings() {
+        return namespaces.getSessionLocalMappings();
+    }
+
     public ValueFactory getValueFactory() {
         return valueFactory;
     }
@@ -280,11 +284,6 @@ public class SessionContext implements N
     }
 
     @Override
-    public boolean hasSessionLocalMappings() {
-        return !namespaces.getSessionLocalMappings().isEmpty();
-    }
-
-    @Override
     public String getJcrName(@Nonnull String oakName) {
         return namePathMapper.getJcrName(oakName);
     }
@@ -420,4 +419,5 @@ public class SessionContext implements N
         }
         return permissionProvider;
     }
+
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java?rev=1560446&r1=1560445&r2=1560446&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java
Wed Jan 22 18:06:37 2014
@@ -109,9 +109,8 @@ public abstract class TargetImportHandle
 
     public NamePathMapper currentNamePathMapper() {
         return new NamePathMapperImpl(new LocalNameMapper(getNSReadTree()) {
-
             @Override
-            protected Map<String, String> getSessionLocalMappings() {
+            public Map<String, String> getSessionLocalMappings() {
                 return documentPrefixMap;
             }
         });



Mime
View raw message