jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r793507 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2s...
Date Mon, 13 Jul 2009 09:02:57 GMT
Author: mreutegg
Date: Mon Jul 13 09:02:57 2009
New Revision: 793507

URL: http://svn.apache.org/viewvc?rev=793507&view=rev
Log:
JCR-2201: Implement QueryResult.getSelectorNames()

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/SelectorTest.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.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/lucene/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java?rev=793507&r1=793506&r2=793507&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
Mon Jul 13 09:02:57 2009
@@ -182,10 +182,15 @@
         }
     }
 
-    // TODO: JCR-2201: Implement QueryResult.getSelectorNames()
+    /**
+     * {@inheritDoc}
+     */
     public String[] getSelectorNames() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException(
-                "JCR-2201: Implement QueryResult.getSelectorNames()");
+        String[] names = new String[selectorNames.length];
+        for (int i = 0; i < selectorNames.length; i++) {
+            names[i] = session.getJCRName(selectorNames[i]);
+        }
+        return names;
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/SelectorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/SelectorTest.java?rev=793507&r1=793506&r2=793507&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/SelectorTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/SelectorTest.java
Mon Jul 13 09:02:57 2009
@@ -22,6 +22,7 @@
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
 import javax.jcr.query.qom.QueryObjectModelConstants;
 import javax.jcr.query.qom.QueryObjectModel;
 
