jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r789269 - in /jackrabbit/trunk: jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/ jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jc...
Date Mon, 29 Jun 2009 09:32:57 GMT
Author: mreutegg
Date: Mon Jun 29 09:32:56 2009
New Revision: 789269

URL: http://svn.apache.org/viewvc?rev=789269&view=rev
Log:
JCR-2076: JSR 283: QOM and SQL2
- change return type of QueryInfo.getColumnNames() from Name[] to String[]
- jcr2spi, spi2dav, spi2jcr implementation (work in progress)

Added:
    jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryResultImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResourceImpl.java
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResultProperty.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/QueryResultImpl.java
    jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryInfo.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.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/RepositoryServiceImpl.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

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=789269&r1=789268&r2=789269&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 Jun 29 09:32:56 2009
@@ -269,7 +269,7 @@
             maxResultSize = limit;
         }
 
-        if (resultNodes.size() >= maxResultSize) {
+        if (resultNodes.size() >= maxResultSize && selectorNames != null) {
             // we already have them all
             return;
         }

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java?rev=789269&r1=789268&r2=789269&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/ItemResourceConstants.java Mon Jun 29 09:32:56 2009
@@ -122,6 +122,7 @@
     public static final DavPropertyName JCR_ISNEW = DavPropertyName.create("isnew", NAMESPACE);
     public static final DavPropertyName JCR_ISMODIFIED = DavPropertyName.create("ismodified", NAMESPACE);
     public static final DavPropertyName JCR_DEFINITION = DavPropertyName.create("definition", NAMESPACE);
+    public static final DavPropertyName JCR_SELECTOR_NAME = DavPropertyName.create("selectorName", NAMESPACE);
 
     // property names used for resources representing jcr-nodes
     public static final DavPropertyName JCR_PRIMARYNODETYPE = DavPropertyName.create(XML_PRIMARYNODETYPE, NAMESPACE);

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=789269&r1=789268&r2=789269&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 09:32:56 2009
@@ -37,6 +37,8 @@
 import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.NamespaceRegistry;
+import javax.jcr.ValueFactory;
+import javax.jcr.PropertyType;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
@@ -45,6 +47,9 @@
 import javax.jcr.query.RowIterator;
 import java.util.Map;
 import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
 
 /**
  * <code>SearchResourceImpl</code>...
@@ -70,9 +75,9 @@
         try {
             QueryManager qMgr = getRepositorySession().getWorkspace().getQueryManager();
             String[] langs = qMgr.getSupportedQueryLanguages();
-            for (int i = 0; i < langs.length; i++) {
+            for (String lang : langs) {
                 // todo: define proper namespace
-                qgs.addQueryLanguage(langs[i], Namespace.EMPTY_NAMESPACE);
+                qgs.addQueryLanguage(lang, Namespace.EMPTY_NAMESPACE);
             }
         } catch (RepositoryException e) {
             log.debug(e.getMessage());
@@ -138,11 +143,11 @@
         Query q;
         if (sInfo != null) {
             // apply namespace mappings to session
-            Map namespaces = sInfo.getNamespaces();
+            Map<String, String> namespaces = sInfo.getNamespaces();
             try {
-                for (Iterator it = namespaces.keySet().iterator(); it.hasNext(); ) {
-                    String prefix = (String) it.next();
-                    String uri = (String) namespaces.get(prefix);
+                for (Map.Entry<String, String> entry : namespaces.entrySet()) {
+                    String prefix = entry.getKey();
+                    String uri = entry.getValue();
                     session.setNamespacePrefix(prefix, uri);
                 }
                 q = qMgr.createQuery(sInfo.getQuery(), sInfo.getLanguageName());
@@ -155,8 +160,7 @@
                 }
             } finally {
                 // reset namespace mappings
-                for (Iterator it = namespaces.values().iterator(); it.hasNext(); ) {
-                    String uri = (String) it.next();
+                for (String uri : namespaces.values()) {
                     try {
                         session.setNamespacePrefix(nsReg.getPrefix(uri), uri);
                     } catch (RepositoryException e) {
@@ -175,7 +179,7 @@
                 q.storeAsNode(itemPath);
             } catch (RepositoryException e) {
                 // ItemExistsException should never occur.
-                new JcrDavException(e);
+                throw new JcrDavException(e);
             }
         }
         return q;
@@ -187,46 +191,181 @@
      * @param qResult <code>QueryResult</code> as obtained from {@link javax.jcr.query.Query#execute()}.
      * @return <code>MultiStatus</code> object listing the query result in
      * Webdav compatible form.
-     * @throws RepositoryException
+     * @throws RepositoryException if an error occurs.
      */
     private MultiStatus queryResultToMultiStatus(QueryResult qResult)
             throws RepositoryException {
         MultiStatus ms = new MultiStatus();
 
-        String[] columnNames = qResult.getColumnNames();
+        List<String> columnNames = new ArrayList<String>();
+        columnNames.addAll(Arrays.asList(qResult.getColumnNames()));
         StringBuffer responseDescription = new StringBuffer();
         String delim = "";
-        for (int i = 0; i < columnNames.length; i++) {
+        for (String columnName : columnNames) {
             responseDescription.append(delim);
-            responseDescription.append(ISO9075.encode(columnNames[i]));
+            responseDescription.append(ISO9075.encode(columnName));
             delim = " ";
         }
         ms.setResponseDescription(responseDescription.toString());
 
+        ValueFactory vf = getRepositorySession().getValueFactory();
+        List<RowValue> descr = new ArrayList<RowValue>();
+        for (Iterator<String> it = columnNames.iterator(); it.hasNext(); ) {
+            String columnName = it.next();
+            if (!isPathOrScore(columnName)) {
+                descr.add(new PlainValue(columnName, null, vf));
+            } else {
+                it.remove();
+            }
+        }
+        // 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
+        }
+        for (String selectorName : sn) {
+            descr.add(new PathValue(JcrConstants.JCR_PATH, selectorName, vf));
+            columnNames.add(JcrConstants.JCR_PATH);
+            descr.add(new ScoreValue(JcrConstants.JCR_SCORE, selectorName, vf));
+            columnNames.add(JcrConstants.JCR_SCORE);
+        }
+        String[] selectorNames = createSelectorNames(descr);
+        String[] colNames = columnNames.toArray(new String[columnNames.size()]);
         RowIterator rowIter = qResult.getRows();
         while (rowIter.hasNext()) {
             Row row = rowIter.nextRow();
-            Value[] values = row.getValues();
+            List<Value> values = new ArrayList<Value>();
+            for (RowValue rv : descr) {
+                values.add(rv.getValue(row));
+            }
 
-            // get the jcr:path column indicating the node path and build
+            // get the path for the first selector and build
             // a webdav compliant resource path of it.
-            String itemPath = row.getValue(JcrConstants.JCR_PATH).getString();
+            String itemPath = row.getPath();
             // create a new ms-response for this row of the result set
             DavResourceLocator loc = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), itemPath, false);
             String href = loc.getHref(true);
             MultiStatusResponse resp = new MultiStatusResponse(href, null);
             // build the s-r-property
-            SearchResultProperty srp = new SearchResultProperty(columnNames, values);
+            SearchResultProperty srp = new SearchResultProperty(colNames,
+                    selectorNames, values.toArray(new Value[values.size()]));
             resp.add(srp);
             ms.addResponse(resp);
         }
         return ms;
     }
 
