jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r550419 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/ main/java/org/apache/jackrabbit/core/query/lucene/ test/java/org/apache/jackrabbit/core/query/
Date Mon, 25 Jun 2007 08:58:08 GMT
Author: mreutegg
Date: Mon Jun 25 01:58:07 2007
New Revision: 550419

URL: http://svn.apache.org/viewvc?view=rev&rev=550419
Log:
JCR-967: Only search the index for the "jcr:system" tree if needed

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/PathQueryNodeTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/DerefQueryNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExactQueryNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/NAryQueryNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OrderQueryNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PathQueryNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PropertyFunctionQueryNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryRootNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/DerefQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/DerefQueryNode.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/DerefQueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/DerefQueryNode.java
Mon Jun 25 01:58:07 2007
@@ -83,4 +83,14 @@
         }
         return false;
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsSystemTree() {
+        // Always return true since we don't know if the referenced nodes path
+        // is a child of /jcr:system
+        return true;
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExactQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExactQueryNode.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExactQueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/ExactQueryNode.java
Mon Jun 25 01:58:07 2007
@@ -93,4 +93,11 @@
         }
         return false;
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsSystemTree() {
+        return false;
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/NAryQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/NAryQueryNode.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/NAryQueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/NAryQueryNode.java
Mon Jun 25 01:58:07 2007
@@ -18,6 +18,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -146,4 +147,20 @@
         }
         return false;
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsSystemTree() {
+        if (operands == null) {
+            return false;
+        }
+        for (Iterator iter = operands.iterator(); iter.hasNext();) {
+            QueryNode queryNode = (QueryNode) iter.next();
+            if (queryNode.needsSystemTree())
+                return true;
+        }
+        return false;
+    }
+    
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OrderQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OrderQueryNode.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OrderQueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/OrderQueryNode.java
Mon Jun 25 01:58:07 2007
@@ -188,4 +188,12 @@
             return false;
         }
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsSystemTree() {
+        return false;
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PathQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PathQueryNode.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PathQueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PathQueryNode.java
Mon Jun 25 01:58:07 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.core.query;
 
+import org.apache.jackrabbit.name.QName;
+
 /**
  * Implements a query node that defines a path restriction.
  */
@@ -109,5 +111,46 @@
             return super.equals(obj) && absolute == other.absolute;
         }
         return false;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsSystemTree() {
+        
+        LocationStepQueryNode[] pathSteps = getPathSteps();
+        if (pathSteps == null || pathSteps.length == 0) {
+            return true;
+        }
+
+        QName firstPathStepName = pathSteps[0].getNameTest();
+        // If the first location step has a null name test we need to include
+        // the system tree ("*")
+        if (firstPathStepName == null)
+            return true;
+        
+        // Calculate the first workspace relative location step
+        LocationStepQueryNode firstWorkspaceRelativeStep = pathSteps[0];
+        if (firstPathStepName.equals(QName.ROOT)) {
+            // path starts with "/jcr:root"
+            if (pathSteps.length > 1) {
+                firstWorkspaceRelativeStep = pathSteps[1];
+            }
+        }
+        
+        // First path step starts with "//"
+        if (firstWorkspaceRelativeStep.getIncludeDescendants())
+            return true;
+
+        // If the first workspace relative location step is jcr:system we need 
+        // to include the system tree
+        QName firstWorkspaceRelativeName = firstWorkspaceRelativeStep.getNameTest();
+        if (firstWorkspaceRelativeName == null
+                || firstWorkspaceRelativeName.equals(QName.JCR_SYSTEM)) {
+            return true;
+        }
+        
+        return super.needsSystemTree();
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PropertyFunctionQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PropertyFunctionQueryNode.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PropertyFunctionQueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/PropertyFunctionQueryNode.java
Mon Jun 25 01:58:07 2007
@@ -112,4 +112,12 @@
     public String getFunctionName() {
         return functionName;
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsSystemTree() {
+        return false;
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryNode.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryNode.java
Mon Jun 25 01:58:07 2007
@@ -125,4 +125,13 @@
      *   <code>this</code>; <code>false</code> otherwise.
      */
     public abstract boolean equals(Object obj);
+    
+    /**
+     * Returns <code>true</code> if this query node needs items under
+     * /jcr:system to be queried.
+     * 
+     * @return <code>true</code> if this query node needs content under
+     *         /jcr:system to be queried; <code>false</code> otherwise.
+     */
+    public abstract boolean needsSystemTree();
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryRootNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryRootNode.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryRootNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryRootNode.java
Mon Jun 25 01:58:07 2007
@@ -133,4 +133,12 @@
         }
         return false;
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsSystemTree() {
+        return (locationNode != null && locationNode.needsSystemTree()) || (orderNode
!= null && orderNode.needsSystemTree());
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/TextsearchQueryNode.java
Mon Jun 25 01:58:07 2007
@@ -209,4 +209,12 @@
         }
         return false;
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean needsSystemTree() {
+        return false;
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryImpl.java
Mon Jun 25 01:58:07 2007
@@ -241,4 +241,15 @@
 
         return (QName[]) selectProps.toArray(new QName[selectProps.size()]);
     }
+    
+    /**
+     * Returns <code>true</code> if this query node needs items under
+     * /jcr:system to be queried.
+     * 
+     * @return <code>true</code> if this query node needs content under
+     *         /jcr:system to be queried; <code>false</code> otherwise.
+     */
+    protected boolean needsSystemTree() {
+        return this.root.needsSystemTree();
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/SearchIndex.java
Mon Jun 25 01:58:07 2007
@@ -519,7 +519,7 @@
         checkOpen();
         SortField[] sortFields = createSortFields(orderProps, orderSpecs);
 
-        IndexReader reader = getIndexReader();
+        IndexReader reader = getIndexReader(queryImpl.needsSystemTree());
         IndexSearcher searcher = new IndexSearcher(reader);
         Hits hits;
         if (sortFields.length > 0) {
@@ -611,9 +611,26 @@
      * @throws IOException the index reader cannot be obtained.
      */
     public IndexReader getIndexReader() throws IOException {
+        return getIndexReader(true);
+    }
+
+    /**
+     * Returns an index reader for this search index. The caller of this method
+     * is responsible for closing the index reader when he is finished using
+     * it.
+     *
+     * @param includeSystemIndex if <code>true</code> the index reader will
+     *                           cover the complete workspace. If
+     *                           <code>false</code> the returned index reader
+     *                           will not contains any nodes under /jcr:system.
+     * @return an index reader for this search index.
+     * @throws IOException the index reader cannot be obtained.
+     */
+    protected IndexReader getIndexReader(boolean includeSystemIndex)
+            throws IOException {
         QueryHandler parentHandler = getContext().getParentHandler();
         IndexReader parentReader = null;
-        if (parentHandler instanceof SearchIndex) {
+        if (parentHandler instanceof SearchIndex && includeSystemIndex) {
             parentReader = ((SearchIndex) parentHandler).index.getIndexReader();
         }
 

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/PathQueryNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/PathQueryNodeTest.java?view=auto&rev=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/PathQueryNodeTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/PathQueryNodeTest.java
Mon Jun 25 01:58:07 2007
@@ -0,0 +1,67 @@
+/*
+ * 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.core.query;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.core.query.xpath.XPathQueryBuilder;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.QName;
+
+public class PathQueryNodeTest extends TestCase {
+
+    private static final NamespaceResolver JCR_RESOLVER = new NamespaceResolver() {
+        public String getJCRName(QName qName) {
+            return this.getPrefix(qName.getNamespaceURI()) + ":"
+                    + qName.getLocalName();
+        }
+
+        public String getPrefix(String uri) {
+            return QName.NS_JCR_PREFIX;
+        }
+
+        public QName getQName(String jcrName) {
+            return new QName(QName.NS_JCR_URI,
+                    jcrName.substring(jcrName.indexOf(':')));
+        }
+
+        public String getURI(String prefix) {
+            return QName.NS_JCR_URI;
+        }
+    };    
+    
+    public void testNeedsSystemTree() throws Exception {
+        QueryRootNode queryRootNode = XPathQueryBuilder.createQuery("/jcr:root/*", JCR_RESOLVER);
+        assertTrue(queryRootNode.needsSystemTree());
+
+        queryRootNode = XPathQueryBuilder.createQuery("/jcr:root/test/*", JCR_RESOLVER);
+        assertFalse(queryRootNode.needsSystemTree());
+
+        queryRootNode = XPathQueryBuilder.createQuery("*", JCR_RESOLVER);
+        assertTrue(queryRootNode.needsSystemTree());
+
+        queryRootNode = XPathQueryBuilder.createQuery("jcr:system/*", JCR_RESOLVER);
+        assertTrue(queryRootNode.needsSystemTree());
+
+        queryRootNode = XPathQueryBuilder.createQuery("test//*", JCR_RESOLVER);
+        assertFalse(queryRootNode.needsSystemTree());
+        
+        queryRootNode = XPathQueryBuilder.createQuery("//test/*", JCR_RESOLVER);
+        assertTrue(queryRootNode.needsSystemTree());         
+    }
+    
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/PathQueryNodeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java?view=diff&rev=550419&r1=550418&r2=550419
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/TestAll.java
Mon Jun 25 01:58:07 2007
@@ -49,6 +49,7 @@
         suite.addTestSuite(ChildAxisQueryTest.class);
         suite.addTestSuite(QueryResultTest.class);
         suite.addTestSuite(FnNameQueryTest.class);
+        suite.addTestSuite(PathQueryNodeTest.class);
 
         // exclude long running tests per default
         //suite.addTestSuite(MassiveRangeTest.class);



Mime
View raw message