Author: alexparvulescu
Date: Fri Sep 27 08:27:29 2013
New Revision: 1526830

URL: http://svn.apache.org/r1526830
Log:
OAK-1051 SelectorImpl should skip reading node type info if the 
#matchesAllTypes flag is set


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=1526830&r1=1526829&r2=1526830&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
 Fri Sep 27 08:27:29 2013
@@ -52,6 +52,8 @@ import org.apache.jackrabbit.oak.spi.que
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
+import com.google.common.collect.ImmutableSet;
+
 /**
  * A selector within a query.
  */
@@ -60,6 +62,9 @@ public class SelectorImpl extends Source
     // TODO possibly support using multiple indexes (using index intersection 
/ index merge)
     protected QueryIndex index;
 
+    /**
+     * the node type associated with the {@link #nodeTypeName}
+     */
     private final NodeState nodeType;
 
     private final String selectorName;
@@ -68,10 +73,20 @@ public class SelectorImpl extends Source
 
     private final boolean matchesAllTypes;
 
+    /**
+     * all of the matching supertypes, or empty if the {@link 
#matchesAllTypes} flag is set
+     */
     private final Set<String> supertypes;
 
+    /**
+     * all of the matching primary subtypes, or empty if the {@link 
#matchesAllTypes} flag is set
+     */
     private final Set<String> primaryTypes;
 
+    /**
+     * all of the matching mixin types, or empty if the {@link 
#matchesAllTypes}
+     * flag is set
+     */
     private final Set<String> mixinTypes;
 
     private Cursor cursor;
@@ -94,15 +109,22 @@ public class SelectorImpl extends Source
         this.nodeTypeName = nodeType.getName(JCR_NODETYPENAME);
         this.matchesAllTypes = NT_BASE.equals(nodeTypeName);
 
-        this.supertypes = newHashSet(nodeType.getNames(OAK_SUPERTYPES));
-        supertypes.add(nodeTypeName);
-
-        this.primaryTypes = 
newHashSet(nodeType.getNames(OAK_PRIMARY_SUBTYPES));
-        this.mixinTypes = newHashSet(nodeType.getNames(OAK_MIXIN_SUBTYPES));
-        if (nodeType.getBoolean(JCR_ISMIXIN)) {
-            mixinTypes.add(nodeTypeName);
+        if (!this.matchesAllTypes) {
+            this.supertypes = newHashSet(nodeType.getNames(OAK_SUPERTYPES));
+            supertypes.add(nodeTypeName);
+
+            this.primaryTypes = newHashSet(nodeType
+                    .getNames(OAK_PRIMARY_SUBTYPES));
+            this.mixinTypes = 
newHashSet(nodeType.getNames(OAK_MIXIN_SUBTYPES));
+            if (nodeType.getBoolean(JCR_ISMIXIN)) {
+                mixinTypes.add(nodeTypeName);
+            } else {
+                primaryTypes.add(nodeTypeName);
+            }
         } else {
-            primaryTypes.add(nodeTypeName);
+            this.supertypes = ImmutableSet.of();
+            this.primaryTypes = ImmutableSet.of();
+            this.mixinTypes = ImmutableSet.of();
         }
     }
 
@@ -114,16 +136,28 @@ public class SelectorImpl extends Source
         return matchesAllTypes;
     }
 
+    /**
+     * @return all of the matching supertypes, or empty if the
+     *         {@link #matchesAllTypes} flag is set
+     */
     @Nonnull
     public Set<String> getSupertypes() {
         return supertypes;
     }
 
+    /**
+     * @return all of the matching primary subtypes, or empty if the
+     *         {@link #matchesAllTypes} flag is set
+     */
     @Nonnull
     public Set<String> getPrimaryTypes() {
         return primaryTypes;
     }
 
+    /**
+     * @return all of the matching mixin types, or empty if the
+     *         {@link #matchesAllTypes} flag is set
+     */
     @Nonnull
     public Set<String> getMixinTypes() {
         return mixinTypes;
@@ -140,7 +174,6 @@ public class SelectorImpl extends Source
 
     @Override
     public String toString() {
-        String nodeTypeName = nodeType.getName(JCR_NODETYPENAME);
         return quote(nodeTypeName) + " as " + quote(selectorName);
     }
 


Reply via email to