+    private static String[] createSelectorNames(Iterable<RowValue> rows)
+            throws RepositoryException {
+        List<String> sn = new ArrayList<String>();
+        for (RowValue rv : rows) {
+            sn.add(rv.getSelectorName());
+        }
+        return sn.toArray(new String[sn.size()]);
+    }
+
+    /**
+     * @param columnName a column name.
+     * @return <code>true</code> if <code>columnName</code> is either
+     *         <code>jcr:path</code> or <code>jcr:score</code>;
+     *         <code>false</code> otherwise.
+     */
+    private static boolean isPathOrScore(String columnName) {
+        return JcrConstants.JCR_PATH.equals(columnName)
+                || JcrConstants.JCR_SCORE.equals(columnName);
+    }
+
     /**
-     * @return
+     * @return the session associated with this resource.
      */
     private Session getRepositorySession() {
         return session.getRepositorySession();
     }
+
+    private interface RowValue {
+
+        public Value getValue(Row row) throws RepositoryException;
+
+        public String getColumnName() throws RepositoryException;
+
+        public String getSelectorName() throws RepositoryException;
+    }
+
+    private static final class PlainValue extends SelectorValue {
+
+        public PlainValue(String columnName,
+                          String selectorName,
+                          ValueFactory vf) {
+            super(columnName, selectorName, vf);
+        }
+
+        public Value getValue(Row row) throws RepositoryException {
+            return row.getValue(columnName);
+        }
+    }
+
+    private static abstract class SelectorValue implements RowValue {
+
+        protected final String columnName;
+
+        protected final String selectorName;
+
+        protected final ValueFactory vf;
+
+        public SelectorValue(String columnName,
+                             String selectorName,
+                             ValueFactory vf) {
+            this.columnName = columnName;
+            this.selectorName = selectorName;
+            this.vf = vf;
+        }
+
+        public String getColumnName() throws RepositoryException {
+            return columnName;
+        }
+
+        public String getSelectorName() throws RepositoryException {
+            return selectorName;
+        }
+    }
+
+    private static final class ScoreValue extends SelectorValue {
+
+        public ScoreValue(String columnName,
+                          String selectorName,
+                          ValueFactory vf) {
+            super(columnName, selectorName, vf);
+        }
+
+        public Value getValue(Row row) throws RepositoryException {
+            double score;
+            if (selectorName != null) {
+                score = row.getScore(selectorName);
+            } else {
+                score = row.getScore();
+            }
+            return vf.createValue(score);
+        }
+    }
+
+    private static final class PathValue extends SelectorValue {
+
+        public PathValue(String columnName,
+                         String selectorName,
+                         ValueFactory vf) {
+            super(columnName, selectorName, vf);
+        }
+
+        public Value getValue(Row row) throws RepositoryException {
+            String path;
+            if (selectorName != null) {
+                path = row.getPath(selectorName);
+            } else {
+                path = row.getPath();
+            }
+            return vf.createValue(path, PropertyType.PATH);
+        }
+    }
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResultProperty.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResultProperty.java?rev=789269&r1=789268&r2=789269&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResultProperty.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/search/SearchResultProperty.java Mon Jun 29 09:32:56 2009
@@ -33,7 +33,6 @@
 import javax.jcr.ValueFormatException;
 import javax.jcr.ValueFactory;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -48,18 +47,24 @@
     private static final String COLUMN = "column";
 
     private final String[] columnNames;
