jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1471288 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/ oak-core/src/test...
Date Wed, 24 Apr 2013 08:25:19 GMT
Author: jukka
Date: Wed Apr 24 08:25:18 2013
New Revision: 1471288

URL: http://svn.apache.org/r1471288
Log:
OAK-325: QueryEngine can't handle node type hierarchies

Fix handling of type restrictions when updating indices

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexHookProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexHookProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookUpdate.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexTest.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexHookProvider.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java
    jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexHookProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexHookProvider.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexHookProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexHookProvider.java
Wed Apr 24 08:25:18 2013
@@ -26,6 +26,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.IndexHook;
 import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
  * This IndexHook provider combines all index hooks of all available OSGi
@@ -40,9 +41,10 @@ public class OsgiIndexHookProvider exten
 
     @Override
     @Nonnull
-    public List<? extends IndexHook> getIndexHooks(String type, NodeBuilder builder)
{
+    public List<? extends IndexHook> getIndexHooks(
+            String type, NodeBuilder builder, NodeState root) {
         IndexHookProvider composite = CompositeIndexHookProvider.compose(getServices());
-        return composite.getIndexHooks(type, builder);
+        return composite.getIndexHooks(type, builder, root);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexHookProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexHookProvider.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexHookProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexHookProvider.java
Wed Apr 24 08:25:18 2013
@@ -23,6 +23,7 @@ import java.util.List;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
@@ -38,8 +39,8 @@ public class CompositeIndexHookProvider 
         if (providers.isEmpty()) {
             return new IndexHookProvider() {
                 @Override
-                public List<? extends IndexHook> getIndexHooks(String type,
-                        NodeBuilder builder) {
+                public List<? extends IndexHook> getIndexHooks(
+                        String type, NodeBuilder builder, NodeState root) {
                     return ImmutableList.of();
                 }
             };
@@ -63,11 +64,11 @@ public class CompositeIndexHookProvider 
 
     @Override
     @Nonnull
-    public List<? extends IndexHook> getIndexHooks(String type,
-            NodeBuilder builder) {
+    public List<? extends IndexHook> getIndexHooks(
+            String type, NodeBuilder builder, NodeState root) {
         List<IndexHook> indexes = Lists.newArrayList();
         for (IndexHookProvider provider : providers) {
-            indexes.addAll(provider.getIndexHooks(type, builder));
+            indexes.addAll(provider.getIndexHooks(type, builder, root));
         }
         return indexes;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManager.java
Wed Apr 24 08:25:18 2013
@@ -45,6 +45,6 @@ public class IndexHookManager implements
     @Override
     public Editor getRootEditor(NodeState before, NodeState after,
             NodeBuilder builder) {
-        return VisibleEditor.wrap(new IndexHookManagerDiff(provider, builder));
+        return VisibleEditor.wrap(new IndexHookManagerDiff(provider, builder, after));
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerDiff.java
Wed Apr 24 08:25:18 2013
@@ -54,11 +54,15 @@ class IndexHookManagerDiff implements Ed
 
     private final NodeBuilder node;
 
+    private final NodeState root;
+
     private Editor inner = new DefaultEditor();
 
-    public IndexHookManagerDiff(IndexHookProvider provider, NodeBuilder node) {
+    public IndexHookManagerDiff(
+            IndexHookProvider provider, NodeBuilder node, NodeState root) {
         this.provider = provider;
         this.node = node;
+        this.root = root;
     }
 
     @Override
@@ -100,9 +104,9 @@ class IndexHookManagerDiff implements Ed
         List<IndexHook> reindex = Lists.newArrayList();
         for (String type : allTypes) {
             if (reindexTypes.contains(type)) {
-                reindex.addAll(provider.getIndexHooks(type, node));
+                reindex.addAll(provider.getIndexHooks(type, node, ref));
             } else {
-                hooks.addAll(provider.getIndexHooks(type, node));
+                hooks.addAll(provider.getIndexHooks(type, node, ref));
             }
         }
         reindex(reindex, ref);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookProvider.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookProvider.java
Wed Apr 24 08:25:18 2013
@@ -21,6 +21,7 @@ import java.util.List;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
  * Extension point for plugging in different kinds of IndexHook providers.
@@ -47,9 +48,12 @@ public interface IndexHookProvider {
      * @param builder
      *            the node state builder of the content node that will be used
      *            for updates
+     * @param root
+     *            root node state
      * @return a list of index hooks of the given type
      */
     @Nonnull
-    List<? extends IndexHook> getIndexHooks(String type, NodeBuilder builder);
+    List<? extends IndexHook> getIndexHooks(
+            String type, NodeBuilder builder, NodeState root);
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUtils.java
Wed Apr 24 08:25:18 2013
@@ -117,7 +117,7 @@ public class IndexUtils {
             entry.setBoolean(UNIQUE_PROPERTY_NAME, true);
         }
         if (declaringNodeTypeNames != null && declaringNodeTypeNames.length >
0) {
-            entry.setStrings(DECLARING_NODE_TYPES, declaringNodeTypeNames);
+            entry.setNames(DECLARING_NODE_TYPES, declaringNodeTypeNames);
         }
         entry.setNames(PROPERTY_NAMES, propertyNames);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHook.java
Wed Apr 24 08:25:18 2013
@@ -16,22 +16,29 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.p2;
 
+import static com.google.common.collect.Iterables.addAll;
 import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Sets.newHashSet;
+import static org.apache.jackrabbit.JcrConstants.JCR_ISMIXIN;
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
+import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
 import static org.apache.jackrabbit.oak.commons.PathUtils.concat;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NODE_TYPE;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexHookProvider.TYPE;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.OAK_MIXIN_SUBTYPES;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.OAK_PRIMARY_SUBTYPES;
 
 import java.io.Closeable;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -93,24 +100,32 @@ class Property2IndexHook implements Inde
      */
     private final Map<String, List<Property2IndexHookUpdate>> indexMap;
 
-    public Property2IndexHook(NodeBuilder root) {
-        this(null, root, null, "/",
-                new HashMap<String, List<Property2IndexHookUpdate>>());
+    /**
+     * The {@code /jcr:system/jcr:nodeTypes} subtree.
+     */
+    private final NodeState types;
+
+    public Property2IndexHook(NodeBuilder builder, NodeState root) {
+        this(null, builder, null, "/",
+                new HashMap<String, List<Property2IndexHookUpdate>>(),
+                root.getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES));
     }
 
     private Property2IndexHook(Property2IndexHook parent, String nodeName) {
         this(parent, getChildNode(parent.node, nodeName), nodeName, null,
-                parent.indexMap);
+                parent.indexMap, parent.types);
     }
 
     private Property2IndexHook(Property2IndexHook parent, NodeBuilder node,
             String nodeName, String path,
-            Map<String, List<Property2IndexHookUpdate>> indexMap) {
+            Map<String, List<Property2IndexHookUpdate>> indexMap,
+            NodeState types) {
         this.parent = parent;
         this.node = node;
         this.nodeName = nodeName;
         this.path = path;
         this.indexMap = indexMap;
+        this.types = types;
     }
 
     private static NodeBuilder getChildNode(NodeBuilder node, String name) {
@@ -143,21 +158,8 @@ class Property2IndexHook implements Inde
         }
         List<Property2IndexHookUpdate> filtered = new ArrayList<Property2IndexHookUpdate>();
         for (Property2IndexHookUpdate pi : indexes) {
-            if (node == null || pi.getNodeTypeNames() == null
-                    || pi.getNodeTypeNames().isEmpty()) {
+            if (node == null || pi.matchesNodeType(node)) {
                 filtered.add(pi);
-                continue;
-            }
-            PropertyState ps = node.getProperty(JCR_PRIMARYTYPE);
-            String type = ps != null && !ps.isArray() ? ps
-                    .getValue(Type.STRING) : null;
-            if (type != null) {
-                for (String typeName : pi.getNodeTypeNames()) {
-                    if (typeName.equals(type)) {
-                        filtered.add(pi);
-                        break;
-                    }
-                }
             }
         }
         return filtered;
@@ -173,15 +175,21 @@ class Property2IndexHook implements Inde
      *            the name of the index
      */
     private void addIndexes(NodeState state, String indexName) {
-        List<String> typeNames = ImmutableList.of();
-        PropertyState appliesTo = state.getProperty(declaringNodeTypes);
-        if (appliesTo != null) {
-            typeNames = newArrayList(appliesTo.getValue(Type.STRINGS));
-            Collections.sort(typeNames);
+        Set<String> primaryTypes = newHashSet();
+        Set<String> mixinTypes = newHashSet();
+        for (String typeName : state.getNames(declaringNodeTypes)) {
+            NodeState type = types.getChildNode(typeName);
+            if (type.getBoolean(JCR_ISMIXIN)) {
+                mixinTypes.add(typeName);
+            } else {
+                primaryTypes.add(typeName);
+            }
+            addAll(primaryTypes, type.getNames(OAK_PRIMARY_SUBTYPES));
+            addAll(mixinTypes, type.getNames(OAK_MIXIN_SUBTYPES));
         }
-        PropertyState ps = state.getProperty(propertyNames);
 
-        Iterable<String> propertyNames = ps != null ? ps.getValue(Type.STRINGS)
+        PropertyState ps = state.getProperty(propertyNames);
+        Iterable<String> propertyNames = ps != null ? ps.getValue(Type.NAMES)
                 : ImmutableList.of(indexName);
         for (String pname : propertyNames) {
             List<Property2IndexHookUpdate> list = this.indexMap.get(pname);
@@ -192,8 +200,7 @@ class Property2IndexHook implements Inde
             boolean exists = false;
             String localPath = getPath();
             for (Property2IndexHookUpdate piu : list) {
-                if (localPath.equals(piu.getPath())
-                        && typeNames.equals(piu.getNodeTypeNames())) {
+                if (piu.matches(localPath, primaryTypes, mixinTypes)) {
                     exists = true;
                     break;
                 }
@@ -201,7 +208,7 @@ class Property2IndexHook implements Inde
             if (!exists) {
                 Property2IndexHookUpdate update = new Property2IndexHookUpdate(
                         getPath(), node.child(INDEX_DEFINITIONS_NAME).child(indexName),
-                        store, typeNames);
+                        store, primaryTypes, mixinTypes);
                 list.add(update);
                 updates.add(update);
             }
@@ -296,7 +303,7 @@ class Property2IndexHook implements Inde
             }
         }
         if (reindex) {
-            return new Property2IndexHook(node);
+            return new Property2IndexHook(node, types);
         }
         return null;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookProvider.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookProvider.java
Wed Apr 24 08:25:18 2013
@@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.jackrabbit.oak.plugins.index.IndexHook;
 import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import com.google.common.collect.ImmutableList;
 
@@ -40,10 +41,10 @@ public class Property2IndexHookProvider 
     public static final String TYPE = "p2";
 
     @Override
-    public List<? extends IndexHook> getIndexHooks(String type,
-            NodeBuilder builder) {
+    public List<? extends IndexHook> getIndexHooks(
+            String type, NodeBuilder builder, NodeState root) {
         if (TYPE.equals(type)) {
-            return ImmutableList.of(new Property2IndexHook(builder));
+            return ImmutableList.of(new Property2IndexHook(builder, root));
         }
         return ImmutableList.of();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookUpdate.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookUpdate.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexHookUpdate.java
Wed Apr 24 08:25:18 2013
@@ -16,11 +16,12 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.p2;
 
+import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
+import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
 import static org.apache.jackrabbit.oak.plugins.index.p2.Property2Index.encode;
 
 import java.util.Collections;
-import java.util.List;
 import java.util.Set;
 
 import javax.jcr.PropertyType;
@@ -50,11 +51,16 @@ class Property2IndexHookUpdate {
     private final String path;
 
     /**
-     * The node types that this index applies to. If <code>null</code> or
-     * <code>empty</code> then the node type of the indexed node is ignored
-     * 
+     * Primary node types that this index applies to. If <code>null</code>
+     * then the node type of the indexed node is ignored
      */
-    private final List<String> nodeTypeNames;
+    private final Set<String> primaryTypes;
+
+    /**
+     * Mixin node types that this index applies to. If <code>null</code>
+     * then the node type of the indexed node is ignored
+     */
+    private final Set<String> mixinTypes;
 
     /**
      * The node where the index definition is stored.
@@ -70,12 +76,21 @@ class Property2IndexHookUpdate {
 
     private final Set<String> modifiedKeys = Sets.newHashSet();
 
-    public Property2IndexHookUpdate(String path, NodeBuilder node,
-            IndexStoreStrategy store, List<String> nodeTypeNames) {
+    public Property2IndexHookUpdate(
+            String path, NodeBuilder node, IndexStoreStrategy store,
+            Set<String> primaryTypes, Set<String> mixinTypes) {
         this.path = path;
         this.node = node;
         this.store = store;
-        this.nodeTypeNames = nodeTypeNames;
+
+        if (primaryTypes.isEmpty() && mixinTypes.isEmpty()) {
+            this.primaryTypes = null;
+            this.mixinTypes = null;
+        } else {
+            this.primaryTypes = primaryTypes;
+            this.mixinTypes = mixinTypes;
+        }
+
         index = this.node.child(":index");
         PropertyState uniquePS = node.getProperty("unique");
         unique = uniquePS != null && !uniquePS.isArray()
@@ -86,10 +101,6 @@ class Property2IndexHookUpdate {
         return path;
     }
 
-    List<String> getNodeTypeNames() {
-        return nodeTypeNames;
-    }
-
     /**
      * A property value was added at the given path.
      * 
@@ -158,4 +169,32 @@ class Property2IndexHookUpdate {
         return reindex;
     }
 
+    public boolean matches(
+            String path, Set<String> primaryTypes, Set<String> mixinTypes) {
+        if (this.primaryTypes == null) {
+            return this.path.equals(path)
+                    && primaryTypes.isEmpty()
+                    && mixinTypes.isEmpty();
+        } else {
+            return this.path.equals(path)
+                    && this.primaryTypes.equals(primaryTypes)
+                    && this.mixinTypes.equals(mixinTypes);
+        }
+    }
+
+    public boolean matchesNodeType(NodeBuilder node) {
+        if (primaryTypes == null
+                || primaryTypes.contains(node.getName(JCR_PRIMARYTYPE))) {
+            return true;
+        }
+        if (!mixinTypes.isEmpty()) {
+            for (String mixinName : node.getNames(JCR_MIXINTYPES)) {
+                if (mixinTypes.contains(mixinName)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexLookup.java
Wed Apr 24 08:25:18 2013
@@ -151,11 +151,13 @@ public class Property2IndexLookup {
             }
             if (contains(ns.getNames(PROPERTY_NAMES), propertyName)) {
                 NodeState index = ns.getChildNode(":index");
-                if (ns.hasProperty(DECLARING_NODE_TYPES) && supertypes != null) {
-                    for (String typeName : ns.getNames(DECLARING_NODE_TYPES)) {
-                        if (supertypes.contains(typeName)) {
-                            // TODO: prefer the most specific type restriction
-                            return index;
+                if (ns.hasProperty(DECLARING_NODE_TYPES)) {
+                    if (supertypes != null) {
+                        for (String typeName : ns.getNames(DECLARING_NODE_TYPES)) {
+                            if (supertypes.contains(typeName)) {
+                                // TODO: prefer the most specific type restriction
+                                return index;
+                            }
                         }
                     }
                 } else if (supertypes == null) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexTest.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexTest.java
Wed Apr 24 08:25:18 2013
@@ -75,7 +75,7 @@ public class Property2IndexTest {
         }
         NodeState after = builder.getNodeState();
 
-        EditorDiff.process(new Property2IndexHook(builder), before, after);
+        EditorDiff.process(new Property2IndexHook(builder, after), before, after);
         NodeState indexed = builder.getNodeState();
 
         FilterImpl f = createFilter(indexed, NT_BASE);
@@ -129,7 +129,7 @@ public class Property2IndexTest {
         NodeState after = builder.getNodeState();
 
         // Add an index
-        EditorDiff.process(new Property2IndexHook(builder), before, after);
+        EditorDiff.process(new Property2IndexHook(builder, after), before, after);
         NodeState indexed = builder.getNodeState();
 
         FilterImpl f = createFilter(indexed, NT_BASE);
@@ -190,7 +190,7 @@ public class Property2IndexTest {
                 .setProperty("foo", Arrays.asList("abc", "def"), Type.STRINGS);
         NodeState after = builder.getNodeState();
 
-        EditorDiff.process(new Property2IndexHook(builder), before, after);
+        EditorDiff.process(new Property2IndexHook(builder, after), before, after);
         NodeState indexed = builder.getNodeState();
 
         FilterImpl f = createFilter(indexed, "nt:unstructured");
@@ -256,7 +256,7 @@ public class Property2IndexTest {
         NodeState after = builder.getNodeState();
 
         // Add an index
-        EditorDiff.process(new Property2IndexHook(builder), before, after);
+        EditorDiff.process(new Property2IndexHook(builder, after), before, after);
         NodeState indexed = builder.getNodeState();
 
         FilterImpl f = createFilter(after, "nt:unstructured");
@@ -298,7 +298,7 @@ public class Property2IndexTest {
         NodeState after = builder.getNodeState();
 
         CommitFailedException expected =
-                EditorDiff.process(new Property2IndexHook(builder), before, after);
+                EditorDiff.process(new Property2IndexHook(builder, after), before, after);
         assertNotNull("Unique constraint should be respected", expected);
     }
 
@@ -327,7 +327,7 @@ public class Property2IndexTest {
         NodeState after = builder.getNodeState();
 
         CommitFailedException unexpected = EditorDiff.process(
-                new Property2IndexHook(builder), before, after);
+                new Property2IndexHook(builder, after), before, after);
         assertNull(unexpected);
     }
 
@@ -355,8 +355,8 @@ public class Property2IndexTest {
                 .setProperty("foo", "abc");
         NodeState after = builder.getNodeState();
 
-        CommitFailedException expected =
-                EditorDiff.process(new Property2IndexHook(builder), before, after);
+        CommitFailedException expected = EditorDiff.process(
+                new Property2IndexHook(builder, after), before, after);
         assertNotNull("Unique constraint should be respected", expected);
     }
 
@@ -386,7 +386,7 @@ public class Property2IndexTest {
         NodeState after = builder.getNodeState();
 
         CommitFailedException unexpected = EditorDiff.process(
-                new Property2IndexHook(builder), before, after);
+                new Property2IndexHook(builder, after), before, after);
         assertNull(unexpected);
     }
 

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexHookProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexHookProvider.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexHookProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexHookProvider.java
Wed Apr 24 08:25:18 2013
@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.jackrabbit.oak.plugins.index.IndexHook;
 import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import com.google.common.collect.ImmutableList;
 
@@ -40,8 +41,8 @@ import com.google.common.collect.Immutab
 public class LuceneIndexHookProvider implements IndexHookProvider {
 
     @Override
-    public List<? extends IndexHook> getIndexHooks(String type,
-            NodeBuilder builder) {
+    public List<? extends IndexHook> getIndexHooks(
+            String type, NodeBuilder builder, NodeState root) {
         if (TYPE_LUCENE.equals(type)) {
             return ImmutableList.of(new LuceneIndexDiff(builder));
         }

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHookProvider.java
Wed Apr 24 08:25:18 2013
@@ -30,6 +30,7 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.index.solr.SolrServerProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -62,8 +63,8 @@ public class SolrIndexHookProvider imple
 
     @Override
     @Nonnull
-    public List<? extends IndexHook> getIndexHooks(String type, NodeBuilder builder)
{
-
+    public List<? extends IndexHook> getIndexHooks(
+            String type, NodeBuilder builder, NodeState root) {
         if (SolrQueryIndex.TYPE.equals(type) && solrServerProvider != null &&
oakSolrConfigurationProvider != null) {
             try {
                 if (log.isDebugEnabled()) {

Modified: jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java?rev=1471288&r1=1471287&r2=1471288&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
(original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/solr/TestUtils.java
Wed Apr 24 08:25:18 2013
@@ -71,7 +71,8 @@ public class TestUtils {
         return new IndexHookProvider() {
             @Nonnull
             @Override
-            public List<? extends IndexHook> getIndexHooks(String s, NodeBuilder nodeBuilder)
{
+            public List<? extends IndexHook> getIndexHooks(
+                    String s, NodeBuilder nodeBuilder, NodeState root) {
                 if (SolrQueryIndex.TYPE.equals(s)) {
                     try {
                         IndexHook indexHook = new SolrIndexDiff(nodeBuilder, solrServer,
configuration);



Mime
View raw message