jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r632309 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-spi-...
Date Fri, 29 Feb 2008 13:01:44 GMT
Author: mreutegg
Date: Fri Feb 29 05:01:42 2008
New Revision: 632309

URL: http://svn.apache.org/viewvc?rev=632309&view=rev
Log:
JCR-1104: JSR 283 support
- support for prepared queries has been moved to existing Query interface
- removed PreparedQuery again

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
  (with props)
Removed:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExecutablePreparedQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PreparedQueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/PreparedQueryImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/jsr283/PreparedQuery.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExecutableQuery.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
    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/QueryManagerImpl.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/AbstractQueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/jsr283/qom/QueryObjectModel.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Fri Feb 29 05:01:42 2008
@@ -26,14 +26,12 @@
 import org.apache.jackrabbit.core.query.QueryHandler;
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
 import org.apache.jackrabbit.core.query.QueryImpl;
-import org.apache.jackrabbit.core.query.PreparedQueryImpl;
 import org.apache.jackrabbit.core.query.QueryObjectModelImpl;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.NodeStateIterator;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
-import org.apache.jackrabbit.spi.commons.query.jsr283.PreparedQuery;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModel;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
 import org.apache.jackrabbit.spi.Path;
@@ -92,12 +90,6 @@
     private static final String PARAM_QUERY_IMPL = "queryClass";
 
     /**
-     * Name of the parameter that indicates the prepared query implementation
-     * class.
-     */
-    private static final String PARAM_PREPARED_QUERY_IMPL = "preparedQueryClass";
-
-    /**
      * Name of the parameter that specifies the idle time for a query handler.
      */
     private static final String PARAM_IDLE_TIME = "idleTime";
@@ -108,11 +100,6 @@
     private static final String DEFAULT_QUERY_IMPL_CLASS = QueryImpl.class.getName();
 
     /**
-     * Name of the default prepared query implementation class.
-     */
-    private static final String DEFAULT_PREPARED_QUERY_IMPL_CLASS = PreparedQueryImpl.class.getName();
-
-    /**
      * The search configuration.
      */
     private final SearchConfig config;
@@ -171,13 +158,6 @@
     private final String queryImplClassName;
 
     /**
-     * Fully qualified name of the prepared query implementation class.
-     * This class must extend {@link org.apache.jackrabbit.core.query.AbstractQueryImpl}
-     * and implement {@link PreparedQuery}!
-     */
-    private final String preparedQueryImplClassName;
-
-    /**
      * Creates a new <code>SearchManager</code>.
      *
      * @param config the search configuration.
@@ -237,7 +217,6 @@
 
         Properties params = config.getParameters();
         queryImplClassName = params.getProperty(PARAM_QUERY_IMPL, DEFAULT_QUERY_IMPL_CLASS);
-        preparedQueryImplClassName = params.getProperty(PARAM_PREPARED_QUERY_IMPL, DEFAULT_PREPARED_QUERY_IMPL_CLASS);
         if (params.containsKey(PARAM_IDLE_TIME)) {
             String msg = "Parameter 'idleTime' is not supported anymore. "
                 + "Please use 'maxIdleTime' in the repository configuration.";
@@ -296,29 +275,6 @@
     }
 
     /**
-     * Creates a prepared query object that can be executed on the workspace.
-     *
-     * @param session   the session of the user executing the query.
-     * @param itemMgr   the item manager of the user executing the query. Needed
-     *                  to return <code>Node</code> instances in the result set.
-     * @param statement the actual query statement.
-     * @param language  the syntax of the query statement.
-     * @return a <code>Query</code> instance to execute.
-     * @throws InvalidQueryException if the query is malformed or the
-     *                               <code>language</code> is unknown.
-     * @throws RepositoryException   if any other error occurs.
-     */
-    public PreparedQuery createPreparedQuery(SessionImpl session,
-                                             ItemManager itemMgr,
-                                             String statement,
-                                             String language)
-            throws InvalidQueryException, RepositoryException {
-        AbstractQueryImpl query = createPreparedQueryInstance();
-        query.init(session, itemMgr, handler, statement, language);
-        return (PreparedQuery) query;
-    }
-
-    /**
      * Creates a query object model that can be executed on the workspace.
      *
      * @param session   the session of the user executing the query.
@@ -525,33 +481,6 @@
             }
         } catch (Throwable t) {
             throw new RepositoryException("Unable to create query: " + t.toString());
-        }
-    }
-
-    /**
-     * Creates a new instance of an {@link AbstractQueryImpl}, which also
-     * implements {@link PreparedQuery} and is not initialized.
-     *
-     * @return an new query instance.
-     * @throws RepositoryException if an error occurs while creating a new query
-     *                             instance.
-     */
-    protected AbstractQueryImpl createPreparedQueryInstance()
-            throws RepositoryException {
-        try {
-            Object obj = Class.forName(preparedQueryImplClassName).newInstance();
-            if (!(obj instanceof AbstractQueryImpl)) {
-                throw new IllegalArgumentException(preparedQueryImplClassName
-                        + " is not of type " + AbstractQueryImpl.class.getName());
-            } else if (!(obj instanceof PreparedQuery)) {
-                throw new IllegalArgumentException(preparedQueryImplClassName
-                        + " is not of type " + PreparedQuery.class.getName());
-            } else {
-                return (AbstractQueryImpl) obj;
-            }
-        } catch (Throwable t) {
-            throw new RepositoryException("Unable to create prepared query: "
-                    + t.toString(), t);
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/AbstractQueryHandler.java
Fri Feb 29 05:01:42 2008
@@ -83,17 +83,4 @@
             addNode(add.nextNodeState());
         }
     }
