jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r219897 - in /incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query: ./ lucene/ sql/
Date Wed, 20 Jul 2005 13:24:33 GMT
Author: mreutegg
Date: Wed Jul 20 06:24:31 2005
New Revision: 219897

URL: http://svn.apache.org/viewcvs?rev=219897&view=rev
Log:
- Minor fix / enhancement for query using descendant-or-self of root node
- Implement equals() method on QueryNode classes
- Implement efficient QueryResult for query that traverses the whole workspace

Added:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java
  (with props)
Modified:
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/AndQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/DerefQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/ExactQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/LocationStepQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NAryQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NodeTypeQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NotQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrderQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/PathQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryRootNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
    incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/AndQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/AndQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/AndQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/AndQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -60,4 +60,14 @@
     public int getType() {
         return QueryNode.TYPE_AND;
     }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof AndQueryNode) {
+            return super.equals(obj);
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/DerefQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/DerefQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/DerefQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/DerefQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -71,4 +71,16 @@
     public Object accept(QueryNodeVisitor visitor, Object data) {
         return visitor.visit(this, data);
     }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof DerefQueryNode) {
+            DerefQueryNode other = (DerefQueryNode) obj;
+            return super.equals(obj)
+                    && refProperty == null ? other.refProperty == null : refProperty.equals(other.refProperty);
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/ExactQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/ExactQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/ExactQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/ExactQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -82,4 +82,15 @@
         return value;
     }
 
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof ExactQueryNode) {
+            ExactQueryNode other = (ExactQueryNode) obj;
+            return (value == null ? other.value == null : value.equals(other.value))
+                    && (property == null ? other.property == null : property.equals(other.property));
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/LocationStepQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/LocationStepQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/LocationStepQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/LocationStepQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -162,4 +162,18 @@
     public int getType() {
         return QueryNode.TYPE_LOCATION;
     }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof LocationStepQueryNode) {
+            LocationStepQueryNode other = (LocationStepQueryNode) obj;
+            return super.equals(other)
+                    && includeDescendants == other.includeDescendants
+                    && index == other.index
+                    && (nameTest == null ? other.nameTest == null : nameTest.equals(other.nameTest));
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NAryQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NAryQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NAryQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NAryQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -135,4 +135,15 @@
         }
         return result.toArray();
     }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof NAryQueryNode) {
+            NAryQueryNode other = (NAryQueryNode) obj;
+            return operands == null ? other.operands == null : operands.equals(other.operands);
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NodeTypeQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NodeTypeQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NodeTypeQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NodeTypeQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -52,4 +52,14 @@
     public int getType() {
         return QueryNode.TYPE_NODETYPE;
     }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof NodeTypeQueryNode) {
+            return super.equals(obj);
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NotQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NotQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NotQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/NotQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -57,4 +57,14 @@
     public int getType() {
         return QueryNode.TYPE_NOT;
     }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof NotQueryNode) {
+            return super.equals(obj);
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -59,4 +59,14 @@
     public int getType() {
         return QueryNode.TYPE_OR;
     }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof OrQueryNode) {
+            return super.equals(obj);
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrderQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrderQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrderQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/OrderQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -30,7 +30,7 @@
     /**
      * The order spects
      */
-    private List specs = new ArrayList();
+    private final List specs = new ArrayList();
 
     /**
      * Creates a new <code>OrderQueryNode</code> with a reference to a parent
@@ -101,6 +101,17 @@
         return (OrderSpec[]) specs.toArray(new OrderSpec[specs.size()]);
     }
 
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof OrderQueryNode) {
+            OrderQueryNode other = (OrderQueryNode) obj;
+            return specs.equals(other.specs);
+        }
+        return false;
+    }
+
     //------------------< OrderSpec class >-------------------------------------
 
     /**
@@ -159,6 +170,22 @@
          */
         public void setAscending(boolean ascending) {
             this.ascending = ascending;
+        }
+
+        /**
+         * Returns <code>true</code> if <code>this</code> order spec
is equal
+         * to <code>obj</code>
+         * @param obj the reference object with which to compare.
+         * @return <code>true</code> if <code>this</code> order spec
is equal
+         *   to <code>obj</code>; <code>false</code> otherwise.
+         */
+        public boolean equals(Object obj) {
+            if (obj instanceof OrderSpec) {
+                OrderSpec other = (OrderSpec) obj;
+                return (property == null ? other.property == null : property.equals(other.property))
+                        && ascending == other.ascending;
+            }
+            return false;
         }
     }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/PathQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/PathQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/PathQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/PathQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -100,4 +100,14 @@
         return absolute;
     }
 
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof PathQueryNode) {
+            PathQueryNode other = (PathQueryNode) obj;
+            return super.equals(obj) && absolute == other.absolute;
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryNode.java
Wed Jul 20 06:24:31 2005
@@ -113,4 +113,13 @@
      */
     public abstract int getType();
 
+    /**
+     * Returns <code>true</code> if <code>obj</code> is the same
type of
+     * <code>QueryNode</code> as <code>this</code> node and is equal
to
+     * <code>this</code> node.
+     * @param obj the reference object with which to compare.
+     * @return <code>true</code> if <code>obj</code> is equal to
+     *   <code>this</code>; <code>false</code> otherwise.
+     */
+    public abstract boolean equals(Object obj);
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryRootNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryRootNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryRootNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/QueryRootNode.java
Wed Jul 20 06:24:31 2005
@@ -120,4 +120,17 @@
     public int getType() {
         return QueryNode.TYPE_ROOT;
     }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof QueryRootNode) {
+            QueryRootNode other = (QueryRootNode) obj;
+            return (locationNode == null ? other.locationNode == null : locationNode.equals(other.locationNode))
+                    && selectProperties.equals(other.selectProperties)
+                    && (orderNode == null ? other.orderNode == null : orderNode.equals(other.orderNode));
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -301,4 +301,20 @@
         return operation;
     }
 
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof RelationQueryNode) {
+            RelationQueryNode other = (RelationQueryNode) obj;
+            return type == other.type
+                    && (valueDate == null ? other.valueDate == null : valueDate.equals(other.valueDate))
+                    && valueDouble == other.valueDouble
+                    && valueLong == other.valueLong
+                    && valuePosition == other.valuePosition
+                    && (valueString == null ? other.valueString == null : valueString.equals(other.valueString))
+                    && (property == null ? other.property == null : property.equals(other.property));
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java
Wed Jul 20 06:24:31 2005
@@ -106,4 +106,16 @@
     public void setPropertyName(QName property) {
         this.propertyName = property;
     }
+
+    /**
+     * @inheritDoc
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof TextsearchQueryNode) {
+            TextsearchQueryNode other = (TextsearchQueryNode) obj;
+            return (query == null ? other.query == null : query.equals(other.query))
+                    && (propertyName == null ? other.propertyName == null : propertyName.equals(other.propertyName));
+        }
+        return false;
+    }
 }

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/ConsistencyCheck.java
Wed Jul 20 06:24:31 2005
@@ -116,6 +116,7 @@
                 if (error.repairable()) {
                     error.repair();
                 } else {
+                    log.warn("Not repairable: " + error);
                     notRepairable++;
                 }
             } catch (IOException e) {

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/LuceneQueryBuilder.java
Wed Jul 20 06:24:31 2005
@@ -453,9 +453,15 @@
                 if (predicates.length > 0) {
                     // if we have a predicate attached, the condition acts as
                     // the sub query.
-                    Query subQuery = new DescendantSelfAxisQuery(context, andQuery, false);
-                    andQuery = new BooleanQuery();
-                    andQuery.add(subQuery, true, false);
+
+                    // only use descendant axis if path is not //*
+                    // otherwise the query for the predicate can be used itself
+                    PathQueryNode pathNode = (PathQueryNode) node.getParent();
+                    if (pathNode.getPathSteps()[0] != node) {
+                        Query subQuery = new DescendantSelfAxisQuery(context, andQuery, false);
+                        andQuery = new BooleanQuery();
+                        andQuery.add(subQuery, true, false);
+                    }
                 } else {
                     // todo this will traverse the whole index, optimize!
                     Query subQuery = null;
@@ -464,8 +470,14 @@
                     } catch (NoPrefixDeclaredException e) {
                         // will never happen, prefixes are created when unknown
                     }
-                    context = new DescendantSelfAxisQuery(context, subQuery);
-                    andQuery.add(new ChildAxisQuery(sharedItemMgr, context, null, node.getIndex()),
true, false);
+                    // only use descendant axis if path is not //*
+                    PathQueryNode pathNode = (PathQueryNode) node.getParent();
+                    if (pathNode.getPathSteps()[0] != node) {
+                        context = new DescendantSelfAxisQuery(context, subQuery);
+                        andQuery.add(new ChildAxisQuery(sharedItemMgr, context, null, node.getIndex()),
true, false);
+                    } else {
+                        andQuery.add(subQuery, true, false);
+                    }
                 }
             }
         } else {

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
Wed Jul 20 06:24:31 2005
@@ -62,6 +62,18 @@
     private static final Logger log = Logger.getLogger(QueryImpl.class);
 
     /**
+     * Represents a query that selects all nodes. E.g. in XPath: //*
+     */
+    private static final QueryRootNode ALL_NODES = new QueryRootNode();
+
+    static {
+        PathQueryNode pathNode = new PathQueryNode(ALL_NODES);
+        pathNode.addPathStep(new LocationStepQueryNode(pathNode, null, true));
+        pathNode.setAbsolute(true);
+        ALL_NODES.setLocationNode(pathNode);
+    }
+
+    /**
      * The root node of the query tree
      */
     private final QueryRootNode root;
@@ -129,6 +141,14 @@
         if (log.isDebugEnabled()) {
             log.debug("Executing query: \n" + root.dump());
         }
+
+        // check for special query
+        if (ALL_NODES.equals(root)) {
+            return new WorkspaceTraversalResult(session,
+                    new QName[]{Constants.JCR_PATH},
+                    session.getNamespaceResolver());
+        }
+
         // build lucene query
         Query query = LuceneQueryBuilder.createQuery(root, session,
                 index.getContext().getItemStateManager(), index.getNamespaceMappings(),

Added: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java?rev=219897&view=auto
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java
(added)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java
Wed Jul 20 06:24:31 2005
@@ -0,0 +1,289 @@
+/*
+ * Copyright 2004-2005 The Apache Software Foundation or its licensors,
+ *                     as applicable.
+ *
+ * Licensed 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.core.query.lucene;
+
+import org.apache.commons.collections.iterators.IteratorChain;
+import org.apache.jackrabbit.core.NodeImpl;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.NoPrefixDeclaredException;
+
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.RowIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
+import javax.jcr.Node;
+import java.util.Iterator;
+import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+/**
+ * Implements a query result that traverses the whole workspace and returns
+ * the nodes in document order.
+ */
+class WorkspaceTraversalResult implements QueryResult {
+
+    /**
+     * The session that issued the query.
+     */
+    private final Session session;
+
+    /**
+     * The select properties.
+     */
+    private final QName[] properties;
+
+    /**
+     * The namespace resolver of the session.
+     */
+    private final NamespaceResolver resolver;
+
+    /**
+     * Creates a new <code>WorkspaceTraversalResult</code>.
+     *
+     * @param session    the session that issued the query.
+     * @param properties the select properties.
+     * @param resolver   the namespace resolver of the session.
+     */
+    WorkspaceTraversalResult(Session session,
+                             QName[] properties,
+                             NamespaceResolver resolver) {
+        this.session = session;
+        this.properties = properties;
+        this.resolver = resolver;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public String[] getColumnNames() throws RepositoryException {
+        try {
+            String[] propNames = new String[properties.length];
+            for (int i = 0; i < properties.length; i++) {
+                propNames[i] = properties[i].toJCRName(resolver);
+            }
+            return propNames;
+        } catch (NoPrefixDeclaredException npde) {
+            String msg = "encountered invalid property name";
+            throw new RepositoryException(msg, npde);
+
+        }
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public RowIterator getRows() throws RepositoryException {
+        return new RowIteratorImpl(getNodeIterator(), properties, resolver);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public NodeIterator getNodes() throws RepositoryException {
+        return getNodeIterator();
+    }
+
+    /**
+     * Returns a {@link ScoreNodeIterator} that traverses the workspace in
+     * document order.
+     *
+     * @return iterator that returns nodes in document order.
+     * @throws RepositoryException if an error occurs while creating the
+     *                             iterator.
+     */
+    private ScoreNodeIterator getNodeIterator() throws RepositoryException {
+        return new TraversingNodeIterator(session.getRootNode(), Offset.ZERO);
+    }
+
+    /**
+     * Implements a node iterator that traverses the workspace in document
+     * order.
+     */
+    private class TraversingNodeIterator implements ScoreNodeIterator, Offset {
+
+        /**
+         * The current <code>Node</code>, which acts as the starting point for
+         * the traversal.
+         */
+        private final Node currentNode;
+
+        /**
+         * The chain of iterators which includes the iterators of the children
+         * of the current node.
+         */
+        private IteratorChain selfAndChildren;
+
+        /**
+         * Offset of this iterator to calculate the value in
+         * {@link #getPosition()}.
+         */
+        private final Offset offset;
+
+        /**
+         * Current (local) position in this iterator.
+         */
+        private long position;
+
+        /**
+         * Creates a <code>TraversingNodeIterator</code>.
+         * @param start the node from where to start the traversal.
+         * @param offset the offset to use to calculate the position.
+         */
+        TraversingNodeIterator(Node start, Offset offset) {
+            currentNode = start;
+            this.offset = offset;
+        }
+
+        /**
+         * Returns always 1.
+         * @return always 1.
+         */
+        public float getScore() {
+            return 1.0f;
+        }
+
+        /**
+         * @inheritDoc
+         */
+        public NodeImpl nextNodeImpl() {
+            init();
+            NodeImpl n = (NodeImpl) selfAndChildren.next();
+            position++;
+            return n;
+        }
+
+        /**
+         * @inheritDoc
+         */
+        public Node nextNode() {
+            return nextNodeImpl();
+        }
+
+        /**
+         * @inheritDoc
+         */
+        public void skip(long skipNum) {
+            while (skipNum > 0) {
+                if (hasNext()) {
+                    next();
+                    skipNum--;
+                } else {
+                    throw new NoSuchElementException();
+                }
+            }
+        }
+
+        /**
+         * Returns always -1 (unknown).
+         * @return always -1.
+         */
+        public long getSize() {
+            return -1;
+        }
+
+        /**
+         * @inheritDoc
+         */
+        public long getPosition() {
+            return offset.getValue() + position;
+        }
+
+        /**
+         * @exception UnsupportedOperationException always.
+         */
+        public void remove() {
+            throw new UnsupportedOperationException("remove");
+        }
+
+        /**
+         * @inheritDoc
+         */
+        public boolean hasNext() {
+            init();
+            return selfAndChildren.hasNext();
+        }
+
+        /**
+         * @inheritDoc
+         */
+        public Object next() {
+            return nextNode();
+        }
+
+        /**
+         * Returns the offset value for this iterator. The offset is the current
+         * position plus 1.
+         * @return  the offset value for this iterator.
+         */
+        public long getValue() {
+            return getPosition() + 1;
+        }
+
+        /**
+         * Initializes the iterator chain once.
+         */
+        private void init() {
+            if (selfAndChildren == null) {
+                Iterator current = Arrays.asList(new Node[]{currentNode}).iterator();
+                List allIterators = new ArrayList();
+                allIterators.add(current);
+                Offset offset = new Offset() {
+                    public long getValue() {
+                        return TraversingNodeIterator.this.offset.getValue() + 1;
+                    }
+                };
+
+                // create new TraversingNodeIterator for each child
+                try {
+                    NodeIterator children = currentNode.getNodes();
+                    while (children.hasNext()) {
+                        offset = new TraversingNodeIterator(children.nextNode(), offset);
+                        allIterators.add(offset);
+                    }
+                } catch (RepositoryException e) {
+                    // currentNode is probably stale
+                }
+                selfAndChildren = new IteratorChain(allIterators);
+            }
+        }
+    }
+
+    /**
+     * Helper class that holds an offset value.
+     */
+    interface Offset {
+
+        /**
+         * Offset that always returns the value 0.
+         */
+        static final Offset ZERO = new Offset() {
+            public long getValue() {
+                return 0;
+            }
+        };
+
+        /**
+         * Returns the value of this offset.
+         * @return the value of this offset..
+         */
+        long getValue();
+    }
+}

Propchange: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/lucene/WorkspaceTraversalResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java?rev=219897&r1=219896&r2=219897&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
(original)
+++ incubator/jackrabbit/trunk/core/src/java/org/apache/jackrabbit/core/query/sql/JCRSQLQueryBuilder.java
Wed Jul 20 06:24:31 2005
@@ -168,7 +168,6 @@
         PathQueryNode pathNode = root.getLocationNode();
         pathNode.setAbsolute(true);
         if (pathConstraints.size() == 0) {
-            pathNode.addPathStep(new LocationStepQueryNode(pathNode, new QName("", ""), false));
             pathNode.addPathStep(new LocationStepQueryNode(pathNode, null, true));
         } else {
             try {
@@ -503,6 +502,12 @@
     private void createPathQuery(String path, int operation) {
         MergingPathQueryNode pathNode = new MergingPathQueryNode(operation);
         pathNode.setAbsolute(true);
+
+        if (path.equals("/")) {
+            pathNode.addPathStep(new LocationStepQueryNode(pathNode, new QName("", ""), false));
+            pathConstraints.add(pathNode);
+            return;
+        }
 
         String[] names = path.split("/");
 



Mime
View raw message