jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1383433 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/query/ test/java/org/apache/jackrabbit/oak/jcr/query/
Date Tue, 11 Sep 2012 14:35:49 GMT
Author: thomasm
Date: Tue Sep 11 14:35:48 2012
New Revision: 1383433

URL: http://svn.apache.org/viewvc?rev=1383433&view=rev
Log:
OAK-28 Query implementation: improved XPath compatibility

Modified:
    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/query/QueryResultImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java

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=1383433&r1=1383432&r2=1383433&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 Sep 11 14:35:48 2012
@@ -92,6 +92,13 @@ public class QueryManagerImpl implements
         return list.toArray(new String[list.size()]);
     }
 
+    /**
+     * Parse the query and get the bind variable names.
+     * 
+     * @param statement the query statement
+     * @param language the query language
+     * @return the bind variable names
+     */
     public List<String> parse(String statement, String language) throws InvalidQueryException
{
         try {
             return queryEngine.getBindVariableNames(statement, language);
@@ -122,7 +129,7 @@ public class QueryManagerImpl implements
         return map;
     }
 
-    SessionDelegate getSessionDelegate() {
+    public SessionDelegate getSessionDelegate() {
         return sessionDelegate;
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java?rev=1383433&r1=1383432&r2=1383433&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryResultImpl.java
Tue Sep 11 14:35:48 2012
@@ -18,29 +18,26 @@
  */
 package org.apache.jackrabbit.oak.jcr.query;
 
-import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
-import static org.apache.jackrabbit.oak.commons.PathUtils.isAncestor;
-import static org.apache.jackrabbit.oak.commons.PathUtils.relativize;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import javax.annotation.CheckForNull;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.RowIterator;
 
 import org.apache.jackrabbit.commons.iterator.NodeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.RowIteratorAdapter;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.ResultRow;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.NodeImpl;
 import org.apache.jackrabbit.oak.jcr.SessionDelegate;
 
-import javax.annotation.CheckForNull;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Value;
-import javax.jcr.query.QueryResult;
-import javax.jcr.query.RowIterator;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
 /**
  * The implementation of the corresponding JCR interface.
  */
@@ -74,7 +71,7 @@ public class QueryResultImpl implements 
             // a row without path (explain,...)
             return true;
         }
-        if (isAncestor(pathFilter, path) || pathFilter.equals(path)) {
+        if (PathUtils.isAncestor(pathFilter, path) || pathFilter.equals(path)) {
             // a row within this workspace
             return true;
         }
@@ -141,14 +138,20 @@ public class QueryResultImpl implements 
     }
 
     String getLocalPath(String path) {
-        return concat("/", relativize(pathFilter, path));
+        return PathUtils.concat("/", PathUtils.relativize(pathFilter, path));
     }
 
     @Override
     public NodeIterator getNodes() throws RepositoryException {
+        String[] selectorNames = getSelectorNames();
+        final String selectorName = selectorNames[0];
         if (getSelectorNames().length > 1) {
-            throw new RepositoryException("Query contains more than one selector: " +
-                    Arrays.toString(getSelectorNames()));
+            // use the first selector
+            // TODO verify using the first selector is allowed according to the specification,
+            // otherwise just allow it when using XPath queries, or make XPath queries
+            // look like they only contain one selector
+            // throw new RepositoryException("Query contains more than one selector: " +
+            //        Arrays.toString(getSelectorNames()));
         }
         Iterator<NodeImpl> nodeIterator = new Iterator<NodeImpl>() {
 
@@ -163,7 +166,7 @@ public class QueryResultImpl implements 
                 current = null;
                 while (it.hasNext()) {
                     ResultRow r = it.next();
-                    String path = r.getPath();
+                    String path = r.getPath(selectorName);
                     if (includeRow(path)) {
                         current = getNode(getLocalPath(path));
                         break;

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java?rev=1383433&r1=1383432&r2=1383433&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/query/QueryTest.java
Tue Sep 11 14:35:48 2012
@@ -62,6 +62,9 @@ public class QueryTest extends AbstractR
         assertTrue(it.hasNext());
         Row row = it.nextRow();
         assertEquals("hello world", row.getValue("text").getString());
+        String[] columns = r.getColumnNames();
+        assertEquals(1, columns.length);
+        assertEquals("text", columns[0]);
         assertFalse(it.hasNext());
 
         r = q.execute();
@@ -74,12 +77,22 @@ public class QueryTest extends AbstractR
         // SQL
 
         q = qm.createQuery("select text from [nt:base] where id = 1", Query.SQL);
-        q.execute();
+        r = q.execute();
+        columns = r.getColumnNames();
+        assertEquals(3, columns.length);
+        assertEquals("text", columns[0]);
+        assertEquals("jcr:path", columns[1]);
+        assertEquals("jcr:score", columns[2]);
 
         // XPath
 
         q = qm.createQuery("//*[@id=1]", Query.XPATH);
-        q.execute();
+        r = q.execute();
+        columns = r.getColumnNames();
+        assertEquals(3, columns.length);
+        assertEquals("jcr:path", columns[0]);
+        assertEquals("jcr:score", columns[1]);
+        assertEquals("*", columns[2]);
     }
 
     @Test



Mime
View raw message