jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r793484 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/q...
Date Mon, 13 Jul 2009 08:20:56 GMT
Author: mreutegg
Date: Mon Jul 13 08:20:55 2009
New Revision: 793484

URL: http://svn.apache.org/viewvc?rev=793484&view=rev
Log:
JCR-2200: Implement Query.getBindVariableNames()

Modified:
    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/QueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/AbstractQueryImpl.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java

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=793484&r1=793483&r2=793484&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
Mon Jul 13 08:20:55 2009
@@ -47,8 +47,15 @@
      * @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.
+     * @throws RepositoryException if an error occurs.
      */
     void bindValue(Name varName, Value value)
         throws IllegalArgumentException, RepositoryException;
+
+    /**
+     * @return the names of the bind variables in this query.
+     *
+     * @throws RepositoryException if an error occurs.
+     */
+    Name[] getBindVariableNames() throws RepositoryException;
 }

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=793484&r1=793483&r2=793484&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
Mon Jul 13 08:20:55 2009
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.Name;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -195,10 +196,16 @@
         }
     }
 
-    // TODO: JCR-2200: Implement Query.getBindVariableNames()
+    /**
+     * {@inheritDoc}
+     */
     public String[] getBindVariableNames() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException(
-                "JCR-2200: Implement Query.getBindVariableNames()");
+        Name[] names = query.getBindVariableNames();
+        String[] strNames = new String[names.length];
+        for (int i = 0; i < names.length; i++) {
+            strNames[i] = session.getJCRName(names[i]);
+        }
+        return strNames;
     }
 
     /**

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=793484&r1=793483&r2=793484&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
Mon Jul 13 08:20:55 2009
@@ -140,6 +140,13 @@
     }
 
     /**
+     * {@inheritDoc}
+     */
+    public Name[] getBindVariableNames() throws RepositoryException {
+        return variableNames.toArray(new Name[variableNames.size()]);
+    }
+
+    /**
      * Adds a name to the set of variables.
      *
      * @param varName the name of the variable.

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java?rev=793484&r1=793483&r2=793484&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java
Mon Jul 13 08:20:55 2009
@@ -71,6 +71,13 @@
         super.tearDown();
     }
 
+    public void testBindVariableNames() throws RepositoryException {
+        String[] names = qomQuery.getBindVariableNames();
+        assertNotNull(names);
+        assertEquals(1, names.length);
+        assertEquals("v", names[0]);
+    }
+
     public void testIllegalArgumentException() throws RepositoryException {
         try {
             bindVariableValue(qomQuery, "x", vf.createValue(STRING_VALUE));

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=793484&r1=793483&r2=793484&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 Jul 13 08:20:55 2009
@@ -220,10 +220,11 @@
         }
     }
 
-    // TODO: JCR-2200: Implement Query.getBindVariableNames()
+    /**
+     * @see Query#getBindVariableNames()
+     */
     public String[] getBindVariableNames() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException(
-                "JCR-2200: Implement Query.getBindVariableNames()");
+        return varNames.toArray(new String[varNames.size()]);
     }
 
     /**

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=793484&r1=793483&r2=793484&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 Jul 13 08:20:55 2009
@@ -89,13 +89,6 @@
 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;
@@ -1034,7 +1027,7 @@
             throws InvalidQueryException, RepositoryException {
         Query q = createQuery(getSessionInfoImpl(sessionInfo).getSession(),
                 statement, language, namespaces);
-        return getBindVariableNames(q);
+        return q.getBindVariableNames();
     }
 
     /**
@@ -1831,36 +1824,4 @@
         // 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