jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1024283 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query: QueryImpl.java QueryObjectModelImpl.java lucene/join/QueryEngine.java
Date Tue, 19 Oct 2010 15:40:58 GMT
Author: jukka
Date: Tue Oct 19 15:40:58 2010
New Revision: 1024283

URL: http://svn.apache.org/viewvc?rev=1024283&view=rev
Log:
JCR-2715: Improved join query performance

Use the new join functionality for handling simple inner equi-joins.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java?rev=1024283&r1=1024282&r2=1024283&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryImpl.java
Tue Oct 19 15:40:58 2010
@@ -92,12 +92,12 @@ public class QueryImpl extends AbstractQ
     /**
      * The maximum result size
      */
-    private long limit = -1;
+    protected long limit = -1;
 
     /**
      * The offset in the total result set
      */
-    private long offset;
+    protected long offset;
 
     /**
      * @inheritDoc

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java?rev=1024283&r1=1024282&r2=1024283&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
Tue Oct 19 15:40:58 2010
@@ -16,17 +16,29 @@
  */
 package org.apache.jackrabbit.core.query;
 
+import static javax.jcr.query.qom.QueryObjectModelConstants.JCR_JOIN_TYPE_INNER;
+
+import java.util.HashMap;
+import java.util.Map;
+
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.QueryResult;
 import javax.jcr.query.qom.Column;
 import javax.jcr.query.qom.Constraint;
+import javax.jcr.query.qom.EquiJoinCondition;
+import javax.jcr.query.qom.Join;
 import javax.jcr.query.qom.Ordering;
 import javax.jcr.query.qom.QueryObjectModel;
+import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.query.qom.Source;
 
 import org.apache.jackrabbit.commons.query.QueryObjectModelBuilderRegistry;
+import org.apache.jackrabbit.core.query.lucene.join.QueryEngine;
 import org.apache.jackrabbit.core.session.SessionContext;
+import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 
 /**
@@ -39,6 +51,8 @@ public class QueryObjectModelImpl extend
      */
     protected QueryObjectModelTree qomTree;
 
+    private final Map<String, Value> variables = new HashMap<String, Value>();
+
     /**
      * {@inheritDoc}
      * @throws UnsupportedOperationException always.
@@ -77,9 +91,35 @@ public class QueryObjectModelImpl extend
         this.node = node;
         this.statement = QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(language).toString(this);
         this.query = handler.createExecutableQuery(sessionContext, qomTree);
+        for (Name name : query.getBindVariableNames()) {
+            variables.put(sessionContext.getJCRName(name), null);
+        }
         setInitialized();
     }
 
+    @Override
+    public void bindValue(String varName, Value value)
+            throws IllegalArgumentException, RepositoryException {
+        super.bindValue(varName, value);
+        variables.put(varName, value);
+    }
+
+    public QueryResult execute() throws RepositoryException {
+        Source source = getSource();
+        if (source instanceof Join) {
+            Join join = (Join) source;
+            if (JCR_JOIN_TYPE_INNER.equals(join.getJoinType())
+                    && join.getJoinCondition() instanceof EquiJoinCondition) {
+                QueryEngine engine =
+                    new QueryEngine(sessionContext.getSessionImpl(), variables);
+                return engine.execute(
+                        getColumns(), getSource(), getConstraint(),
+                        getOrderings(), offset, limit);
+            }
+        }
+        return super.execute();
+    }
+
     //-------------------------< QueryObjectModel >-----------------------------
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java?rev=1024283&r1=1024282&r2=1024283&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/join/QueryEngine.java
Tue Oct 19 15:40:58 2010
@@ -215,8 +215,10 @@ public class QueryEngine {
             }
             rightRows = new RowIteratorAdapter(list);
         }
-        return merger.merge(
+
+        QueryResult result = merger.merge(
                 new RowIteratorAdapter(leftRows), rightRows, offset, limit);
+        return sort(result, orderings);
     }
 
     private String toSqlConstraint(Constraint constraint)



Mime
View raw message