You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by al...@apache.org on 2013/12/06 14:47:44 UTC
svn commit: r1548513 - in /jackrabbit/oak/trunk/oak-core/src:
main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/
test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/
Author: alexparvulescu
Date: Fri Dec 6 13:47:44 2013
New Revision: 1548513
URL: http://svn.apache.org/r1548513
Log:
OAK-1269 NodeType index doesn't respect the declaringNodeTypes setting
Added:
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java (with props)
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndex.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexLookup.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndex.java?rev=1548513&r1=1548512&r2=1548513&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndex.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndex.java Fri Dec 6 13:47:44 2013
@@ -48,7 +48,7 @@ class NodeTypeIndex implements QueryInde
return Double.POSITIVE_INFINITY;
}
NodeTypeIndexLookup lookup = new NodeTypeIndexLookup(root);
- if (lookup.isIndexed(filter.getPath())) {
+ if (lookup.isIndexed(filter.getPath(), filter)) {
return lookup.getCost(filter);
} else {
return Double.POSITIVE_INFINITY;
@@ -58,7 +58,7 @@ class NodeTypeIndex implements QueryInde
@Override
public Cursor query(Filter filter, NodeState root) {
NodeTypeIndexLookup lookup = new NodeTypeIndexLookup(root);
- if (!hasNodeTypeRestriction(filter) || !lookup.isIndexed(filter.getPath())) {
+ if (!hasNodeTypeRestriction(filter) || !lookup.isIndexed(filter.getPath(), filter)) {
throw new IllegalStateException(
"NodeType index is used even when no index is available for filter " + filter);
}
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexLookup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexLookup.java?rev=1548513&r1=1548512&r2=1548513&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexLookup.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexLookup.java Fri Dec 6 13:47:44 2013
@@ -45,10 +45,10 @@ class NodeTypeIndexLookup implements Jcr
* @return <code>true</code> if a node type index exists; <code>false</code>
* otherwise.
*/
- public boolean isIndexed(String path) {
+ public boolean isIndexed(String path, Filter f) {
PropertyIndexLookup lookup = new PropertyIndexLookup(root);
- if (lookup.isIndexed(JCR_PRIMARYTYPE, path, null)
- && lookup.isIndexed(JCR_MIXINTYPES, path, null)) {
+ if (lookup.isIndexed(JCR_PRIMARYTYPE, path, f)
+ && lookup.isIndexed(JCR_MIXINTYPES, path, f)) {
return true;
}
@@ -62,13 +62,13 @@ class NodeTypeIndexLookup implements Jcr
NodeState child = root.getChildNode(path.substring(0, slash));
return new NodeTypeIndexLookup(child).isIndexed(
- path.substring(slash));
+ path.substring(slash), f);
}
public double getCost(Filter filter) {
PropertyIndexLookup lookup = new PropertyIndexLookup(root);
- return lookup.getCost(null, JCR_PRIMARYTYPE, newName(filter.getPrimaryTypes()))
- + lookup.getCost(null, JCR_MIXINTYPES, newName(filter.getMixinTypes()));
+ return lookup.getCost(filter, JCR_PRIMARYTYPE, newName(filter.getPrimaryTypes()))
+ + lookup.getCost(filter, JCR_MIXINTYPES, newName(filter.getMixinTypes()));
}
/**
Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java?rev=1548513&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java Fri Dec 6 13:47:44 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.oak.plugins.index.nodetype;
+
+import static com.google.common.collect.ImmutableList.of;
+import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.createIndexDefinition;
+
+import java.util.ArrayList;
+
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
+import org.apache.jackrabbit.oak.query.AbstractQueryTest;
+import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
+import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.junit.Test;
+
+/**
+ * Tests the node type index implementation.
+ */
+public class NodeTypeIndexQueryTest extends AbstractQueryTest {
+
+ @Override
+ protected ContentRepository createRepository() {
+ return new Oak().with(new InitialContent())
+ .with(new OpenSecurityProvider())
+ .with(new NodeTypeIndexProvider())
+ .with(new PropertyIndexEditorProvider())
+ .createContentRepository();
+ }
+
+ private static void child(Tree t, String n, String type) {
+ t.addChild(n).setProperty(JCR_PRIMARYTYPE, type, Type.NAME);
+ }
+
+ private static void mixLanguage(Tree t, String n) {
+ Tree c = t.addChild(n);
+ c.setProperty(JCR_PRIMARYTYPE, "nt:unstructured", Type.NAME);
+ c.setProperty(JCR_MIXINTYPES, of("mix:language"), Type.NAMES);
+ }
+
+ @Test
+ public void query() throws Exception {
+ setTravesalFallback(false);
+
+ Tree t = root.getTree("/");
+ child(t, "a", "nt:unstructured");
+ child(t, "b", "nt:unstructured");
+ child(t, "c", "nt:folder");
+ child(t, "d", "nt:folder");
+ mixLanguage(t, "e");
+ mixLanguage(t, "f");
+
+ NodeUtil n = new NodeUtil(root.getTree("/oak:index"));
+ createIndexDefinition(n, "nodetype", false, new String[] {
+ JCR_PRIMARYTYPE, JCR_MIXINTYPES }, new String[] { "nt:folder",
+ "mix:language" });
+
+ root.commit();
+
+ assertQuery("select [jcr:path] from [nt:unstructured] ",
+ new ArrayList<String>());
+ assertQuery("select [jcr:path] from [nt:folder] ", of("/c", "/d"));
+ assertQuery("select [jcr:path] from [mix:language] ", of("/e", "/f"));
+
+ setTravesalFallback(true);
+ }
+}
\ No newline at end of file
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexQueryTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL