jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1306221 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/query/ main/java/org/apache/jackrabbit/oak/query/ast/ main/java/org/apache/jackrabbit/oak/query/index/ test/java/org/apache/jackrabbit/oak/query/ test/jav...
Date Wed, 28 Mar 2012 09:08:24 GMT
Author: thomasm
Date: Wed Mar 28 09:08:23 2012
New Revision: 1306221

URL: http://svn.apache.org/viewvc?rev=1306221&view=rev
Log:
OAK-28 Query implementation (renaming classes/interfaces to not collide with other modules;
slightly changed API)

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/CoreValueFactory.java
      - copied, changed from r1305825, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ScalarFactory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Result.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRow.java
      - copied, changed from r1305825, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Row.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndex.java
      - copied, changed from r1305822, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/NodeReader.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
      - copied, changed from r1305822, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingReader.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Row.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ScalarFactory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/NodeReader.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingReader.java
Modified:
    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/QueryEngine.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/ast/ComparisonImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/Filter.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/CoreValueFactory.java
(from r1305825, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ScalarFactory.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/CoreValueFactory.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/CoreValueFactory.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ScalarFactory.java&r1=1305825&r2=1306221&rev=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ScalarFactory.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/CoreValueFactory.java
Wed Mar 28 09:08:23 2012
@@ -18,7 +18,7 @@ package org.apache.jackrabbit.oak.query;
 
 import java.math.BigDecimal;
 
-public class ScalarFactory {
+public class CoreValueFactory {
 
     public CoreValue createValue(String value) {
         return new CoreValue(value, CoreValue.STRING);

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=1306221&r1=1306220&r2=1306221&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 Mar 28 09:08:23 2012
@@ -63,7 +63,7 @@ public class Query {
     private long limit;
     private long offset;
     private boolean prepared;
-    private final ScalarFactory valueFactory = new ScalarFactory();
+    private final CoreValueFactory valueFactory = new CoreValueFactory();
 
     Query(SourceImpl source, ConstraintImpl constraint, OrderingImpl[] orderings,
             ColumnImpl[] columns) {
@@ -252,7 +252,7 @@ public class Query {
         this.offset = offset;
     }
 
-    public ScalarFactory getValueFactory() {
+    public CoreValueFactory getValueFactory() {
         return valueFactory;
     }
 
@@ -260,26 +260,29 @@ public class Query {
         this.explain = explain;
     }
 
-    public Iterator<Row> executeQuery(String revisionId) {
+    public Result executeQuery(String revisionId) {
         prepare();
+        Iterator<ResultRow> it;
         if (explain) {
             String plan = source.getPlan();
             columns = new ColumnImpl[] { new ColumnImpl("explain", "plan", "plan")};
-            Row r = new Row(this, new String[0], new CoreValue[] { valueFactory.createValue(plan)
}, null);
-            return Arrays.asList(r).iterator();
-        }
-        RowIterator it = new RowIterator(revisionId);
-        if (orderings == null) {
-            return it;
-        }
-        // TODO "order by" is not necessary if the used index returns rows in the same order
-        ArrayList<Row> list = new ArrayList<Row>();
-        while (it.hasNext()) {
-            Row r = it.next();
-            list.add(r);
+            ResultRow r = new ResultRow(this, new String[0], new CoreValue[] { valueFactory.createValue(plan)
}, null);
+            it = Arrays.asList(r).iterator();
+        } else {
+            it = new RowIterator(revisionId);
+            if (orderings != null) {
+                // TODO "order by" is not necessary if the used index returns
+                // rows in the same order
+                ArrayList<ResultRow> list = new ArrayList<ResultRow>();
+                while (it.hasNext()) {
+                    ResultRow r = it.next();
+                    list.add(r);
+                }
+                Collections.sort(list);
+                it = list.iterator();
+            }
         }
-        Collections.sort(list);
-        return list.iterator();
+        return new Result(this, it);
     }
 
     public int compareRows(CoreValue[] orderValues, CoreValue[] orderValues2) {
@@ -316,10 +319,10 @@ public class Query {
         source.prepare(mk);
     }
 
-    class RowIterator implements Iterator<Row> {
+    class RowIterator implements Iterator<ResultRow> {
 
         private final String revisionId;
-        private Row current;
+        private ResultRow current;
         private boolean started, end;
 
         RowIterator(String revisionId) {
@@ -360,14 +363,14 @@ public class Query {
         }
 
         @Override
-        public Row next() {
+        public ResultRow next() {
             if (end) {
                 return null;
             }
             if (current == null) {
                 fetchNext();
             }
-            Row r = current;
+            ResultRow r = current;
             current = null;
             return r;
         }
@@ -379,7 +382,7 @@ public class Query {
 
     }
 
-    Row currentRow() {
+    ResultRow currentRow() {
         int selectorCount = selectors.size();
         String[] paths = new String[selectorCount];
         for (int i = 0; i < selectorCount; i++) {
@@ -402,7 +405,7 @@ public class Query {
                 orderValues[i] = orderings[i].getOperand().currentValue();
             }
         }
-        return new Row(this, paths, values, orderValues);
+        return new ResultRow(this, paths, values, orderValues);
     }
 
     public int getSelectorIndex(String selectorName) {
@@ -444,4 +447,8 @@ public class Query {
         return Collections.unmodifiableList(selectors);
     }
 
+    public List<String> getBindVariableNames() {
+        return new ArrayList<String>(bindVariableMap.keySet());
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngine.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngine.java?rev=1306221&r1=1306220&r2=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngine.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngine.java
Wed Mar 28 09:08:23 2012
@@ -17,7 +17,7 @@
 package org.apache.jackrabbit.oak.query;
 
 import java.text.ParseException;
-import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import org.apache.jackrabbit.mk.api.MicroKernel;
@@ -28,29 +28,44 @@ public class QueryEngine {
     public static final String SQL2 = "sql2";
 
     private final MicroKernel mk;
-    private final ScalarFactory vf = new ScalarFactory();
+    private final CoreValueFactory vf = new CoreValueFactory();
     private final SQL2Parser parserSQL2;
 
-    private QueryEngine(MicroKernel mk) {
+    public QueryEngine(MicroKernel mk) {
         this.mk = mk;
         parserSQL2 = new SQL2Parser(vf);
     }
 
-    public static QueryEngine getInstance(MicroKernel mk) {
-        return new QueryEngine(mk);
+    /**
+     * Parse the query (check if it's valid) and get the list of bind variable names.
+     *
+     * @param statement
+     * @param language
+     * @return the list of bind variable names
+     * @throws ParseException
+     */
+    public List<String> parse(String statement, String language) throws ParseException
{
+        Query q = parseQuery(statement, language);
+        return q.getBindVariableNames();
+
     }
 
-    public Iterator<Row> executeQuery(String language, String query, Map<String,
CoreValue> bindings) throws ParseException {
+    private Query parseQuery(String statement, String language) throws ParseException {
         Query q;
         if (SQL2.equals(language)) {
-            q = parserSQL2.parse(query);
+            q = parserSQL2.parse(statement);
         } else if (XPATH.equals(language)) {
             XPathToSQL2Converter converter = new XPathToSQL2Converter();
-            String sql2 = converter.convert(query);
+            String sql2 = converter.convert(statement);
             q = parserSQL2.parse(sql2);
         } else {
             throw new ParseException("Unsupported language: " + language, 0);
         }
+        return q;
+    }
+
+    public Result executeQuery(String statement, String language, Map<String, CoreValue>
bindings) throws ParseException {
+        Query q = parseQuery(statement, language);
         q.setMicroKernel(mk);
         if (bindings != null) {
             for (Entry<String, CoreValue> e : bindings.entrySet()) {

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Result.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Result.java?rev=1306221&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Result.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Result.java
Wed Mar 28 09:08:23 2012
@@ -0,0 +1,59 @@
+/*
+ * 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.query;
+
+import java.util.Iterator;
+import java.util.List;
+import org.apache.jackrabbit.oak.query.ast.ColumnImpl;
+import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
+
+/**
+ * A query result.
+ */
+public class Result {
+
+    private final Query query;
+    private final Iterator<ResultRow> it;
+
+    Result(Query query, Iterator<ResultRow> it) {
+        this.query = query;
+        this.it = it;
+    }
+
+    public String[] getColumnNames() {
+        ColumnImpl[] cols = query.getColumns();
+        String[] names = new String[cols.length];
+        for (int i = 0; i < cols.length; i++) {
+            names[i] = cols[i].getColumnName();
+        }
+        return names;
+    }
+
+    public String[] getSelectorNames() {
+        List<SelectorImpl> selectors = query.getSelectors();
+        String[] names = new String[selectors.size()];
+        for (int i = 0; i < selectors.size(); i++) {
+            names[i] = selectors.get(i).getSelectorName();
+        }
+        return names;
+    }
+
+    public Iterator<ResultRow> getRows() {
+        return it;
+    }
+
+}

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRow.java
(from r1305825, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Row.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRow.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRow.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Row.java&r1=1305825&r2=1306221&rev=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Row.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ResultRow.java
Wed Mar 28 09:08:23 2012
@@ -22,14 +22,14 @@ import org.apache.jackrabbit.oak.query.a
 /**
  * A query result row that keeps all data in memory.
  */
-public class Row implements Comparable<Row> {
+public class ResultRow implements Comparable<ResultRow> {
 
     private final Query query;
     private final String[] paths;
     private final CoreValue[] values;
     private final CoreValue[] orderValues;
 
-    Row(Query query, String[] paths, CoreValue[] values, CoreValue[] orderValues) {
+    ResultRow(Query query, String[] paths, CoreValue[] values, CoreValue[] orderValues) {
         this.query = query;
         this.paths = paths;
         this.values = values;
@@ -62,7 +62,7 @@ public class Row implements Comparable<R
     }
 
     @Override
-    public int compareTo(Row o) {
+    public int compareTo(ResultRow o) {
         return query.compareRows(orderValues, o.orderValues);
     }
 

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=1306221&r1=1306220&r2=1306221&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 Mar 28 09:08:23 2012
@@ -75,14 +75,14 @@ public class SQL2Parser {
     private boolean allowNumberLiterals = true;
 
     private final AstElementFactory factory = new AstElementFactory();
-    private final ScalarFactory valueFactory;
+    private final CoreValueFactory valueFactory;
 
     /**
      * Create a new parser. A parser can be re-used, but it is not thread safe.
      *
      * @param valueFactory the value factory
      */
-    public SQL2Parser(ScalarFactory valueFactory) {
+    public SQL2Parser(CoreValueFactory valueFactory) {
         this.valueFactory = valueFactory;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java?rev=1306221&r1=1306220&r2=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/ComparisonImpl.java
Wed Mar 28 09:08:23 2012
@@ -19,7 +19,7 @@
 package org.apache.jackrabbit.oak.query.ast;
 
 import org.apache.jackrabbit.oak.query.CoreValue;
-import org.apache.jackrabbit.oak.query.ScalarFactory;
+import org.apache.jackrabbit.oak.query.CoreValueFactory;
 import org.apache.jackrabbit.oak.query.index.Filter;
 
 public class ComparisonImpl extends ConstraintImpl {
@@ -266,7 +266,7 @@ public class ComparisonImpl extends Cons
                 if (lowerBound == null && upperBound == null) {
                     // ignore
                 } else {
-                    ScalarFactory vf = query.getValueFactory();
+                    CoreValueFactory vf = query.getValueFactory();
                     if (lowerBound != null) {
                         operand1.apply(f, Operator.GREATER_OR_EQUAL, vf.createValue(lowerBound));
                     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java?rev=1306221&r1=1306220&r2=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
Wed Mar 28 09:08:23 2012
@@ -25,15 +25,15 @@ import org.apache.jackrabbit.oak.query.Q
 import org.apache.jackrabbit.oak.query.CoreValue;
 import org.apache.jackrabbit.oak.query.index.Cursor;
 import org.apache.jackrabbit.oak.query.index.Filter;
-import org.apache.jackrabbit.oak.query.index.NodeReader;
-import org.apache.jackrabbit.oak.query.index.TraversingReader;
+import org.apache.jackrabbit.oak.query.index.QueryIndex;
+import org.apache.jackrabbit.oak.query.index.TraversingIndex;
 
 public class SelectorImpl extends SourceImpl {
 
     // TODO jcr:path isn't an official feature, support it?
     private static final String PATH = "jcr:path";
 
-    protected NodeReader reader;
+    protected QueryIndex index;
 
     private final String nodeTypeName, selectorName;
     private Cursor cursor;
@@ -65,17 +65,17 @@ public class SelectorImpl extends Source
 
     @Override
     public void prepare(MicroKernel mk) {
-        reader = new TraversingReader(mk);
+        index = new TraversingIndex(mk);
     }
 
     @Override
     public void execute(String revisionId) {
-        cursor = reader.query(createFilter(), revisionId);
+        cursor = index.query(createFilter(), revisionId);
     }
 
     @Override
     public String getPlan() {
-        return  nodeTypeName + " AS " + getSelectorName() + " /* " + reader.getPlan(createFilter())
+ " */";
+        return  nodeTypeName + " AS " + getSelectorName() + " /* " + index.getPlan(createFilter())
+ " */";
     }
 
     private Filter createFilter() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/Filter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/Filter.java?rev=1306221&r1=1306220&r2=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/Filter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/Filter.java
Wed Mar 28 09:08:23 2012
@@ -26,7 +26,7 @@ import org.apache.jackrabbit.oak.query.a
 import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
 
 /**
- * An index filter / lookup condition.
+ * A filter or lookup condition.
  */
 public class Filter {
 

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndex.java
(from r1305822, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/NodeReader.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndex.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndex.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/NodeReader.java&r1=1305822&r2=1306221&rev=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/NodeReader.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/QueryIndex.java
Wed Mar 28 09:08:23 2012
@@ -19,13 +19,13 @@
 package org.apache.jackrabbit.oak.query.index;
 
 /**
- * A node reader. The reader should use the data in the filter if possible to
- * speed up reading.
+ * Represents an index. The index should use the data in the filter if possible
+ * to speed up reading.
  */
-public interface NodeReader {
+public interface QueryIndex {
 
     /**
-     * Estimate the cost to use this reader with the given filter. The returned
+     * Estimate the cost to query with the given filter. The returned
      * cost is a value between 1 (very fast; lookup of a unique node) and the
      * estimated number of nodes to traverse.
      *
@@ -35,7 +35,7 @@ public interface NodeReader {
     double getCost(Filter filter);
 
     /**
-     * Start reading nodes.
+     * Start a query.
      *
      * @param filter the filter
      * @param revisionId the revision
@@ -44,7 +44,7 @@ public interface NodeReader {
     Cursor query(Filter filter, String revisionId);
 
     /**
-     * Get the query plan for the given reader.
+     * Get the query plan for the given filter.
      *
      * @param filter the filter
      * @return the query plan

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
(from r1305822, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingReader.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingReader.java&r1=1305822&r2=1306221&rev=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingReader.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingIndex.java
Wed Mar 28 09:08:23 2012
@@ -21,12 +21,12 @@ package org.apache.jackrabbit.oak.query.
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.util.PathUtils;
 
-public class TraversingReader implements NodeReader {
+public class TraversingIndex implements QueryIndex {
 
     private final MicroKernel mk;
     private int childBlockSize = 2000;
 
-    public TraversingReader(MicroKernel mk) {
+    public TraversingIndex(MicroKernel mk) {
         this.mk = mk;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java?rev=1306221&r1=1306220&r2=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
Wed Mar 28 09:08:23 2012
@@ -43,7 +43,7 @@ public class QueryTest {
     public void setUp() {
         mk = MicroKernelFactory.getInstance("simple:/target/temp;clear");
         head = mk.getHeadRevision();
-        qe = QueryEngine.getInstance(mk);
+        qe = new QueryEngine(mk);
     }
 
     @After
@@ -65,20 +65,20 @@ public class QueryTest {
     public void bindVariableTest() throws Exception {
         head = mk.commit("/", "+ \"test\": { \"hello\": {\"id\": \"1\"}, \"world\": {\"id\":
\"2\"}}", null, null);
         HashMap<String, CoreValue> sv = new HashMap<String, CoreValue>();
-        ScalarFactory vf = new ScalarFactory();
+        CoreValueFactory vf = new CoreValueFactory();
         sv.put("id", vf.createValue("1"));
-        Iterator<Row> result;
-        result = qe.executeQuery(QueryEngine.SQL2, "select * from [nt:base] where id = $id",
sv);
+        Iterator<ResultRow> result;
+        result = qe.executeQuery("select * from [nt:base] where id = $id", QueryEngine.SQL2,
sv).getRows();
         assertTrue(result.hasNext());
         assertEquals("/test/hello", result.next().getPath());
 
         sv.put("id", vf.createValue("2"));
-        result = qe.executeQuery(QueryEngine.SQL2, "select * from [nt:base] where id = $id",
sv);
+        result = qe.executeQuery("select * from [nt:base] where id = $id", QueryEngine.SQL2,
sv).getRows();
         assertTrue(result.hasNext());
         assertEquals("/test/world", result.next().getPath());
 
 
-        qe.executeQuery(QueryEngine.SQL2, "explain select * from [nt:base] where id = 1 order
by id", null);
+        qe.executeQuery("explain select * from [nt:base] where id = 1 order by id", QueryEngine.SQL2,
null);
 
 
 
@@ -115,10 +115,10 @@ public class QueryTest {
                     }
                 } else if (line.startsWith("select") || line.startsWith("explain")) {
                     w.println(line);
-                    Iterator<Row> result = qe.executeQuery(QueryEngine.SQL2, line,
null);
+                    Iterator<ResultRow> result = qe.executeQuery(line, QueryEngine.SQL2,
null).getRows();
                     boolean readEnd = true;
                     while (result.hasNext()) {
-                        Row row = result.next();
+                        ResultRow row = result.next();
                         String resultLine = readRow(line, row);
                         w.println(resultLine);
                         if (readEnd) {
@@ -168,7 +168,7 @@ public class QueryTest {
         }
     }
 
-    private String readRow(String query, Row row) {
+    private String readRow(String query, ResultRow row) {
         StringBuilder buff = new StringBuilder();
         CoreValue[] values = row.getValues();
         for (int i = 0; i < values.length; i++) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java?rev=1306221&r1=1306220&r2=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/FilterTest.java
Wed Mar 28 09:08:23 2012
@@ -24,7 +24,7 @@ import static org.junit.Assert.fail;
 import java.util.ArrayList;
 import java.util.Random;
 import org.apache.jackrabbit.oak.query.CoreValue;
-import org.apache.jackrabbit.oak.query.ScalarFactory;
+import org.apache.jackrabbit.oak.query.CoreValueFactory;
 import org.apache.jackrabbit.oak.query.ast.Operator;
 import org.apache.jackrabbit.oak.query.index.Filter.PathRestriction;
 import org.junit.Test;
@@ -36,8 +36,8 @@ public class FilterTest {
 
     @Test
     public void propertyRestriction() {
-        CoreValue one = new ScalarFactory().createValue("1");
-        CoreValue two = new ScalarFactory().createValue("2");
+        CoreValue one = new CoreValueFactory().createValue("1");
+        CoreValue two = new CoreValueFactory().createValue("2");
 
         Filter f = new Filter(null);
         assertTrue(null == f.getPropertyRestriction("x"));

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java?rev=1306221&r1=1306220&r2=1306221&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/index/TraversingCursorTest.java
Wed Mar 28 09:08:23 2012
@@ -48,24 +48,24 @@ public class TraversingCursorTest {
 
     @Test
     public void traverse() throws Exception {
-        TraversingReader r = new TraversingReader(mk);
-        traverse(r);
+        TraversingIndex t = new TraversingIndex(mk);
+        traverse(t);
     }
 
     @Test
     public void traverseBlockwise() throws Exception {
-        TraversingReader r = new TraversingReader(mk);
-        r.setChildBlockSize(2);
-        traverse(r);
+        TraversingIndex t = new TraversingIndex(mk);
+        t.setChildBlockSize(2);
+        traverse(t);
     }
 
-    private void traverse(TraversingReader r) {
+    private void traverse(TraversingIndex t) {
         head = mk.commit("/", "+ \"parents\": { \"p0\": {\"id\": \"0\"}, \"p1\": {\"id\":
\"1\"}, \"p2\": {\"id\": \"2\"}}", head, "");
         head = mk.commit("/", "+ \"children\": { \"c1\": {\"p\": \"1\"}, \"c2\": {\"p\":
\"1\"}, \"c3\": {\"p\": \"2\"}, \"c4\": {\"p\": \"3\"}}", head, "");
         Filter f = new Filter(null);
         Cursor c;
         f.setPath("/");
-        c = r.query(f, head);
+        c = t.query(f, head);
         String[] list = {"/", "/parents", "/parents/p0", "/parents/p1",  "/parents/p2",
                 "/children", "/children/c1", "/children/c2", "/children/c3", "/children/c4"};
         for (String s : list) {
@@ -75,7 +75,7 @@ public class TraversingCursorTest {
         assertFalse(c.next());
         assertFalse(c.next());
         f.setPath("/nowhere");
-        c = r.query(f, head);
+        c = t.query(f, head);
         assertFalse(c.next());
         assertFalse(c.next());
     }



Mime
View raw message