jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r789307 - in /jackrabbit/trunk: jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/ jackrabbit-spi2jcr/ jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/
Date Mon, 29 Jun 2009 12:31:28 GMT
Author: mreutegg
Date: Mon Jun 29 12:31:28 2009
New Revision: 789307

URL: http://svn.apache.org/viewvc?rev=789307&view=rev
Log:
JCR-2076: JSR 283: QOM and SQL2
- jcr2spi, spi2dav, spi2jcr implementation (work in progress)

Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java
    jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/RepositoryServiceImpl.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java?rev=789307&r1=789306&r2=789307&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
Mon Jun 29 12:31:28 2009
@@ -45,6 +45,11 @@
 import javax.jcr.query.QueryResult;
 import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
+import javax.jcr.query.qom.Source;
+import javax.jcr.query.qom.Join;
+import javax.jcr.query.qom.Selector;
+import javax.jcr.query.qom.QueryObjectModel;
+
 import java.util.Map;
 import java.util.Iterator;
 import java.util.List;
@@ -92,9 +97,7 @@
      */
     public MultiStatus search(SearchInfo sInfo) throws DavException {
         try {
-            Query q = getQuery(sInfo);
-            QueryResult qR = q.execute();
-            return queryResultToMultiStatus(qR);
+            return queryResultToMultiStatus(getQuery(sInfo));
 
         } catch (RepositoryException e) {
             throw new JcrDavException(e);
@@ -188,13 +191,14 @@
     /**
      * Build a <code>MultiStatus</code> object from the specified query result.
      *
-     * @param qResult <code>QueryResult</code> as obtained from {@link javax.jcr.query.Query#execute()}.
+     * @param query the query to execute.
      * @return <code>MultiStatus</code> object listing the query result in
      * Webdav compatible form.
      * @throws RepositoryException if an error occurs.
      */
-    private MultiStatus queryResultToMultiStatus(QueryResult qResult)
+    private MultiStatus queryResultToMultiStatus(Query query)
             throws RepositoryException {
+        QueryResult qResult = query.execute();
         MultiStatus ms = new MultiStatus();
 
         List<String> columnNames = new ArrayList<String>();
@@ -220,11 +224,7 @@
         }
         // add path and score for each selector
         List<String> sn = new ArrayList<String>();
-        // TODO
-        // sn.addAll(Arrays.asList(qResult.getSelectorNames()));
-        if (sn.isEmpty()) {
-            sn.add(null); // default selector
-        }
+        collectSelectorNames(query, qResult, sn);
         for (String selectorName : sn) {
             descr.add(new PathValue(JcrConstants.JCR_PATH, selectorName, vf));
             columnNames.add(JcrConstants.JCR_PATH);
@@ -368,4 +368,35 @@
             return vf.createValue(path, PropertyType.PATH);
         }
     }
+
+    private static void collectSelectorNames(Query query,
+                                             QueryResult result,
+                                             List<String> sn) {
+        if (query instanceof QueryObjectModel) {
+            QueryObjectModel qom = (QueryObjectModel) query;
+            collectSelectorNames(qom.getSource(), sn);
+        } else {
+            // TODO
+            // sn.addAll(Arrays.asList(qResult.getSelectorNames()));
+            // TODO: remove once getSelectorNames() is available
+            sn.add(null); // default selector
+        }
+    }
+
+    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());
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml?rev=789307&r1=789306&r2=789307&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml Mon Jun 29 12:31:28 2009
@@ -71,12 +71,6 @@
                 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.query.qom.ChildNodeJoinConditionTest
-                org.apache.jackrabbit.test.api.query.qom.DescendantNodeJoinConditionTest
-                org.apache.jackrabbit.test.api.query.qom.EquiJoinConditionTest
-                org.apache.jackrabbit.test.api.query.qom.SameNodeJoinConditionTest
-                org.apache.jackrabbit.test.api.query.qom.OrderingTest#testMultipleSelectors
-                org.apache.jackrabbit.test.api.query.qom.ColumnTest#testMultiColumn
                 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/QueryInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryInfoImpl.java?rev=789307&r1=789306&r2=789307&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 Jun 29 12:31:28 2009