+    private final String[] selectorNames;
     private final Value[] values;
 
     /**
      * Creates a new <code>SearchResultProperty</code>.
      *
-     * @param columnNames the column names of the search row represented by this
-     * dav property.
-     * @param values the values present in the columns
-     */
-    public SearchResultProperty(String[] columnNames, Value[] values) {
+     * @param columnNames   the column names of the search row represented by
+     *                      this dav property.
+     * @param selectorNames the selecotr names of the row represented by this
+     *                      dav property.
+     * @param values        the values present in the columns
+     */
+    public SearchResultProperty(String[] columnNames,
+                                String[] selectorNames,
+                                Value[] values) {
         super(SEARCH_RESULT_PROPERTY, true);
         this.columnNames = columnNames;
+        this.selectorNames = selectorNames;
         this.values = values;
     }
 
@@ -79,35 +84,39 @@
 	    throw new IllegalArgumentException("SearchResultProperty may only be created from a property named " + SEARCH_RESULT_PROPERTY.toString());
 	}
 
-        List colList = new ArrayList();
-        List valList = new ArrayList();
+        List<String> colList = new ArrayList<String>();
+        List<String> selList = new ArrayList<String>();
+        List<Value> valList = new ArrayList<Value>();
         Object propValue = property.getValue();
         if (propValue instanceof List) {
-            Iterator elemIt = ((List)propValue).iterator();
-            while (elemIt.hasNext()) {
-                Object el = elemIt.next();
-                if (el instanceof Element) {
-                    parseColumnElement((Element)el, colList, valList, valueFactory);
+            for (Object o : ((List) propValue)) {
+                if (o instanceof Element) {
+                    parseColumnElement((Element) o, colList, selList, valList, valueFactory);
                 }
             }
         } else if (propValue instanceof Element) {
-            parseColumnElement((Element)property.getValue(), colList, valList, valueFactory);
+            parseColumnElement((Element)property.getValue(), colList, selList, valList, valueFactory);
         } else {
             throw new IllegalArgumentException("SearchResultProperty requires a list of 'dcr:column' xml elements.");
         }
 
-        columnNames = (String[]) colList.toArray(new String[colList.size()]);
-        values = (Value[]) valList.toArray(new Value[valList.size()]);
+        columnNames = colList.toArray(new String[colList.size()]);
+        selectorNames = selList.toArray(new String[selList.size()]);
+        values = valList.toArray(new Value[valList.size()]);
     }
 
-    private void parseColumnElement(Element columnElement, List columnNames,
-                                    List values, ValueFactory valueFactory)
+    private void parseColumnElement(Element columnElement,
+                                    List<String> columnNames,
+                                    List<String> selectorNames,
+                                    List<Value> values,
+                                    ValueFactory valueFactory)
         throws ValueFormatException, RepositoryException {
         if (!DomUtil.matches(columnElement, COLUMN, ItemResourceConstants.NAMESPACE)) {
             log.debug("dcr:column element expected within search result.");
             return;
         }
         columnNames.add(DomUtil.getChildText(columnElement, JCR_NAME.getName(), JCR_NAME.getNamespace()));
+        selectorNames.add(DomUtil.getChildText(columnElement, JCR_SELECTOR_NAME.getName(), JCR_SELECTOR_NAME.getNamespace()));
 
         Value jcrValue;
         Element valueElement = DomUtil.getChildElement(columnElement, JCR_VALUE.getName(), JCR_VALUE.getNamespace());
@@ -132,6 +141,13 @@
     }
 
     /**
+     * @return the selector name for each of the columns in the result property.
+     */
+    public String[] getSelectorNames() {
+        return selectorNames;
+    }
+
+    /**
      * Return the values representing the values of that row in the search
      * result table.
      *
@@ -154,7 +170,8 @@
 
     /**
      * Return the xml representation of this webdav property. For every value in
-     * the query result row a dcr:name, dcr:value and dcr:type element is created.
+     * the query result row a dcr:name, dcr:value, dcr:type and an optional
+     * dcr:selectorName element is created.
      * Example:
      * <pre>
      * -----------------------------------------------------------
@@ -162,6 +179,7 @@
      * -----------------------------------------------------------
      *   value     |   xxx   |   111   |  /aNode    |    1
      *   type      |    1    |    3    |     8      |    3
+     *   sel-name  |         |         |     S      |    S
      * -----------------------------------------------------------
      * </pre>
      * results in:
@@ -178,10 +196,12 @@
      *    &lt;dcr:column&gt;
      *       &lt;dcr:name&gt;jcr:path&lt;dcr:name/&gt;
      *       &lt;dcr:value dcr:type="Path"&gt;/aNode&lt;dcr:value/&gt;
+     *       &lt;dcr:selectorName&gt;S&lt;dcr:selectorName/&gt;
      *    &lt;/dcr:column&gt;
      *    &lt;dcr:column&gt;
      *       &lt;dcr:name&gt;jcr:score&lt;dcr:name/&gt;
      *       &lt;dcr:value dcr:type="Long"&gt;1&lt;dcr:value/&gt;
+     *       &lt;dcr:selectorName&gt;S&lt;dcr:selectorName/&gt;
      *    &lt;/dcr:column&gt;
      * &lt;/dcr:search-result-property&gt;
      * </pre>
@@ -192,6 +212,7 @@
         Element elem = getName().toXml(document);
         for (int i = 0; i < columnNames.length; i++) {
             String propertyName = columnNames[i];
+            String selectorName = selectorNames[i];
             Value propertyValue = values[i];
 
             Element columnEl = DomUtil.addChildElement(elem, COLUMN, ItemResourceConstants.NAMESPACE);
@@ -206,6 +227,9 @@
                     log.error(e.toString());
                 }
             }
+            if (selectorName != null) {
+                DomUtil.addChildElement(columnEl, JCR_SELECTOR_NAME.getName(), JCR_SELECTOR_NAME.getNamespace(), selectorName);
+            }
         }
         return elem;
     }

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java?rev=789269&r1=789268&r2=789269&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java Mon Jun 29 09:32:56 2009
@@ -213,12 +213,12 @@
         while (next == null && rows.hasNext()) {
             try {
                 QueryResultRow row = (QueryResultRow) rows.next();
-                nextId = row.getNodeId();
+                nextId = row.getNodeId(null);
                 Item tmp = itemMgr.getItem(hierarchyMgr.getNodeEntry(nextId));
 
                 if (tmp.isNode()) {
                     next = (Node) tmp;
-                    nextScore = row.getScore();
+                    nextScore = row.getScore(null);
                 } else {
                     log.warn("Item with Id is not a Node: " + nextId);
                     // try next

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=789269&r1=789268&r2=789269&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 Jun 29 09:32:56 2009
@@ -18,9 +18,7 @@
 
 import org.apache.jackrabbit.jcr2spi.ItemManager;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QueryInfo;
-import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
@@ -66,13 +64,7 @@
      * {@inheritDoc}
      */
     public String[] getColumnNames() throws RepositoryException {
-        Name[] names = queryInfo.getColumnNames();
-        String[] propNames = new String[names.length];
-        NamePathResolver resolver = mgrProvider.getNamePathResolver();
-        for (int i = 0; i < names.length; i++) {
-            propNames[i] = resolver.getJCRName(names[i]);
-        }
-        return propNames;
+        return queryInfo.getColumnNames();
     }
 
     /**
@@ -87,7 +79,8 @@
      */
     public RowIterator getRows() throws RepositoryException {
         return new RowIteratorImpl(queryInfo, mgrProvider.getNamePathResolver(),
-                mgrProvider.getJcrValueFactory());
+                mgrProvider.getJcrValueFactory(), itemMgr,
+                mgrProvider.getHierarchyManager());
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java?rev=789269&r1=789268&r2=789269&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/RowIteratorImpl.java Mon Jun 29 09:32:56 2009
@@ -25,19 +25,20 @@
 import javax.jcr.Node;
 import javax.jcr.RangeIterator;
 import javax.jcr.RepositoryException;
-import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.jcr.query.Row;
 import javax.jcr.query.RowIterator;
 
-import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QueryInfo;
 import org.apache.jackrabbit.spi.QueryResultRow;
+import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
+import org.apache.jackrabbit.jcr2spi.ItemManager;
+import org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManager;
 
 /**
  * Implements the {@link javax.jcr.query.RowIterator} interface returned by
@@ -53,7 +54,7 @@
     /**
      * The column names.
      */
-    private final Name[] columnNames;
+    private final String[] columnNames;
 
     /**
      * The <code>NamePathResolver</code> of the user <code>Session</code>.
@@ -66,6 +67,16 @@
     private final ValueFactory vFactory;
 
     /**
+     * The item manager.
+     */
+    private final ItemManager itemMgr;
+
+    /**
+     * The hierarchy manager.
+     */
+    private final HierarchyManager hmgr;
+
+    /**
      * Creates a new <code>RowIteratorImpl</code> that iterates over the result
      * nodes.
      *
@@ -73,12 +84,18 @@
      * @param resolver  <code>NameResolver</code> of the user
      *                  <code>Session</code>.
      * @param vFactory  the JCR value factory.
+     * @param itemMgr   the item manager.
+     * @param hmgr      the hierarchy manager.
      */
-    RowIteratorImpl(QueryInfo queryInfo, NamePathResolver resolver, ValueFactory vFactory) {
+    RowIteratorImpl(QueryInfo queryInfo, NamePathResolver resolver,
+                    ValueFactory vFactory, ItemManager itemMgr,
+                    HierarchyManager hmgr) {
         this.rows = queryInfo.getRows();
         this.columnNames = queryInfo.getColumnNames();
         this.resolver = resolver;
         this.vFactory = vFactory;
+        this.itemMgr = itemMgr;
+        this.hmgr = hmgr;
     }
 
     //--------------------------------------------------------< RowIterator >---
@@ -180,10 +197,10 @@
         private Value[] values;
 
         /**
-         * Map of select property <code>Name</code>s. Key: Name, Value:
+         * Map of select property names. Key: String, Value:
          * Integer, which refers to the array index in {@link #values}.
          */
-        private Map propertyMap;
+        private Map<String, Integer> propertyMap;
 
         /**
          * Creates a new <code>RowImpl</code> instance based on a SPI result
@@ -242,15 +259,14 @@
         public Value getValue(String propertyName) throws ItemNotFoundException, RepositoryException {
             if (propertyMap == null) {
                 // create the map first
-                Map tmp = new HashMap();
+                Map<String, Integer> tmp = new HashMap<String, Integer>();
                 for (int i = 0; i < columnNames.length; i++) {
-                    tmp.put(columnNames[i], new Integer(i));
+                    tmp.put(columnNames[i], i);
                 }
                 propertyMap = tmp;
             }
             try {
-                Name prop = resolver.getQName(propertyName);
-                Integer idx = (Integer) propertyMap.get(prop);
+                Integer idx = propertyMap.get(propertyName);
                 if (idx == null) {
                     throw new ItemNotFoundException(propertyName);
                 }
@@ -258,7 +274,7 @@
                 if (values == null) {
                     getValues();
                 }
-                return values[idx.intValue()];
+                return values[idx];
             } catch (NameException e) {
                 throw new RepositoryException(e.getMessage(), e);
             }
@@ -268,50 +284,69 @@
          * @see Row#getNode()
          */
         public Node getNode() throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            return getNode(row.getNodeId(null));
         }
 
         /**
          * @see Row#getNode(String)
          */
         public Node getNode(String selectorName) throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            return getNode(row.getNodeId(resolver.getQName(selectorName)));
         }
 
         /**
          * @see Row#getPath()
          */
         public String getPath() throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            String path = null;
