jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1536602 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/query/ oak-core/src/test/java/org/apache/jackrabbit/oak/query/ oak-jcr/src/main/java/org/apache/jack...
Date Tue, 29 Oct 2013 08:14:22 GMT
Author: thomasm
Date: Tue Oct 29 08:14:22 2013
New Revision: 1536602

URL: http://svn.apache.org/r1536602
Log:
OAK-1106 Query engine does not deal with remapped namespaces (namespace remapping while parsing)

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/query/QueryEngineImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/SQL2Parser.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryManagerImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/RemappingTest.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=1536602&r1=1536601&r2=1536602&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
Tue Oct 29 08:14:22 2013
@@ -42,10 +42,12 @@ public interface QueryEngine {
      *
      * @param statement
      * @param language
+     * @param namePathMapper the name and path mapper to use
      * @return the list of bind variable names
      * @throws ParseException
      */
-    List<String> getBindVariableNames(String statement, String language) throws ParseException;
+    List<String> getBindVariableNames(String statement, String language,
+            NamePathMapper namePathMapper) throws ParseException;
 
     /**
      * Execute a query and get the result.

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=1536602&r1=1536601&r2=1536602&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
Tue Oct 29 08:14:22 2013
@@ -88,17 +88,18 @@ public abstract class QueryEngineImpl im
      * @throws ParseException
      */
     @Override
-    public List<String> getBindVariableNames(String statement, String language) throws
ParseException {
-        Query q = parseQuery(statement, language, getExecutionContext());
+    public List<String> getBindVariableNames(String statement, String language, NamePathMapper
namePathMapper) throws ParseException {
+        Query q = parseQuery(statement, language, getExecutionContext(), namePathMapper);
         return q.getBindVariableNames();
     }
 
-    private static Query parseQuery(String statement, String language, ExecutionContext context)
throws ParseException {
+    private static Query parseQuery(String statement, String language, 
+            ExecutionContext context, NamePathMapper namePathMapper) throws ParseException
{
         LOG.debug("Parsing {} statement: {}", language, statement);
         NodeState root = context.getRootState();
         NodeState system = root.getChildNode(JCR_SYSTEM);
         NodeState types = system.getChildNode(JCR_NODE_TYPES);
-        SQL2Parser parser = new SQL2Parser(types);
+        SQL2Parser parser = new SQL2Parser(namePathMapper, types);
         if (language.endsWith(NO_LITERALS)) {
             language = language.substring(0, language.length() - NO_LITERALS.length());
             parser.setAllowNumberLiterals(false);
@@ -116,7 +117,10 @@ public abstract class QueryEngineImpl im
             try {
                 return parser.parse(sql2);
             } catch (ParseException e) {
-                throw new ParseException(statement + " converted to SQL-2 " + e.getMessage(),
0);
+                ParseException e2 = new ParseException(
+                        statement + " converted to SQL-2 " + e.getMessage(), 0);
+                e2.initCause(e);
+                throw e2;
             }
         } else {
             throw new ParseException("Unsupported language: " + language, 0);
@@ -135,7 +139,7 @@ public abstract class QueryEngineImpl im
         }
 
         ExecutionContext context = getExecutionContext();
-        Query q = parseQuery(statement, language, context);
+        Query q = parseQuery(statement, language, context, namePathMapper);
         q.setExecutionContext(context);
         q.setNamePathMapper(namePathMapper);
         q.setLimit(limit);

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=1536602&r1=1536601&r2=1536602&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
Tue Oct 29 08:14:22 2013
@@ -27,10 +27,12 @@ import java.util.HashMap;
 import java.util.Map;
 
 import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.api.PropertyValue;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.query.ast.AstElementFactory;
 import org.apache.jackrabbit.oak.query.ast.BindVariableValueImpl;
 import org.apache.jackrabbit.oak.query.ast.ColumnImpl;
@@ -98,12 +100,16 @@ public class SQL2Parser {
 
     private boolean supportSQL1;
 
+    private NamePathMapper namePathMapper;
+
     /**
      * Create a new parser. A parser can be re-used, but it is not thread safe.
      * 
+     * @param namePathMapper the name-path mapper to use
      * @param types the node with the node type information
      */
-    public SQL2Parser(NodeState types) {
+    public SQL2Parser(NamePathMapper namePathMapper, NodeState types) {
+        this.namePathMapper = namePathMapper;
         this.types = checkNotNull(types);
     }
 
@@ -206,6 +212,15 @@ public class SQL2Parser {
 
     private SelectorImpl parseSelector() throws ParseException {
         String nodeTypeName = readName();
+        if (namePathMapper != null) {
+            try {
+                nodeTypeName = namePathMapper.getOakName(nodeTypeName);
+            } catch (RepositoryException e) {
+                ParseException e2 = getSyntaxError("could not convert node type name " +
nodeTypeName);
+                e2.initCause(e);
+                throw e2;
+            }
+        }
         NodeState type = types.getChildNode(nodeTypeName);
         if (!type.exists()) {
             throw getSyntaxError("unknown node type");

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java?rev=1536602&r1=1536601&r2=1536602&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
Tue Oct 29 08:14:22 2013
@@ -35,7 +35,7 @@ public class SQL2ParserTest {
     private final NodeState types =
             INITIAL_CONTENT.getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
 
-    private final SQL2Parser p = new SQL2Parser(types);
+    private final SQL2Parser p = new SQL2Parser(null, types);
 
     @Test
     public void testIgnoreSqlComment() throws ParseException {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java?rev=1536602&r1=1536601&r2=1536602&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
Tue Oct 29 08:14:22 2013
@@ -74,11 +74,18 @@ public class QueryImpl implements Query 
         bindVariableMap.put(varName, value);
     }
 
-    private void parse() throws InvalidQueryException {
+    private void parse() throws InvalidQueryException, RepositoryException {
         if (parsed) {
             return;
         }
-        List<String> names = manager.parse(statement, language);
+        List<String> names = sessionContext.getSessionDelegate().perform(
+                new SessionOperation<List<String>>() {
+                    @Override
+                    public List<String> perform() throws RepositoryException {
+                        return manager.parse(statement, language);
+                    }
+                });
+        
         for (String n : names) {
             bindVariableMap.put(n, null);
         }

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=1536602&r1=1536601&r2=1536602&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
Tue Oct 29 08:14:22 2013
@@ -108,7 +108,7 @@ public class QueryManagerImpl implements
      */
     public List<String> parse(String statement, String language) throws InvalidQueryException
{
         try {
-            return queryEngine.getBindVariableNames(statement, language);
+            return queryEngine.getBindVariableNames(statement, language, sessionContext);
         } catch (ParseException e) {
             throw new InvalidQueryException(e);
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/RemappingTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/RemappingTest.java?rev=1536602&r1=1536601&r2=1536602&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/RemappingTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/RemappingTest.java
Tue Oct 29 08:14:22 2013
@@ -21,6 +21,7 @@ import javax.jcr.NodeIterator;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
 
@@ -96,7 +97,26 @@ public class RemappingTest extends Abstr
         assertEquals(resultPath, ni.nextNode().getPath());
     }
 
+    public void testQuery4() throws Exception {
+        String statement = 
+                "/jcr:root/myRep:security/myRep:authorizables//" + 
+                "element(*,myRep:Authorizable)[@my:property='value']";
+
+        QueryManager qm = session.getWorkspace().getQueryManager();
+        Query q = qm.createQuery(statement, "xpath");
+        
+        q.getBindVariableNames();
+
+        QueryResult qr = q.execute();
+        NodeIterator ni = qr.getNodes();
+        while (ni.hasNext()) {
+            ni.next();
+        }
+        
+    }
+
     private String createStatement(String propertyName, String value) throws RepositoryException
{
         return "/jcr:root"+ testRootNode.getPath() +"/my:node//element(*)[@"+propertyName+"='"+value+"']";
     }
+
 }
\ No newline at end of file



Mime
View raw message