@@ -38,7 +39,12 @@
                 qf.selector(testNodeType, "s"), null, null, null);
         forQOMandSQL2(qom, new Callable() {
             public Object call(Query query) throws RepositoryException {
-                NodeIterator it = query.execute().getNodes();
+                QueryResult result = query.execute();
+                String[] names = result.getSelectorNames();
+                assertNotNull(names);
+                assertEquals(1, names.length);
+                assertEquals("s", names[0]);
+                NodeIterator it = result.getNodes();
                 while (it.hasNext()) {
                     assertTrue("Wrong node type", it.nextNode().isNodeType(testNodeType));
                 }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java?rev=793507&r1=793506&r2=793507&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
Mon Jul 13 09:02:57 2009
@@ -19,10 +19,11 @@
 import org.apache.jackrabbit.jcr2spi.ItemManager;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.apache.jackrabbit.spi.QueryInfo;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.commons.conversion.NameResolver;
 
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.RowIterator;
 
@@ -61,10 +62,17 @@
         this.queryInfo = queryInfo;
     }
 
-    // TODO: JCR-2201: Implement QueryResult.getSelectorNames()
+    /**
+     * {@inheritDoc}
+     */
     public String[] getSelectorNames() throws RepositoryException {
-        throw new UnsupportedRepositoryOperationException(
-                "JCR-2201: Implement QueryResult.getSelectorNames()");
+        Name[] names = queryInfo.getSelectorNames();
+        String[] sn = new String[names.length];
+        NameResolver resolver = mgrProvider.getNameResolver();
+        for (int i = 0; i < sn.length; i++) {
+            sn[i] = resolver.getJCRName(names[i]);
+        }
+        return sn;
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java?rev=793507&r1=793506&r2=793507&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java
Mon Jul 13 09:02:57 2009
@@ -39,9 +39,16 @@
     public RangeIterator getRows();
 
     /**
-     * @return an array of <code>Name</code>s representing the column names of
-     * the query result.
+     * @return an array of <code>String</code>s representing the column names
of
+     *         the query result.
      * @see javax.jcr.query.QueryResult#getColumnNames()
      */
     public String[] getColumnNames();
+
+    /**
+     * @return an array of <code>Name</code>s representing the selector names
of
+     *         the query result.
+     * @see javax.jcr.query.QueryResult#getSelectorNames()
+     */
+    public Name[] getSelectorNames();
 }

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java?rev=793507&r1=793506&r2=793507&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryInfoImpl.java
Mon Jul 13 09:02:57 2009
@@ -18,6 +18,8 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFactory;
@@ -27,6 +29,7 @@
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.QueryResultRow;
 import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.util.ISO9075;
 import org.apache.jackrabbit.webdav.MultiStatus;
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
@@ -86,4 +89,23 @@
         System.arraycopy(columnNames, 0, names, 0, columnNames.length);
         return names;
     }
+
+    /**
+     * @see QueryInfo#getSelectorNames()
+     */
+    public Name[] getSelectorNames() {
+        if (results.isEmpty()) {
+            // TODO: this is not correct
+            return new Name[0];
+        } else {
+            Set<Name> uniqueNames = new HashSet<Name>();
+            QueryResultRowImpl row = (QueryResultRowImpl) results.get(0);
+            for (Name n : row.getSelectorNames()) {
+                if (n != null) {
+                    uniqueNames.add(n);
+                }
+            }
+            return uniqueNames.toArray(new Name[uniqueNames.size()]);
+        }
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java?rev=793507&r1=793506&r2=793507&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java
Mon Jul 13 09:02:57 2009
@@ -56,6 +56,8 @@
 
     private final String[] columnNames;
 
+    private final Name[] selectorNames;
+
     public QueryResultRowImpl(MultiStatusResponse response,
                               String[] columnNames,
                               NamePathResolver resolver,
@@ -73,22 +75,23 @@
         Value[] values = resultProp.getValues();
         String[] names = resultProp.getColumnNames();
         String[] selectorNames = resultProp.getSelectorNames();
+        this.selectorNames = new Name[selectorNames.length];
         for (int i = 0; i < values.length; i++) {
             try {
                 QValue v = (values[i] == null) ? null : ValueFormat.getQValue(values[i],
resolver, qValueFactory);
-                Name s = (selectorNames[i] == null) ? null : resolver.getQName(selectorNames[i]);
+                this.selectorNames[i] = (selectorNames[i] == null) ? null : resolver.getQName(selectorNames[i]);
                 if (jcrScore.equals(names[i])) {
                     Double score = 0.0;
                     if (v != null) {
                         score = v.getDouble();
                     }
-                    scores.put(s, score);
+                    scores.put(this.selectorNames[i], score);
                 } else if (jcrPath.equals(names[i])) {
                     NodeId id = null;
                     if (v != null) {
                         id = idFactory.createNodeId((String) null, v.getPath());
                     }
-                    nodeIds.put(s, id);
+                    nodeIds.put(this.selectorNames[i], id);
                 }
                 qValues.put(names[i], v);
             } catch (RepositoryException e) {
@@ -129,4 +132,8 @@
         }
         return values;
     }
+
+    Name[] getSelectorNames() {
+        return selectorNames;
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java?rev=793507&r1=793506&r2=793507&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java
Mon Jul 13 09:02:57 2009
@@ -27,16 +27,11 @@
 
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.Row;
-import javax.jcr.query.Query;
-import javax.jcr.query.qom.QueryObjectModel;
-import javax.jcr.query.qom.Source;
-import javax.jcr.query.qom.Join;
-import javax.jcr.query.qom.Selector;
 import javax.jcr.RepositoryException;
 import javax.jcr.RangeIterator;
 import java.util.NoSuchElementException;
 import java.util.List;
-import java.util.ArrayList;
+import java.util.Arrays;
 
 /**
  * <code>QueryInfoImpl</code> implements a <code>QueryInfo</code>
based on a
@@ -82,7 +77,6 @@
     /**
      * Creates a new query info based on a given <code>result</code>.
      *
-     * @param query         the JCR query.
      * @param result        the JCR query result.
      * @param idFactory     the id factory.
      * @param resolver      the name path resolver.
@@ -90,8 +84,7 @@
      * @throws RepositoryException if an error occurs while reading from
      *                             <code>result</code>.
      */
-    public QueryInfoImpl(Query query,
-                         QueryResult result,
+    public QueryInfoImpl(QueryResult result,
                          IdFactoryImpl idFactory,
                          NamePathResolver resolver,
                          QValueFactory qValueFactory)
@@ -101,7 +94,7 @@
         this.resolver = resolver;
         this.qValueFactory = qValueFactory;
         this.columnNames = result.getColumnNames();
-        this.selectorNames = getSelectorNames(query, result, resolver);
+        this.selectorNames = getSelectorNames(result, resolver);
     }
 
     /**
@@ -136,39 +129,23 @@
         return names;
     }
 
-    private static Name[] getSelectorNames(Query query,
-                                           QueryResult result,
+    /**
+     * {@inheritDoc}
+     */
+    public Name[] getSelectorNames() {
+        Name[] names = new Name[selectorNames.length];
+        System.arraycopy(selectorNames, 0, names, 0, selectorNames.length);
+        return names;
+    }
+
+    private static Name[] getSelectorNames(QueryResult result,
                                            NamePathResolver resolver)
             throws RepositoryException {
-        List<String> sn = new ArrayList<String>();
-        if (query instanceof QueryObjectModel) {
-            QueryObjectModel qom = (QueryObjectModel) query;
-            collectSelectorNames(qom.getSource(), sn);
-        } else {
-            // TODO
-            // sn.addAll(Arrays.asList(result.getSelectorNames()));
-        }
+        List<String> sn = Arrays.asList(result.getSelectorNames());
         Name[] selectorNames = new Name[sn.size()];
         for (int i = 0; i < sn.size(); i++) {
             selectorNames[i] = resolver.getQName(sn.get(i));
         }
         return selectorNames;
     }
-
-    private static void collectSelectorNames(Source source, List<String> sn) {
-        if (source instanceof Join) {
-            collectSelectorNames((Join) source, sn);
-        } else {
-            collectSelectorNames((Selector) source, sn);
-        }
-    }
-
-    private static void collectSelectorNames(Join join, List<String> sn) {
-        collectSelectorNames(join.getLeft(), sn);
-        collectSelectorNames(join.getRight(), sn);
-    }
-
-    private static void collectSelectorNames(Selector s, List<String> sn) {
-        sn.add(s.getSelectorName());
-    }
 }

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=793507&r1=793506&r2=793507&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 09:02:57 2009
@@ -1049,7 +1049,7 @@
                 query.bindValue(entry.getKey(), value);
             }
         }
-        return new QueryInfoImpl(query, query.execute(), idFactory,
+        return new QueryInfoImpl(query.execute(), idFactory,
                 sInfo.getNamePathResolver(), getQValueFactory());
     }
 



Mime
View raw message