jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r789324 - in /jackrabbit/trunk: jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/ jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/ ja...
Date Mon, 29 Jun 2009 13:46:31 GMT
Author: mreutegg
Date: Mon Jun 29 13:46:30 2009
New Revision: 789324

URL: http://svn.apache.org/viewvc?rev=789324&view=rev
Log:
JCR-2175: Return bind variable names on RepositoryService.checkQueryStatement()

Modified:
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?rev=789324&r1=789323&r2=789324&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Mon Jun 29 13:46:30 2009
@@ -294,15 +294,16 @@
      * @param language   the query language.
      * @param namespaces the locally remapped namespaces which might be used in
      *                   the query statement.
+     * @return the bind variable names.
      * @throws InvalidQueryException if the query statement is invalid.
      * @throws RepositoryException   if an error occurs while checking the query
      *                               statement.
      */
-    public void checkQueryStatement(String statement,
-                                    String language,
-                                    Map namespaces)
+    public String[] checkQueryStatement(String statement,
+                                        String language,
+                                        Map namespaces)
             throws InvalidQueryException, RepositoryException {
-        service.checkQueryStatement(sessionInfo, statement, language, namespaces);
+        return service.checkQueryStatement(sessionInfo, statement, language, namespaces);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java?rev=789324&r1=789323&r2=789324&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
Mon Jun 29 13:46:30 2009
@@ -18,6 +18,8 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Arrays;
+import java.util.Collection;
 
 import javax.jcr.ItemExistsException;
 import javax.jcr.ItemNotFoundException;
@@ -102,6 +104,12 @@
     private final Map<String, QValue> boundValues = new HashMap<String, QValue>();
 
     /**
+     * The names of the bind variables as returned by the SPI implementation
+     * after checking the query statement.
+     */
+    private final Collection<String> varNames;
+
+    /**
      * Creates a new query.
      *
      * @param session     the session that created this query.
@@ -129,7 +137,8 @@
         this.statement = statement;
         this.language = language;
         this.wspManager = wspManager;
-        this.wspManager.checkQueryStatement(statement, language, getNamespaceMappings());
+        this.varNames = Arrays.asList(this.wspManager.checkQueryStatement(
+                statement, language, getNamespaceMappings()));
         this.node = node;
     }
 
@@ -215,6 +224,9 @@
      * @see Query#bindValue(String, Value)
      */
     public void bindValue(String varName, Value value) throws RepositoryException {
+        if (!varNames.contains(varName)) {
+            throw new IllegalArgumentException(varName + " is not a known bind variable name
in this query");
+        }
         if (value == null) {
             boundValues.remove(varName);
         } else {

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java?rev=789324&r1=789323&r2=789324&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/AbstractReadableRepositoryService.java
Mon Jun 29 13:46:30 2009
@@ -774,7 +774,7 @@
         return new String[0];
     }
 
-    public void checkQueryStatement(SessionInfo sessionInfo, String statement,
+    public String[] checkQueryStatement(SessionInfo sessionInfo, String statement,
                                     String language, Map namespaces) throws
             InvalidQueryException, RepositoryException {
         throw new UnsupportedRepositoryOperationException();

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java?rev=789324&r1=789323&r2=789324&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/logging/RepositoryServiceLogger.java
Mon Jun 29 13:46:30 2009
@@ -542,13 +542,12 @@
         }, "getSupportedQueryLanguages(SessionInfo)", new Object[]{unwrap(sessionInfo)});
     }
 
-    public void checkQueryStatement(final SessionInfo sessionInfo, final String statement,
+    public String[] checkQueryStatement(final SessionInfo sessionInfo, final String statement,
             final String language, final Map<String, String> namespaces) throws RepositoryException
{
 
-        execute(new Callable() {
+        return (String[]) execute(new Callable() {
             public Object call() throws RepositoryException {
-                service.checkQueryStatement(unwrap(sessionInfo), statement, language, namespaces);
-                return null;
+                return service.checkQueryStatement(unwrap(sessionInfo), statement, language,
namespaces);
             }
         }, "checkQueryStatement(SessionInfo, String, String, Map)",
                 new Object[]{unwrap(sessionInfo), statement, language, namespaces});

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?rev=789324&r1=789323&r2=789324&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
Mon Jun 29 13:46:30 2009
@@ -868,20 +868,22 @@
 
     /**
      * Checks if the query <code>statement</code> is valid according to the
-     * specified query <code>language</code>.
+     * specified query <code>language</code> and returns the bind variable
+     * names found in the query statement.
      *
      * @param sessionInfo the session info.
      * @param statement   the query statement to check.
      * @param language    the query language.
      * @param namespaces  the locally re-mapped namespace which may be used in
      *                    the query <code>statement</code>.
+     * @return the bind variable names.
      * @throws InvalidQueryException if the query statement is invalid or the
      *                               language is not supported.
      * @throws RepositoryException   if an error occurs while checking the
      *                               statement.
      * @see javax.jcr.query.QueryManager#createQuery(String, String)
      */
-    public void checkQueryStatement(SessionInfo sessionInfo, String statement, String language,
Map<String, String> namespaces) throws InvalidQueryException, RepositoryException;
+    public String[] checkQueryStatement(SessionInfo sessionInfo, String statement, String
language, Map<String, String> namespaces) throws InvalidQueryException, RepositoryException;
 
     /**
      * Execute the given query statement with the specified query language. The

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?rev=789324&r1=789323&r2=789324&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Mon Jun 29 13:46:30 2009
@@ -1667,12 +1667,13 @@
         }
     }
 
-    public void checkQueryStatement(SessionInfo sessionInfo,
+    public String[] checkQueryStatement(SessionInfo sessionInfo,
                                     String statement,
                                     String language,
                                     Map namespaces)
             throws InvalidQueryException, RepositoryException {
         // TODO implement
+        return new String[0];
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml?rev=789324&r1=789323&r2=789324&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml Mon Jun 29 13:46:30 2009
@@ -70,7 +70,6 @@
                 org.apache.jackrabbit.jcr2spi.name.NamespaceRegistryTest#testReRegisteredNamespaceVisibility
                 org.apache.jackrabbit.jcr2spi.name.NamespaceRegistryTest#testRegisteredNamespaceVisibility
                 org.apache.jackrabbit.test.api.observation.EventJournalTest
-                org.apache.jackrabbit.test.api.query.qom.BindVariableValueTest#testIllegalArgumentException
                 org.apache.jackrabbit.test.api.ShareableNodeTest
                 org.apache.jackrabbit.test.api.version.simple
               </value>

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java?rev=789324&r1=789323&r2=789324&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java
Mon Jun 29 13:46:30 2009
@@ -86,6 +86,13 @@
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.Query;
+import javax.jcr.query.qom.Constraint;
+import javax.jcr.query.qom.And;
+import javax.jcr.query.qom.Or;
+import javax.jcr.query.qom.Not;
+import javax.jcr.query.qom.Comparison;
+import javax.jcr.query.qom.BindVariableValue;
+import javax.jcr.query.qom.QueryObjectModel;
 import javax.jcr.lock.LockException;
 import javax.jcr.lock.Lock;
 import javax.jcr.version.VersionException;
@@ -1017,13 +1024,14 @@
     /**
      * {@inheritDoc}
      */
-    public void checkQueryStatement(SessionInfo sessionInfo,
+    public String[] checkQueryStatement(SessionInfo sessionInfo,
                                     String statement,
                                     String language,
                                     Map namespaces)
             throws InvalidQueryException, RepositoryException {
-        createQuery(getSessionInfoImpl(sessionInfo).getSession(), statement,
-                language, namespaces);
+        Query q = createQuery(getSessionInfoImpl(sessionInfo).getSession(),
+                statement, language, namespaces);
+        return getBindVariableNames(q);
     }
 
     /**
@@ -1789,4 +1797,36 @@
         // if we get here simply run as is
         return call.run();
     }
+
+    private String[] getBindVariableNames(Query query) {
+        List<String> names = new ArrayList<String>();
+        if (query instanceof QueryObjectModel) {
+            QueryObjectModel qom = (QueryObjectModel) query;
+            collectBindVariableNames(qom.getConstraint(), names);
+        } else {
+            // TODO: use when available
+            // names.addAll(Arrays.asList(q.getBindVariableNames()));
+        }
+        return names.toArray(new String[names.size()]);
+    }
+
+    private void collectBindVariableNames(Constraint c, List<String> names) {
+        if (c instanceof And) {
+            collectBindVariableNames(((And) c).getConstraint1(), names);
+            collectBindVariableNames(((And) c).getConstraint2(), names);
+        } else if (c instanceof Or) {
+            collectBindVariableNames(((Or) c).getConstraint1(), names);
+            collectBindVariableNames(((Or) c).getConstraint2(), names);
+        } else if (c instanceof Not) {
+            collectBindVariableNames(((Not) c).getConstraint(), names);
+        } else if (c instanceof Comparison) {
+            collectBindVariableNames((Comparison) c, names);
+        }
+    }
+
+    private void collectBindVariableNames(Comparison c, List<String> names) {
+        if (c.getOperand2() instanceof BindVariableValue) {
+            names.add(((BindVariableValue) c.getOperand2()).getBindVariableName());
+        }
+    }
 }



Mime
View raw message