+            Node n = getNode();
+            if (n != null) {
+                path = n.getPath();
+            }
+            return path;
         }
 
         /**
          * @see Row#getPath(String)
          */
         public String getPath(String selectorName) throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            String path = null;
+            Node n = getNode(selectorName);
+            if (n != null) {
+                path = n.getPath();
+            }
+            return path;
         }
 
         /**
          * @see Row#getScore()
          */
         public double getScore() throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            return row.getScore(null);
         }
 
         /**
          * @see Row#getScore(String)
          */
         public double getScore(String selectorName) throws RepositoryException {
-            // TODO
-            throw new UnsupportedRepositoryOperationException("JCR-1104");
+            return row.getScore(resolver.getQName(selectorName));
         }
 
+        /**
+         * Returns the node with the given <code>id</code> or <code>null</code>
+         * if <code>id</code> is <code>null</code>.
+         *
+         * @param id a node id or <code>null</code>.
+         * @return the node with the given id or <code>null</code>.
+         * @throws RepositoryException if an error occurs while retrieving the
+         *                             node.
+         */
+        private Node getNode(NodeId id) throws RepositoryException {
+            Node node = null;
+            if (id != null) {
+                node = (Node) itemMgr.getItem(hmgr.getNodeEntry(id));
+            }
+            return node;
+        }
     }