-
-    /**
-     * {@inheritDoc}
-     * <p/>
-     * Throws {@link UnsupportedOperationException}.
-     */
-    public ExecutablePreparedQuery createExecutablePreparedQuery(
-            SessionImpl session,
-            ItemManager itemMgr,
-            QueryObjectModelTree qomTree) throws InvalidQueryException {
-        throw new UnsupportedOperationException(
-                "This query handler does not support prepared queries");
-    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExecutableQuery.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExecutableQuery.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExecutableQuery.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExecutableQuery.java
Fri Feb 29 05:01:42 2008
@@ -16,7 +16,10 @@
  */
 package org.apache.jackrabbit.core.query;
 
+import org.apache.jackrabbit.spi.Name;
+
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.query.QueryResult;
 
 /**
@@ -35,4 +38,17 @@
      * @throws RepositoryException if an error occurs
      */
     QueryResult execute(long offset, long limit) throws RepositoryException;
+
+    /**
+     * Binds the given <code>value</code> to the variable named
+     * <code>varName</code>.
+     *
+     * @param varName name of variable in query
+     * @param value   value to bind
+     * @throws IllegalArgumentException      if <code>varName</code> is not a
+     *                                       valid variable in this query.
+     * @throws javax.jcr.RepositoryException if an error occurs.
+     */
+    void bindValue(Name varName, Value value)
+        throws IllegalArgumentException, RepositoryException;
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryHandler.java
Fri Feb 29 05:01:42 2008
@@ -105,9 +105,10 @@
      * @return A <code>Query</code> object.
      */
     ExecutableQuery createExecutableQuery(SessionImpl session,
-                             ItemManager itemMgr,
-                             String statement,
-                             String language) throws InvalidQueryException;
+                                          ItemManager itemMgr,
+                                          String statement,
+                                          String language)
+            throws InvalidQueryException;
 
     /**
      * Creates a new query by specifying the query object model. If the query
@@ -121,8 +122,8 @@
      * @return A <code>Query</code> object.
      * @throws InvalidQueryException if the query object model tree is invalid.
      */
-    ExecutablePreparedQuery createExecutablePreparedQuery(
-            SessionImpl session,
-            ItemManager itemMgr,
-            QueryObjectModelTree qomTree) throws InvalidQueryException;
+    ExecutableQuery createExecutableQuery(SessionImpl session,
+                                          ItemManager itemMgr,
+                                          QueryObjectModelTree qomTree)
+            throws InvalidQueryException;
 }

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=632309&r1=632308&r2=632309&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
Fri Feb 29 05:01:42 2008
@@ -29,6 +29,7 @@
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.Value;
 import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.query.InvalidQueryException;
