jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1404114 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
Date Wed, 31 Oct 2012 12:36:14 GMT
Author: mreutegg
Date: Wed Oct 31 12:36:13 2012
New Revision: 1404114

URL: http://svn.apache.org/viewvc?rev=1404114&view=rev
Log:
OAK-325: QueryEngine can't handle node type hierarchies
- evaluate type hierarchy only once per query

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java?rev=1404114&r1=1404113&r2=1404114&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/SelectorImpl.java
Wed Oct 31 12:36:13 2012
@@ -20,6 +20,8 @@ package org.apache.jackrabbit.oak.query.
 
 import static org.apache.jackrabbit.oak.api.Type.STRINGS;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Set;
 
 import javax.annotation.CheckForNull;
@@ -56,6 +58,10 @@ public class SelectorImpl extends Source
     private final String nodeTypeName, selectorName;
     private Cursor cursor;
     private int scanCount;
+    /**
+     * Iterable over selected node type and its subtypes
+     */
+    private Iterable<NodeType> nodeTypes;
 
     /**
      * The selector condition can be evaluated when the given selector is
@@ -160,23 +166,8 @@ public class SelectorImpl extends Source
         Set<String> mixins =
                 getStrings(tree, JcrConstants.JCR_MIXINTYPES);
 
-        // TODO: Should retrieve matching node types only once per query
-        // execution instead of again and again for each return row
-        NodeTypeManager manager = new ReadOnlyNodeTypeManager() {
-            @Override @CheckForNull
-            protected Tree getTypes() {
-                return getTree(NodeTypeConstants.NODE_TYPES_PATH);
-            }
-        };
-
         try {
-            NodeType type = manager.getNodeType(nodeTypeName);
-            if (evaluateTypeMatch(type, primary, mixins)) {
-                return true;
-            }
-            NodeTypeIterator iterator = type.getSubtypes();
-            while (iterator.hasNext()) {
-                type = iterator.nextNodeType();
+            for (NodeType type : getNodeTypes()) {
                 if (evaluateTypeMatch(type, primary, mixins)) {
                     return true;
                 }
@@ -274,4 +265,24 @@ public class SelectorImpl extends Source
         }
     }
 
+    private Iterable<NodeType> getNodeTypes() throws RepositoryException {
+        if (nodeTypes == null) {
+            List<NodeType> types = new ArrayList<NodeType>();
+            NodeTypeManager manager = new ReadOnlyNodeTypeManager() {
+                @Override @CheckForNull
+                protected Tree getTypes() {
+                    return getTree(NodeTypeConstants.NODE_TYPES_PATH);
+                }
+            };
+            NodeType type = manager.getNodeType(nodeTypeName);
+            types.add(type);
+
+            NodeTypeIterator it = type.getSubtypes();
+            while (it.hasNext()) {
+                types.add(it.nextNodeType());
+            }
+            nodeTypes = types;
+        }
+        return nodeTypes;
+    }
 }



Mime
View raw message