-
 }

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=789269&r1=789268&r2=789269&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 Jun 29 09:32:56 2009
@@ -43,5 +43,5 @@
      * the query result.
      * @see javax.jcr.query.QueryResult#getColumnNames()
      */
-    public Name[] getColumnNames();
+    public String[] getColumnNames();
 }

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java?rev=789269&r1=789268&r2=789269&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java (original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/QueryResultRow.java Mon Jun 29 09:32:56 2009
@@ -24,18 +24,27 @@
 public interface QueryResultRow {
 
     /**
-     * Returns {@link NodeId} of node this result row represents.
+     * Returns {@link NodeId} of node for a given <code>selectorname</code> this
+     * result row represents.
      *
-     * @return node id of the <code>Node</code> this result row represents.
+     * @param selectorName the name of a selector or <code>null</code> for the
+     *                     default selector.
+     * @return node id of the <code>Node</code> this result row represents or
+     *         <code>null</code> if there is no node present in this row for the
+     *         given selector name.
+     * @see javax.jcr.query.Row#getNode()
+     * @see javax.jcr.query.Row#getNode(String)
      */
-    public NodeId getNodeId();
+    public NodeId getNodeId(Name selectorName);
 
     /**
-     * Returns score of this result row.
+     * Returns score for the given <code>selectorName</code> of this result row.
      *
-     * @return score of this result row.
+     * @param selectorName the name of a selector or <code>null</code> for the
+     *                     default selector.
+     * @return score for the given selector in this result row.
      */
-    public double getScore();
+    public double getScore(Name selectorName);
 
     /**
      * Returns an array of <code>QValue</code>s.

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=789269&r1=789268&r2=789269&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 Jun 29 09:32:56 2009
@@ -16,33 +16,22 @@
  */
 package org.apache.jackrabbit.spi2dav;
 
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFactory;
-import javax.jcr.Value;
 import javax.jcr.RangeIterator;
 
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
-import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.QueryInfo;
-import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.QueryResultRow;
-import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.util.ISO9075;
-import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.MultiStatus;
 import org.apache.jackrabbit.webdav.MultiStatusResponse;
-import org.apache.jackrabbit.webdav.jcr.search.SearchResultProperty;
-import org.apache.jackrabbit.webdav.property.DavProperty;
-import org.apache.jackrabbit.webdav.property.DavPropertySet;
-import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.commons.conversion.NameException;
+import org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -56,13 +45,11 @@
      */
     private static final Logger log = LoggerFactory.getLogger(QueryInfoImpl.class);
 
-    private static final double UNDEFINED_SCORE = -1;
+    private final String[] columnNames;
 
-    private final Name[] columnNames;
-    private int scoreIndex = -1;
-    private final Map results = new LinkedHashMap();
+    private final List<QueryResultRow> results = new ArrayList<QueryResultRow>();
 
-    public QueryInfoImpl(MultiStatus ms, SessionInfo sessionInfo, URIResolver uriResolver,
+    public QueryInfoImpl(MultiStatus ms, IdFactory idFactory,
                          NamePathResolver resolver, ValueFactory valueFactory,
                          QValueFactory qValueFactory)
         throws RepositoryException {
@@ -70,43 +57,17 @@
         String responseDescription = ms.getResponseDescription();
         if (responseDescription != null) {
             String[] cn = responseDescription.split(" ");
-            this.columnNames = new Name[cn.length];
+            this.columnNames = new String[cn.length];
             for (int i = 0; i < cn.length; i++) {
-                String jcrColumnNames = ISO9075.decode(cn[i]);
-                try {
-                    columnNames[i] = resolver.getQName(jcrColumnNames);
-                    if (NameConstants.JCR_SCORE.equals(columnNames[i])) {
-                        scoreIndex = i;
-                    }
-                } catch (NameException e) {
-                    throw new RepositoryException(e);
-                }
+                columnNames[i] = ISO9075.decode(cn[i]);
             }
         } else {
             throw new RepositoryException("Missing column infos: Unable to build QueryInfo object.");
         }
 
-        MultiStatusResponse[] responses = ms.getResponses();
-        for (int i = 0; i < responses.length; i++) {
-            MultiStatusResponse response = responses[i];
-            String href = response.getHref();
-            DavPropertySet okSet = response.getProperties(DavServletResponse.SC_OK);
-
-            DavProperty davProp = okSet.get(SearchResultProperty.SEARCH_RESULT_PROPERTY);
-            SearchResultProperty resultProp = new SearchResultProperty(davProp, valueFactory);
-            Value[] values = resultProp.getValues();
-            QValue[] qValues = new QValue[values.length];
-            for (int j = 0; j < values.length; j++) {
-                try {
-                    qValues[j] = (values[j] == null) ?  null : ValueFormat.getQValue(values[j], resolver, qValueFactory);
-                } catch (RepositoryException e) {
-                    // should not occur
-                    log.error("Malformed value: " + values[j].toString());
-                }
-            }
-
-            NodeId nodeId = uriResolver.getNodeId(href, sessionInfo);
-            results.put(nodeId, qValues);
+        for (MultiStatusResponse response : ms.getResponses()) {
+            results.add(new QueryResultRowImpl(response, columnNames, resolver,
+                    qValueFactory, valueFactory, idFactory));
         }
     }
 
@@ -114,112 +75,15 @@
      * @see QueryInfo#getRows()
      */
     public RangeIterator getRows() {
-        return new QueryResultRowIterator();
+        return new RangeIteratorAdapter(results);
     }
 
     /**
      * @see QueryInfo#getColumnNames()
      */
-    public Name[] getColumnNames() {
-        return columnNames;
-    }
-
-    //--------------------------------------------------------< inner class >---
-    /**
-     * Inner class implementing the <code>RangeIterator</code> for the query
-     * result rows. 
-     */
-    private class QueryResultRowIterator implements RangeIterator {
-
-        private final Iterator keyIterator;
-        private long pos = 0;
-
-        private QueryResultRowIterator() {
-            keyIterator = results.keySet().iterator();
-        }
-
-        private QueryResultRow nextQueryResultRow() {
-            final NodeId nId = (NodeId) keyIterator.next();
-            final QValue[] qValues = (QValue[]) results.get(nId);
-            pos++;
-
-            return new QueryResultRow() {
-                /**
-                 * @see QueryResultRow#getNodeId()
-                 */
-                public NodeId getNodeId() {
-                    return nId;
-                }
-
-                /**
-                 * @see QueryResultRow#getScore()
-                 */
-                public double getScore() {
-                    if (scoreIndex != -1 && qValues[scoreIndex] != null) {
-                        try {
-                            return Double.parseDouble(qValues[scoreIndex].getString());
-                        } catch (RepositoryException e) {
-                            log.error("Error while building query score", e);
-                        }   return UNDEFINED_SCORE;
-                    } else {
-                        log.error("Cannot determined jcr:score from query results.");
-                        return UNDEFINED_SCORE;
-                    }
-                }
-
-                /**
-                 * @see QueryResultRow#getValues()
-                 */
-                public QValue[] getValues() {
-                    return qValues;
-                }
-            };
-        }
-
-        //--------------------------------------------------< RangeIterator >---
-        /**
-         * @see RangeIterator#skip(long)
-         */
-        public void skip(long skipNum) {
-            while (skipNum-- > 0) {
-                nextQueryResultRow();
-            }
-        }
-
-        /**
-         * @see RangeIterator#getSize()
-         */
-        public long getSize() {
-            return results.size();
-        }
-
-        /**
-         * @see RangeIterator#getPosition()
-         */
-        public long getPosition() {
-            return pos;
-        }
-
-        //-------------------------------------------------------< Iterator >---
-        /**
-         * @see Iterator#remove()
-         */
-        public void remove() {
-            throw new UnsupportedOperationException("Remove not implemented");
-        }
-
-        /**
-         * @see Iterator#hasNext()
-         */
-        public boolean hasNext() {
-            return keyIterator.hasNext();
-        }
-
-        /**
-         * @see Iterator#next()
-         */
-        public Object next() {
-            return nextQueryResultRow();
-        }
+    public String[] getColumnNames() {
+        String[] names = new String[columnNames.length];
+        System.arraycopy(columnNames, 0, names, 0, columnNames.length);
+        return names;
     }
 }

Added: 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=789269&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java (added)
+++ jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java Mon Jun 29 09:32:56 2009
@@ -0,0 +1,132 @@
+/*
+ * 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.spi2dav;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import javax.jcr.Value;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFactory;
+
+import org.apache.jackrabbit.spi.QueryResultRow;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.QValue;
+import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.spi.IdFactory;
+import org.apache.jackrabbit.spi.commons.value.ValueFormat;
+import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.webdav.property.DavPropertySet;
+import org.apache.jackrabbit.webdav.property.DavProperty;
+import org.apache.jackrabbit.webdav.DavServletResponse;
+import org.apache.jackrabbit.webdav.MultiStatusResponse;
+import org.apache.jackrabbit.webdav.jcr.search.SearchResultProperty;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+/**
+ * <code>QueryResultRowImpl</code> implements a QueryResultRow that is
+ * initialized from a multi status response.
+ */
+public class QueryResultRowImpl implements QueryResultRow {
+
+    private static final Logger log = LoggerFactory.getLogger(QueryResultRowImpl.class);
+
+    private final Map<Name, NodeId> nodeIds = new HashMap<Name, NodeId>();
+
+    private final Map<Name, Double> scores = new HashMap<Name, Double>();
+
+    private final Map<String, QValue> qValues = new HashMap<String, QValue>();
+
+    private final String[] columnNames;
+
+    public QueryResultRowImpl(MultiStatusResponse response,
+                              String[] columnNames,
+                              NamePathResolver resolver,
+                              QValueFactory qValueFactory,
+                              ValueFactory valueFactory,
+                              IdFactory idFactory)
+            throws RepositoryException {
+        this.columnNames = columnNames;
+        DavPropertySet okSet = response.getProperties(DavServletResponse.SC_OK);
+
+        String jcrPath = resolver.getJCRName(NameConstants.JCR_PATH);
+        String jcrScore = resolver.getJCRName(NameConstants.JCR_SCORE);
+        DavProperty davProp = okSet.get(SearchResultProperty.SEARCH_RESULT_PROPERTY);
+        SearchResultProperty resultProp = new SearchResultProperty(davProp, valueFactory);
+        Value[] values = resultProp.getValues();
+        String[] names = resultProp.getColumnNames();
+        String[] selectorNames = resultProp.getSelectorNames();
+        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]);
+                if (jcrScore.equals(names[i])) {
+                    Double score = 0.0;
+                    if (v != null) {
+                        score = v.getDouble();
+                    }
+                    scores.put(s, score);
+                } else if (jcrPath.equals(names[i])) {
+                    NodeId id = null;
+                    if (v != null) {
+                        id = idFactory.createNodeId((String) null, v.getPath());
+                    }
+                    nodeIds.put(s, id);
+                }
+                qValues.put(names[i], v);
+            } catch (RepositoryException e) {
+                // should not occur
+                log.error("Malformed value: " + values[i].toString());
+            }
+        }
+    }
+
+    public NodeId getNodeId(Name selectorName) {
+        NodeId id = nodeIds.get(selectorName);
+        if (id == null) {
+            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) {
+            if (scores.size() == 1) {
+                return scores.values().iterator().next();
+            } else {
+                throw new IllegalArgumentException(selectorName + " is not a valid selectorName");
+            }
+        }
+        return score;
+    }
+
+    public QValue[] getValues() {
+        QValue[] values = new QValue[columnNames.length];
+        for (int i = 0; i < columnNames.length; i++) {
+            values[i] = qValues.get(columnNames[i]);
+        }
+        return values;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/QueryResultRowImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=789269&r1=789268&r2=789269&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 09:32:56 2009
@@ -1690,7 +1690,7 @@
 
             MultiStatus ms = method.getResponseBodyAsMultiStatus();
             NamePathResolver resolver = getNamePathResolver(sessionInfo);
-            return new QueryInfoImpl(ms, sessionInfo, uriResolver, resolver, valueFactory, getQValueFactory());
+            return new QueryInfoImpl(ms, idFactory, resolver, valueFactory, getQValueFactory());
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {
@@ -1725,7 +1725,7 @@
 
             MultiStatus ms = method.getResponseBodyAsMultiStatus();
             NamePathResolver resolver = getNamePathResolver(sessionInfo);
-            return new QueryInfoImpl(ms, sessionInfo, uriResolver, resolver, valueFactory, getQValueFactory());
+            return new QueryInfoImpl(ms, idFactory, resolver, valueFactory, getQValueFactory());
         } catch (IOException e) {
             throw new RepositoryException(e);
         } catch (DavException e) {

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml?rev=789269&r1=789268&r2=789269&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml Mon Jun 29 09:32:56 2009
@@ -70,21 +70,13 @@
                 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.GetLanguageTest#testJCRQOM
-                org.apache.jackrabbit.test.api.query.OrderByDateTest
-                org.apache.jackrabbit.test.api.query.OrderByDoubleTest
-                org.apache.jackrabbit.test.api.query.OrderByLongTest
-                org.apache.jackrabbit.test.api.query.OrderByStringTest
-                org.apache.jackrabbit.test.api.query.OrderByLengthTest
-                org.apache.jackrabbit.test.api.query.OrderByLocalNameTest
-                org.apache.jackrabbit.test.api.query.OrderByLowerCaseTest
-                org.apache.jackrabbit.test.api.query.OrderByNameTest
-                org.apache.jackrabbit.test.api.query.OrderByUpperCaseTest
-                org.apache.jackrabbit.test.api.query.OrderByDecimalTest
-                org.apache.jackrabbit.test.api.query.OrderByURITest
-                org.apache.jackrabbit.test.api.query.SetLimitTest
-                org.apache.jackrabbit.test.api.query.SetOffsetTest
-                org.apache.jackrabbit.test.api.query.qom
+                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=789269&r1=789268&r2=789269&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 09:32:56 2009
@@ -19,10 +19,8 @@
 import org.apache.jackrabbit.spi.QueryInfo;
 import org.apache.jackrabbit.spi.QValueFactory;
 import org.apache.jackrabbit.spi.Name;
-import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.commons.iterator.RangeIteratorAdapter;
 import org.apache.jackrabbit.commons.iterator.RangeIteratorDecorator;
-import org.apache.jackrabbit.spi.commons.conversion.NameException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -67,24 +65,19 @@
     /**
      * The names of the columns in the query result.
      */
-    private final Name[] columnNames;
+    private final String[] columnNames;
 
     /**
-     * The resolved name of the jcr:score column.
+     * The names of the selectors in the query result.
      */
-    private final String scoreName;
-
-    /**
-     * The resolved name of the jcr:path column.
-     */
-    private final String pathName;
+    private final Name[] selectorNames;
 
     /**
      * Creates a new query info based on a given <code>result</code>.
      *
      * @param result        the JCR query result.
      * @param idFactory     the id factory.
-     * @param resolver
+     * @param resolver      the name path resolver.
      * @param qValueFactory the QValue factory.
      * @throws RepositoryException if an error occurs while reading from
      *                             <code>result</code>.
@@ -98,16 +91,12 @@
         this.idFactory = idFactory;
         this.resolver = resolver;
         this.qValueFactory = qValueFactory;
-        String[] jcrNames = result.getColumnNames();
-        this.columnNames = new Name[jcrNames.length];
-        try {
-            for (int i = 0; i < jcrNames.length; i++) {
-                columnNames[i] = resolver.getQName(jcrNames[i]);
-            }
-            this.scoreName = resolver.getJCRName(NameConstants.JCR_SCORE);
-            this.pathName = resolver.getJCRName(NameConstants.JCR_PATH);
-        } catch (NameException e) {
-            throw new RepositoryException(e.getMessage(), e);
+        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]);
         }
     }
 
@@ -116,13 +105,12 @@
      */
     public RangeIterator getRows() {
         try {
-            final String[] columnJcrNames = result.getColumnNames();
             return new RangeIteratorDecorator(result.getRows()) {
                 public Object next() {
                     try {
                         return new QueryResultRowImpl(
-                                (Row) super.next(), columnJcrNames, scoreName,
-                                pathName, idFactory, resolver, qValueFactory);
+                                (Row) super.next(), columnNames, selectorNames,
+                                idFactory, resolver, qValueFactory);
                     } catch (RepositoryException e) {
                         log.warn("Exception when creating QueryResultRowImpl: " +
                                 e.getMessage(), e);
@@ -138,8 +126,8 @@
     /**
      * {@inheritDoc}
      */
-    public Name[] getColumnNames() {
-        Name[] names = new Name[columnNames.length];
+    public String[] getColumnNames() {
+        String[] names = new String[columnNames.length];
         System.arraycopy(columnNames, 0, names, 0, columnNames.length);
         return names;
     }

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=789269&r1=789268&r2=789269&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 09:32:56 2009
@@ -16,18 +16,24 @@
  */
 package org.apache.jackrabbit.spi2jcr;
 
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Arrays;
+
 import org.apache.jackrabbit.spi.QueryResultRow;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.Name;
 import org.apache.jackrabbit.spi.commons.value.ValueFormat;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.spi.commons.conversion.NameException;
 
 import javax.jcr.query.Row;
 import javax.jcr.RepositoryException;
 import javax.jcr.Value;
+import javax.jcr.Node;
 
 /**
  * <code>QueryResultRowImpl</code> implements a <code>QueryResultRow</code>
@@ -36,14 +42,14 @@
 class QueryResultRowImpl implements QueryResultRow {
 
     /**
-     * The node id of the underlying row.
+     * The node ids of the underlying row.
      */
-    private final NodeId nodeId;
+    private final Map<Name, NodeId> nodeIds = new HashMap<Name, NodeId>();
 
     /**
-     * The score value for this row.
+     * The score values for this row.
      */
-    private final double score;
+    private final Map<Name, Double> scores = new HashMap<Name, Double>();
 
     /**
      * The QValues for this row.
@@ -55,30 +61,19 @@
      *
      * @param row           the JCR row.
      * @param columnNames   the resolved names of the columns.
-     * @param scoreName     the name of the jcr:score column.
-     * @param pathName      the name of the jcr:path column
+     * @param selectorNames the selector names.
      * @param idFactory     the id factory.
-     * @param resolver
+     * @param resolver      the name path resolver.
      * @param qValueFactory the QValue factory.
      * @throws RepositoryException if an error occurs while reading from
      *                             <code>row</code>.
      */
     public QueryResultRowImpl(Row row,
                               String[] columnNames,
-                              String scoreName,
-                              String pathName,
+                              Name[] selectorNames,
                               IdFactoryImpl idFactory,
                               NamePathResolver resolver,
                               QValueFactory qValueFactory) throws RepositoryException {
-        String jcrPath = row.getValue(pathName).getString();
-        Path path;
-        try {
-            path = resolver.getQPath(jcrPath);
-        } catch (NameException e) {
-            throw new RepositoryException(e.getMessage(), e);
-        }
-        this.nodeId = idFactory.createNodeId((String) null, path);
-        this.score = row.getValue(scoreName).getDouble();
         this.values = new QValue[columnNames.length];
         for (int i = 0; i < columnNames.length; i++) {
             Value v = row.getValue(columnNames[i]);
@@ -88,19 +83,52 @@
                 values[i] = ValueFormat.getQValue(v, resolver, qValueFactory);
             }
         }
+        List<Name> selNames = new ArrayList<Name>();
+        selNames.addAll(Arrays.asList(selectorNames));
+        if (selNames.isEmpty()) {
+            selNames.add(null); // default selector
+        }
+        for (Name sn : selNames) {
+            Node n;
+            double score;
+            if (sn == null) {
+                n = row.getNode();
+                score = row.getScore();
+            } else {
+                String selName = resolver.getJCRName(sn);
+                n = row.getNode(selName);
+                score = row.getScore(selName);
+            }
+            NodeId id = null;
+            if (n != null) {
+                id = idFactory.fromJcrIdentifier(n.getIdentifier());
+            }
+            nodeIds.put(sn, id);
+            scores.put(sn, score);
+        }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public NodeId getNodeId() {
-        return nodeId;
+    public NodeId getNodeId(Name selectorName) {
+        NodeId id = nodeIds.get(selectorName);
+        if (id == null) {
+            if (nodeIds.size() == 1) {
+                return nodeIds.values().iterator().next();
+            } else {
+                throw new IllegalArgumentException(selectorName + " is not a valid selectorName");
+            }
+        }
+        return id;
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public double getScore() {
+    public double getScore(Name selectorName) {
+        Double score = scores.get(selectorName);
+        if (score == null) {
+            if (scores.size() == 1) {
+                return scores.values().iterator().next();
+            } else {
+                throw new IllegalArgumentException(selectorName + " is not a valid selectorName");
+            }
+        }
         return score;
     }
 



Mime
View raw message