@@ -242,6 +243,26 @@
             return node;
         } catch (NameException e) {
             throw new RepositoryException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Binds the given <code>value</code> to the variable named
+     * <code>varName</code>.
+     *
+     * @param varName name of variable in query
+     * @param value   value to bind
+     * @throws IllegalArgumentException      if <code>varName</code> is not a
+     *                                       valid variable in this query.
+     * @throws javax.jcr.RepositoryException if an error occurs.
+     */
+    public void bindValue(String varName, Value value)
+            throws IllegalArgumentException, RepositoryException {
+        checkInitialized();
+        try {
+            query.bindValue(session.getQName(varName), value);
+        } catch (NameException e) {
+            throw new RepositoryException(e.getMessage());
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryManagerImpl.java
Fri Feb 29 05:01:42 2008
@@ -22,7 +22,6 @@
 import org.apache.jackrabbit.spi.commons.query.QueryTreeBuilderRegistry;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelFactoryImpl;
 import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
-import org.apache.jackrabbit.spi.commons.query.jsr283.PreparedQuery;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModelFactory;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModel;
 
@@ -120,30 +119,6 @@
     }
 
     //---------------------------< JSR 283 >------------------------------------
-
-    /**
-     * Creates a new prepared query by specifying the query
-     * <code>statement</code> itself and the <code>language</code>
in which the
-     * query is stated. If the query statement is syntactically invalid, given
-     * the language specified, an <code>InvalidQueryException</code> is thrown.
-     * The language parameter must be a string from among those returned by
-     * <code>QueryManager.getSupportedQueryLanguages()</code>; if it is not,
-     * then an <code>InvalidQueryException</code> is thrown.
-     *
-     * @param statement a <code>String</code>
-     * @param language  a <code>String</code>
-     * @return a <code>PreparedQuery</code> object
-     * @throws InvalidQueryException if the query statement is syntactically
-     *                               invalid or the specified language is not
-     *                               supported
-     * @throws RepositoryException   if another error occurs
-     * @since JCR 2.0
-     */
-    public PreparedQuery createPreparedQuery(String statement, String language)
-            throws InvalidQueryException, RepositoryException {
-        sanityCheck();
-        return searchMgr.createPreparedQuery(session, itemMgr, statement, language);
-    }
 
     /**
      * Returns a <code>QueryObjectModelFactory</code> with which a JCR-JQOM

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=632309&r1=632308&r2=632309&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
Fri Feb 29 05:01:42 2008
@@ -21,13 +21,84 @@
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.Ordering;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.Constraint;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.Column;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.ItemManager;
+
+import javax.jcr.query.InvalidQueryException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
 
 /**
  * <code>QueryObjectModelImpl</code>...
  */
-public class QueryObjectModelImpl
-        extends PreparedQueryImpl
-        implements QueryObjectModel {
+public class QueryObjectModelImpl extends QueryImpl implements QueryObjectModel {
+
+    /**
+     * The query object model tree.
+     */
+    protected QueryObjectModelTree qomTree;
+
+    /**
+     * @inheritDoc
+     */
+    public void init(SessionImpl session,
+                     ItemManager itemMgr,
+                     QueryHandler handler,
+                     String statement,
+                     String language) throws InvalidQueryException {
+        checkNotInitialized();
+        this.session = session;
+        this.language = language;
+        this.handler = handler;
+        this.statement = statement;
+        this.query = handler.createExecutableQuery(session, itemMgr,
+                createQOMTree(statement, language));
+        setInitialized();
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public void init(SessionImpl session,
+                     ItemManager itemMgr,
+                     QueryHandler handler,
+                     Node node) throws InvalidQueryException, RepositoryException {
+        checkNotInitialized();
+        this.session = session;
+        this.node = node;
+        this.handler = handler;
+
+        if (!node.isNodeType(session.getJCRName(NameConstants.NT_QUERY))) {
+            throw new InvalidQueryException("node is not of type nt:query");
+        }
+        this.statement = node.getProperty(session.getJCRName(NameConstants.JCR_STATEMENT)).getString();
+        this.language = node.getProperty(session.getJCRName(NameConstants.JCR_LANGUAGE)).getString();
+        this.query = handler.createExecutableQuery(session, itemMgr,
+                createQOMTree(statement, language));
+        setInitialized();
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public void init(SessionImpl session,
+                     ItemManager itemMgr,
+                     QueryHandler handler,
+                     QueryObjectModelTree qomTree,
+                     String language)
+            throws InvalidQueryException, RepositoryException {
+        checkNotInitialized();
+        this.session = session;
+        this.language = language;
+        this.handler = handler;
+        this.qomTree = qomTree;
+        this.statement = null; // TODO: format qomTree into a SQL2 statement
+        this.query = handler.createExecutableQuery(session, itemMgr, qomTree);
+        setInitialized();
+    }
+
 
     //-------------------------< QueryObjectModel >-----------------------------
 
@@ -65,5 +136,23 @@
      */
     public Column[] getColumns() {
         return qomTree.getColumns();
+    }
+
+    //------------------------------< internal >--------------------------------
+
+    /**
+     * Creates a {@link QueryObjectModelTree} representation for the query
+     * <code>statement</code>.
+     *
+     * @param statement the query statement.
+     * @param language  the language of the query statement.
+     * @return the {@link QueryObjectModelTree} representation.
+     * @throws InvalidQueryException if the query statement is malformed.
+     */
+    private QueryObjectModelTree createQOMTree(String statement,
+                                               String language)
+            throws InvalidQueryException {
+        // TODO: implement
+        return null;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java
Fri Feb 29 05:01:42 2008
@@ -20,6 +20,15 @@
 import org.apache.jackrabbit.core.query.PropertyTypeRegistry;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.ItemManager;
+import org.apache.jackrabbit.spi.Name;
+
+import javax.jcr.Value;
+import javax.jcr.RepositoryException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collections;
 
 /**
  * <code>AbstractQueryImpl</code> provides a base class for executable queries
@@ -54,6 +63,17 @@
     private boolean documentOrder = true;
 
     /**
+     * Set&lt;Name>, where Name is a variable name in the query statement.
+     */
+    private final Set variableNames = new HashSet();
+
+    /**
+     * Binding of variable name to value. Maps {@link Name} to {@link Value}.
+     */
+    private final Map bindValues = new HashMap();
+
+
+    /**
      * Creates a new query instance from a query string.
      *
      * @param session the session of the user executing this query.
@@ -96,6 +116,42 @@
      */
     public void setRespectDocumentOrder(boolean documentOrder) {
         this.documentOrder = documentOrder;
+    }
+
+    /**
+     * Binds the given <code>value</code> to the variable named
+     * <code>varName</code>.
+     *
+     * @param varName name of variable in query
+     * @param value   value to bind
+     * @throws IllegalArgumentException if <code>varName</code> is not a valid
+     *                                  variable in this query.
+     * @throws RepositoryException      if an error occurs.
+     */
+    public void bindValue(Name varName, Value value)
+            throws IllegalArgumentException, RepositoryException {
+        if (!variableNames.contains(varName)) {
+            throw new IllegalArgumentException("not a valid variable in this query");
+        } else {
+            bindValues.put(varName, value);
+        }
+    }
+
+    /**
+     * Adds a name to the set of variables.
+     *
+     * @param varName the name of the variable.
+     */
+    protected void addVariableName(Name varName) {
+        variableNames.add(varName);
+    }
+
+    /**
+     * @return an unmodifieable map, which contains the variable names and their
+     *         respective value.
+     */
+    protected Map getBindVariableValues() {
+        return Collections.unmodifiableMap(bindValues);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/JQOM2LuceneQueryBuilder.java
Fri Feb 29 05:01:42 2008
@@ -555,6 +555,7 @@
 
     public Object visit(PropertyExistenceImpl node, Object data) throws Exception {
         String propName = npResolver.getJCRName(node.getPropertyQName());
+        // TODO respect index version
         return new MatchAllQuery(propName);
     }
 

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java?rev=632309&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
Fri Feb 29 05:01:42 2008
@@ -0,0 +1,129 @@
+/*
+ * 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.core.query.lucene;
+
+import org.apache.jackrabbit.core.query.PropertyTypeRegistry;
+import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModelConstants;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
+import org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.OrderingImpl;
+import org.apache.jackrabbit.spi.commons.query.qom.DefaultTraversingQOMTreeVisitor;
+import org.apache.jackrabbit.spi.commons.query.qom.BindVariableValueImpl;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.ItemManager;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.lucene.search.Query;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.query.QueryResult;
+
+/**
+ * <code>QueryObjectModelImpl</code>...
+ */
+public class QueryObjectModelImpl extends AbstractQueryImpl {
+
+    /**
+     * The query object model tree.
+     */
+    private final QueryObjectModelTree qomTree;
+
+    /**
+     * Creates a new query instance from a query string.
+     *
+     * @param session the session of the user executing this query.
+     * @param itemMgr the item manager of the session executing this query.
+     * @param index   the search index.
+     * @param propReg the property type registry.
+     * @param qomTree the query object model tree.
+     */
+    public QueryObjectModelImpl(SessionImpl session,
+                                ItemManager itemMgr,
+                                SearchIndex index,
+                                PropertyTypeRegistry propReg,
+                                QueryObjectModelTree qomTree) {
+        super(session, itemMgr, index, propReg);
+        this.qomTree = qomTree;
+        extractBindVariableNames();
+    }
+
+    /**
+     * Returns <code>true</code> if this query node needs items under
+     * /jcr:system to be queried.
+     *
+     * @return <code>true</code> if this query node needs content under
+     *         /jcr:system to be queried; <code>false</code> otherwise.
+     */
+    public boolean needsSystemTree() {
+        // TODO: analyze QOM tree
+        return true;
+    }
+
+    //-------------------------< ExecutableQuery >------------------------------
+
+    /**
+     * Executes this query and returns a <code>{@link javax.jcr.query.QueryResult}</code>.
+     *
+     * @param offset the offset in the total result set
+     * @param limit  the maximum result size
+     * @return a <code>QueryResult</code>
+     * @throws RepositoryException if an error occurs
+     */
+    public QueryResult execute(long offset, long limit)
+            throws RepositoryException {
+        Query query = JQOM2LuceneQueryBuilder.createQuery(qomTree, session,
+                index.getContext().getItemStateManager(),
+                index.getNamespaceMappings(), index.getTextAnalyzer(),
+                propReg, index.getSynonymProvider(), getBindVariableValues());
+
+        ColumnImpl[] columns = qomTree.getColumns();
+        Name[] selectProps = new Name[columns.length];
+        for (int i = 0; i < columns.length; i++) {
+            selectProps[i] = columns[i].getPropertyQName();
+        }
+        OrderingImpl[] orderings = qomTree.getOrderings();
+        // TODO: there are many kinds of DynamicOperand that can be ordered by
+        Name[] orderProps = new Name[orderings.length];
+        boolean[] orderSpecs = new boolean[orderings.length];
+        for (int i = 0; i < orderings.length; i++) {
+            orderSpecs[i] = orderings[i].getOrder() == QueryObjectModelConstants.ORDER_ASCENDING;
+        }
+        return new QueryResultImpl(index, itemMgr,
+                session, session.getAccessManager(),
+                // TODO: spell suggestion missing
+                this, query, null, selectProps, orderProps, orderSpecs,
+                getRespectDocumentOrder(), offset, limit);
+    }
+
+    //--------------------------< internal >------------------------------------
+
+    /**
+     * Extracts all {@link BindVariableValueImpl} from the {@link #qomTree}
+     * and adds it to the set of known variable names.
+     */
+    private void extractBindVariableNames() {
+        try {
+            qomTree.accept(new DefaultTraversingQOMTreeVisitor() {
+                public Object visit(BindVariableValueImpl node, Object data) {
+                    addVariableName(node.getBindVariableQName());
+                    return data;
+                }
+            }, null);
+        } catch (Exception e) {
+            // will never happen
+        }
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Fri Feb 29 05:01:42 2008
@@ -25,7 +25,6 @@
 import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
 import org.apache.jackrabbit.core.query.AbstractQueryHandler;
-import org.apache.jackrabbit.core.query.ExecutablePreparedQuery;
 import org.apache.jackrabbit.core.query.ExecutableQuery;
 import org.apache.jackrabbit.core.query.QueryHandler;
 import org.apache.jackrabbit.core.query.QueryHandlerContext;
@@ -589,13 +588,13 @@
      * @return A <code>Query</code> object.
      * @throws javax.jcr.query.InvalidQueryException
      *          if the query object model tree is invalid.
-     * @see QueryHandler#createExecutablePreparedQuery(SessionImpl, ItemManager, QueryObjectModelTree)
+     * @see QueryHandler#createExecutableQuery(SessionImpl, ItemManager, QueryObjectModelTree)
      */
-    public ExecutablePreparedQuery createExecutablePreparedQuery(
+    public ExecutableQuery createExecutableQuery(
             SessionImpl session,
             ItemManager itemMgr,
             QueryObjectModelTree qomTree) throws InvalidQueryException {
-        PreparedQueryImpl query = new PreparedQueryImpl(session, itemMgr, this,
+        QueryObjectModelImpl query = new QueryObjectModelImpl(session, itemMgr, this,
                 getContext().getPropertyTypeRegistry(), qomTree);
         query.setRespectDocumentOrder(documentOrder);
         return query;

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/jsr283/qom/QueryObjectModel.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/jsr283/qom/QueryObjectModel.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/jsr283/qom/QueryObjectModel.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/jsr283/qom/QueryObjectModel.java
Fri Feb 29 05:01:42 2008
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.spi.commons.query.jsr283.qom;
 
-import org.apache.jackrabbit.spi.commons.query.jsr283.PreparedQuery;
+import javax.jcr.query.Query;
 
 /**
  * A query in the JCR query object model.
@@ -55,7 +55,7 @@
  *
  * @since JCR 2.0
  */
-public interface QueryObjectModel extends PreparedQuery {
+public interface QueryObjectModel extends Query {
 
     /**
      * Gets the node-tuple source for this query.

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java?rev=632309&r1=632308&r2=632309&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
Fri Feb 29 05:01:42 2008
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.spi.commons.query.sql2;
 
-import org.apache.jackrabbit.spi.commons.query.jsr283.PreparedQuery;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.BindVariableValue;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.Column;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.Constraint;
@@ -31,6 +30,7 @@
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.Selector;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.Source;
 import org.apache.jackrabbit.spi.commons.query.jsr283.qom.StaticOperand;
+import org.apache.jackrabbit.spi.commons.query.jsr283.qom.QueryObjectModel;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -43,7 +43,7 @@
 import javax.jcr.query.InvalidQueryException;
 
 /**
- * The SQL2 parser can convert a JCR-SQL2 query to a PreparedQuery.
+ * The SQL2 parser can convert a JCR-SQL2 query to a QueryObjectModel.
  */
 public class Parser {
 
@@ -93,14 +93,14 @@
     }
 
     /**
-     * Parse a JCR-SQL2 query and return the prepared query.
+     * Parse a JCR-SQL2 query and return the query object model
      *
      * @param query the query string
-     * @return the prepared query
+     * @return the query object model
      * @throws RepositoryException if parsing failed
      */
     // Page 125
-    public PreparedQuery createPreparedQuery(String query) throws RepositoryException {
+    public QueryObjectModel createQueryObjectModel(String query) throws RepositoryException
{
         initialize(query);
         selectors = new ArrayList();
         expected = new ArrayList();



Mime
View raw message