@@ -27,9 +27,16 @@
 
 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;
 
 /**
  * <code>QueryInfoImpl</code> implements a <code>QueryInfo</code>
based on a
@@ -75,6 +82,7 @@
     /**
      * 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.
@@ -82,7 +90,8 @@
      * @throws RepositoryException if an error occurs while reading from
      *                             <code>result</code>.
      */
-    public QueryInfoImpl(QueryResult result,
+    public QueryInfoImpl(Query query,
+                         QueryResult result,
                          IdFactoryImpl idFactory,
                          NamePathResolver resolver,
                          QValueFactory qValueFactory)
@@ -92,12 +101,7 @@
         this.resolver = resolver;
         this.qValueFactory = qValueFactory;
         this.columnNames = result.getColumnNames();
-        // TODO
-        String[] sn = new String[0]; //result.getSelectorNames();
-        this.selectorNames = new Name[sn.length];
-        for (int i = 0; i < sn.length; i++) {
-            selectorNames[i] = resolver.getQName(sn[i]);
-        }
+        this.selectorNames = getSelectorNames(query, result, resolver);
     }
 
     /**
@@ -131,4 +135,40 @@
         System.arraycopy(columnNames, 0, names, 0, columnNames.length);
         return names;
     }
+
+    private static Name[] getSelectorNames(Query query,
+                                           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()));
+        }
+        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/QueryResultRowImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java?rev=789307&r1=789306&r2=789307&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/src/main/java/org/apache/jackrabbit/spi2jcr/QueryResultRowImpl.java
Mon Jun 29 12:31:28 2009
@@ -109,27 +109,33 @@
     }
 
     public NodeId getNodeId(Name selectorName) {
-        NodeId id = nodeIds.get(selectorName);
-        if (id == null) {
+        if (nodeIds.containsKey(selectorName)) {
+            return nodeIds.get(selectorName);
+        } else {
             if (nodeIds.size() == 1) {
                 return nodeIds.values().iterator().next();
             } else {
                 throw new IllegalArgumentException(selectorName + " is not a valid selectorName");
             }
         }
-        return id;
     }
 
     public double getScore(Name selectorName) {
-        Double score = scores.get(selectorName);
-        if (score == null) {
+        Double score;
+        if (scores.containsKey(selectorName)) {
+            score = scores.get(selectorName);
+        } else {
             if (scores.size() == 1) {
-                return scores.values().iterator().next();
+                score = scores.values().iterator().next();
             } else {
                 throw new IllegalArgumentException(selectorName + " is not a valid selectorName");
             }
         }
-        return score;
+        if (score == null) {
+            return Double.NaN;
+        } else {
+            return score;
+        }
     }
 
     /**

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=789307&r1=789306&r2=789307&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 12:31:28 2009
@@ -1036,7 +1036,7 @@
         SessionInfoImpl sInfo = getSessionInfoImpl(sessionInfo);
         Query query = createQuery(sInfo.getSession(), statement,
                 language, namespaces);
-        return new QueryInfoImpl(query.execute(), idFactory,
+        return new QueryInfoImpl(query, query.execute(), idFactory,
                 sInfo.getNamePathResolver(), getQValueFactory());
     }
 
@@ -1050,13 +1050,12 @@
         query.setLimit(limit);
         query.setOffset(offset);
         if (values != null && !values.isEmpty()) {
-            for (Iterator<String> it = values.keySet().iterator(); it.hasNext();) {
-                String varName = it.next();
-                Value value = ValueFormat.getJCRValue(values.get(varName), sInfo.getNamePathResolver(),
sInfo.getSession().getValueFactory());
-                query.bindValue(varName, value);
+            for (Map.Entry<String, QValue> entry : values.entrySet()) {
+                Value value = ValueFormat.getJCRValue(entry.getValue(), sInfo.getNamePathResolver(),
sInfo.getSession().getValueFactory());
+                query.bindValue(entry.getKey(), value);
             }
         }
-        return new QueryInfoImpl(query.execute(), idFactory,
+        return new QueryInfoImpl(query, query.execute(), idFactory,
                 sInfo.getNamePathResolver(), getQValueFactory());
     }
 



Mime
View raw message