jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1475754 [1/2] - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/ 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/a...
Date Thu, 25 Apr 2013 13:20:24 GMT
Author: alexparvulescu
Date: Thu Apr 25 13:20:23 2013
New Revision: 1475754

URL: http://svn.apache.org/r1475754
Log:
OAK-734 Refactor indexing code to use Editors

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexEditorProvider.java   (contents, props changed)
      - copied, changed from r1475736, 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/CompositeIndexEditorProvider.java   (contents, props changed)
      - copied, changed from r1475701, 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/IndexEditor.java   (contents, props changed)
      - copied, changed from r1475701, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java   (contents, props changed)
      - copied, changed from r1475701, 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/IndexUpdate.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java   (with props)
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java   (with props)
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java   (contents, props changed)
      - copied, changed from r1475736, jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexHookProvider.java
Removed:
    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/IndexHook.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/test/java/org/apache/jackrabbit/oak/plugins/index/IndexHookManagerTest.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexHookProvider.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
    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/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/spi/lifecycle/OakInitializer.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/p2/Property2IndexTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/LuceneOakRepositoryStub.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java
    jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.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/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrNodeStateDiff.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/Oak.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java Thu Apr 25 13:20:23 2013
@@ -38,9 +38,9 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.apache.jackrabbit.oak.plugins.commit.ConflictHook;
-import org.apache.jackrabbit.oak.plugins.index.CompositeIndexHookProvider;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookManager;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.observation2.EventQueueWriterProvider;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeEditorProvider;
@@ -82,7 +82,7 @@ public class Oak {
 
     private final List<QueryIndexProvider> queryIndexProviders = newArrayList();
 
-    private final List<IndexHookProvider> indexHookProviders = newArrayList();
+    private final List<IndexEditorProvider> indexHookProviders = newArrayList();
 
     private final List<CommitHook> commitHooks = newArrayList();
 
@@ -147,7 +147,7 @@ public class Oak {
      * @return this builder
      */
     @Nonnull
-    public Oak with(@Nonnull IndexHookProvider provider) {
+    public Oak with(@Nonnull IndexEditorProvider provider) {
         indexHookProviders.add(provider);
         return this;
     }
@@ -243,7 +243,7 @@ public class Oak {
     }
 
     public ContentRepository createContentRepository() {
-        IndexHookProvider indexHooks = CompositeIndexHookProvider.compose(indexHookProviders);
+        IndexEditorProvider indexHooks = CompositeIndexEditorProvider.compose(indexHookProviders);
         OakInitializer.initialize(store, new CompositeInitializer(initializers), indexHooks);
 
         QueryIndexProvider indexProvider = CompositeQueryIndexProvider.compose(queryIndexProviders);
@@ -267,7 +267,7 @@ public class Oak {
                 CompositeHook.compose(initHooks));
 
         // add index hooks later to prevent the OakInitializer to do excessive indexing
-        with(IndexHookManager.of(indexHooks));
+        with(new IndexUpdateProvider(indexHooks));
         with(new EventQueueWriterProvider());
         withEditorHook();
         CommitHook commitHook = CompositeHook.compose(commitHooks);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java Thu Apr 25 13:20:23 2013
@@ -50,7 +50,7 @@ public class Activator implements Bundle
 
     private final OsgiIndexProvider indexProvider = new OsgiIndexProvider();
 
-    private final OsgiIndexHookProvider indexHookProvider = new OsgiIndexHookProvider();
+    private final OsgiIndexEditorProvider indexEditorProvider = new OsgiIndexEditorProvider();
 
     private final OsgiEditorProvider validatorProvider = new OsgiEditorProvider();
 
@@ -65,7 +65,7 @@ public class Activator implements Bundle
         context = bundleContext;
 
         indexProvider.start(bundleContext);
-        indexHookProvider.start(bundleContext);
+        indexEditorProvider.start(bundleContext);
         validatorProvider.start(bundleContext);
         repositoryInitializerTracker.setObserver(this);
         repositoryInitializerTracker.start(bundleContext);
@@ -82,7 +82,7 @@ public class Activator implements Bundle
         // nodeStoreTracker.close();
         microKernelTracker.close();
         indexProvider.stop();
-        indexHookProvider.stop();
+        indexEditorProvider.stop();
         validatorProvider.stop();
         repositoryInitializerTracker.stop();
     }
@@ -100,13 +100,13 @@ public class Activator implements Bundle
                     new Properties()));
         } else if (service instanceof NodeStore) {
             NodeStore store = (NodeStore) service;
-            OakInitializer.initialize(store, repositoryInitializerTracker, indexHookProvider);
+            OakInitializer.initialize(store, repositoryInitializerTracker, indexEditorProvider);
             Oak oak = new Oak(store)
                 // FIXME: proper osgi setup for security provider (see OAK-17 and sub-tasks)
                 .with(new SecurityProviderImpl())
                 .with(validatorProvider)
                 .with(indexProvider)
-                .with(indexHookProvider);
+                .with(indexEditorProvider);
             services.put(reference, context.registerService(
                     ContentRepository.class.getName(),
                     oak.createContentRepository(),
@@ -136,7 +136,7 @@ public class Activator implements Bundle
             if (service instanceof ContentRepositoryImpl) {
                 ContentRepositoryImpl repository = (ContentRepositoryImpl) service;
                 OakInitializer.initialize(repository.getNodeStore(), ri,
-                        indexHookProvider);
+                        indexEditorProvider);
             }
         }
     }

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexEditorProvider.java (from r1475736, 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/OsgiIndexEditorProvider.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexEditorProvider.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexHookProvider.java&r1=1475736&r2=1475754&rev=1475754&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/OsgiIndexEditorProvider.java Thu Apr 25 13:20:23 2013
@@ -18,33 +18,30 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
-import java.util.List;
-
-import javax.annotation.Nonnull;
-
-import org.apache.jackrabbit.oak.plugins.index.CompositeIndexHookProvider;
-import org.apache.jackrabbit.oak.plugins.index.IndexHook;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
 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
- * IndexHook providers.
+ * This IndexEditor provider combines all index editors of all available OSGi
+ * IndexEditor providers.
  */
-public class OsgiIndexHookProvider extends
-        AbstractServiceTracker<IndexHookProvider> implements IndexHookProvider {
+public class OsgiIndexEditorProvider extends
+        AbstractServiceTracker<IndexEditorProvider> implements IndexEditorProvider {
 
-    public OsgiIndexHookProvider() {
-        super(IndexHookProvider.class);
+    public OsgiIndexEditorProvider() {
+        super(IndexEditorProvider.class);
     }
 
     @Override
-    @Nonnull
-    public List<? extends IndexHook> getIndexHooks(
-            String type, NodeBuilder builder, NodeState root) {
-        IndexHookProvider composite = CompositeIndexHookProvider.compose(getServices());
-        return composite.getIndexHooks(type, builder, root);
+    public Editor getIndexEditor(String type, NodeBuilder builder) {
+        IndexEditorProvider composite = CompositeIndexEditorProvider
+                .compose(getServices());
+        if (composite == null) {
+            return null;
+        }
+        return composite.getIndexEditor(type, builder);
     }
 
 }

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexEditorProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexEditorProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexEditorProvider.java (from r1475701, 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/CompositeIndexEditorProvider.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexEditorProvider.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexHookProvider.java&r1=1475701&r2=1475754&rev=1475754&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/CompositeIndexEditorProvider.java Thu Apr 25 13:20:23 2013
@@ -22,54 +22,56 @@ import java.util.List;
 
 import javax.annotation.Nonnull;
 
+import org.apache.jackrabbit.oak.spi.commit.CompositeEditor;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
+import org.apache.jackrabbit.oak.spi.commit.VisibleEditor;
 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;
 
 /**
- * TODO document
+ * Aggregation of a list of editor providers into a single provider.
  */
-public class CompositeIndexHookProvider implements IndexHookProvider {
+public class CompositeIndexEditorProvider implements IndexEditorProvider {
 
     @Nonnull
-    public static IndexHookProvider compose(
-            @Nonnull Collection<IndexHookProvider> providers) {
+    public static IndexEditorProvider compose(
+            @Nonnull Collection<IndexEditorProvider> providers) {
         if (providers.isEmpty()) {
-            return new IndexHookProvider() {
+            return new IndexEditorProvider() {
                 @Override
-                public List<? extends IndexHook> getIndexHooks(
-                        String type, NodeBuilder builder, NodeState root) {
-                    return ImmutableList.of();
+                public Editor getIndexEditor(String type, NodeBuilder builder) {
+                    return null;
                 }
             };
         } else if (providers.size() == 1) {
             return providers.iterator().next();
         } else {
-            return new CompositeIndexHookProvider(
+            return new CompositeIndexEditorProvider(
                     ImmutableList.copyOf(providers));
         }
     }
 
-    private final List<IndexHookProvider> providers;
+    private final List<IndexEditorProvider> providers;
 
-    private CompositeIndexHookProvider(List<IndexHookProvider> providers) {
+    private CompositeIndexEditorProvider(List<IndexEditorProvider> providers) {
         this.providers = providers;
     }
 
-    public CompositeIndexHookProvider(IndexHookProvider... providers) {
+    public CompositeIndexEditorProvider(IndexEditorProvider... providers) {
         this(Arrays.asList(providers));
     }
 
     @Override
-    @Nonnull
-    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, root));
+    public Editor getIndexEditor(String type, NodeBuilder builder) {
+        List<Editor> indexes = Lists.newArrayList();
+        for (IndexEditorProvider provider : providers) {
+            Editor e = provider.getIndexEditor(type, builder);
+            if (e != null) {
+                indexes.add(e);
+            }
         }
-        return indexes;
+        return VisibleEditor.wrap(CompositeEditor.compose(indexes));
     }
 }

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexEditorProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/CompositeIndexEditorProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditor.java (from r1475701, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHook.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditor.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditor.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHook.java&r1=1475701&r2=1475754&rev=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHook.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditor.java Thu Apr 25 13:20:23 2013
@@ -16,40 +16,14 @@
  */
 package org.apache.jackrabbit.oak.plugins.index;
 
-import javax.annotation.CheckForNull;
-
-import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
  * Represents the content of a QueryIndex as well as a mechanism for keeping
  * this content up to date. <br>
- * An IndexHook listens for changes to the content and updates the index data
+ * An IndexEditor listens for changes to the content and updates the index data
  * accordingly.
  */
-public interface IndexHook extends Editor {
-
-    /**
-     * Return an editor that can be used to recreate this index, or
-     * <code>null</code> if reindexing is not required or is taken care of by
-     * the impl directly using the provided state as a reference <br>
-     * <br>
-     * By providing an Editor an impl could help the IndexManager gain some
-     * performance on account of doing the reindexing in parallel for all
-     * indexers <br>
-     * <br>
-     * <i>Note:</i> All the existing IndexHook impls require a call to
-     * {@link #enter(NodeState, NodeState)} to build initial state before
-     * calling {@link #reindex(NodeState)}, this is enforced via the
-     * IndexManager.
-     * 
-     * @param state
-     *            state can be used to reindex inside the IndexHook directly,
-     *            instead of providing an Editor
-     * 
-     */
-    @CheckForNull
-    Editor reindex(NodeState state) throws CommitFailedException;
+public interface IndexEditor extends Editor {
 
 }

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java (from r1475701, 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/IndexEditorProvider.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexHookProvider.java&r1=1475701&r2=1475754&rev=1475754&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/IndexEditorProvider.java Thu Apr 25 13:20:23 2013
@@ -16,44 +16,36 @@
  */
 package org.apache.jackrabbit.oak.plugins.index;
 
-import java.util.List;
-
-import javax.annotation.Nonnull;
+import javax.annotation.CheckForNull;
 
+import org.apache.jackrabbit.oak.spi.commit.Editor;
 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.
+ * Extension point for plugging in different kinds of IndexEditor providers.
  * 
- * @see IndexHook
+ * @see IndexEditor
  */
-public interface IndexHookProvider {
+public interface IndexEditorProvider {
 
     /**
      * 
      * Each provider knows how to produce a certain type of index. If the
      * <code>type</code> param is of an unknown value, the provider is expected
-     * to return an empty list.
+     * to return {@code null}.
      * 
      * <p>
-     * The <code>builder</code> must point to the repository content node, not
-     * the index content node. Each <code>IndexHook</code> implementation will
-     * have to drill down to its specific index content, and possibly deal with
-     * multiple indexes of the same type.
+     * The <code>builder</code> must points to the index definition node
+     * under which the indexer is expected to store the index content.
      * </p>
      * 
      * @param type
      *            the index type
      * @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
+     *            the node state builder of the index definition node that
+     *            will be used for updates
+     * @return index update editor, or {@code null} if type is unknown
      */
-    @Nonnull
-    List<? extends IndexHook> getIndexHooks(
-            String type, NodeBuilder builder, NodeState root);
-
+    @CheckForNull
+    Editor getIndexEditor(String type, NodeBuilder builder);
 }

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexEditorProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java?rev=1475754&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java Thu Apr 25 13:20:23 2013
@@ -0,0 +1,210 @@
+/*
+ * 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;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Lists.newArrayListWithCapacity;
+import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.ASYNC_PROPERTY_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.INDEX_DEFINITIONS_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.TYPE_PROPERTY_NAME;
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.commit.CompositeEditor;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
+import org.apache.jackrabbit.oak.spi.commit.EditorDiff;
+import org.apache.jackrabbit.oak.spi.commit.VisibleEditor;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+class IndexUpdate implements Editor {
+
+    private final IndexEditorProvider provider;
+
+    private final boolean async;
+
+    private final NodeState root;
+
+    private final NodeBuilder builder;
+
+    private final List<Editor> editors = newArrayList();
+
+    IndexUpdate(
+            IndexEditorProvider provider, boolean async,
+            NodeState root, NodeBuilder builder) {
+        this.provider = checkNotNull(provider);
+        this.async = async;
+        this.root = checkNotNull(root);
+        this.builder = checkNotNull(builder);
+    }
+
+    private IndexUpdate(IndexUpdate parent, String name) {
+        checkNotNull(parent);
+        this.provider = parent.provider;
+        this.async = parent.async;
+        this.root = parent.root;
+        this.builder = parent.builder.child(checkNotNull(name));
+    }
+
+    private static String getString(NodeBuilder builder, String name) {
+        PropertyState property = builder.getProperty(name);
+        if (property != null && property.getType() == STRING) {
+            return property.getValue(STRING);
+        } else {
+            return null;
+        }
+    }
+
+    private static boolean getBoolean(NodeBuilder builder, String name) {
+        PropertyState property = builder.getProperty(name);
+        return property != null
+                && property.getType() == BOOLEAN
+                && property.getValue(BOOLEAN);
+    }
+
+    @Override
+    public void enter(NodeState before, NodeState after)
+            throws CommitFailedException {
+        List<Editor> reindex = newArrayList();
+        if (builder.hasChildNode(INDEX_DEFINITIONS_NAME)) {
+            Map<String, Editor> tempEditors = new HashMap<String, Editor>();
+            NodeBuilder definitions = builder.child(INDEX_DEFINITIONS_NAME);
+            for (String name : definitions.getChildNodeNames()) {
+                NodeBuilder definition = definitions.child(name);
+                if (async == getBoolean(definition, ASYNC_PROPERTY_NAME)) {
+                    String type = getString(definition, TYPE_PROPERTY_NAME);
+                    Editor editor = null;
+                    if (tempEditors.containsKey(type)) {
+                        editor = tempEditors.get(type);
+                    } else {
+                        editor = provider.getIndexEditor(type, builder);
+                        tempEditors.put(type, editor);
+                    }
+
+                    if (editor == null) {
+                        // trigger reindexing when an indexer becomes available
+                        definition.setProperty(REINDEX_PROPERTY_NAME, true);
+                    } else if (getBoolean(definition, REINDEX_PROPERTY_NAME)) {
+                        definition.setProperty(REINDEX_PROPERTY_NAME, false);
+                        definition.removeChildNode(":index");
+                        reindex.add(editor);
+                    } else {
+                        editors.add(VisibleEditor.wrap(editor));
+                    }
+                }
+            }
+        }
+
+        // no-op when reindex is empty
+        CommitFailedException exception = EditorDiff.process(
+                VisibleEditor.wrap(CompositeEditor.compose(reindex)), MISSING_NODE, after);
+        if (exception != null) {
+            throw exception;
+        }
+
+        for (Editor editor : editors) {
+            editor.enter(before, after);
+        }
+    }
+
+    @Override
+    public void leave(NodeState before, NodeState after)
+            throws CommitFailedException {
+        for (Editor editor : editors) {
+            editor.leave(before, after);
+        }
+    }
+
+    @Override
+    public void propertyAdded(PropertyState after)
+            throws CommitFailedException {
+        for (Editor editor : editors) {
+            editor.propertyAdded(after);
+        }
+    }
+
+    @Override
+    public void propertyChanged(PropertyState before, PropertyState after)
+            throws CommitFailedException {
+        for (Editor editor : editors) {
+            editor.propertyChanged(before, after);
+        }
+    }
+
+    @Override
+    public void propertyDeleted(PropertyState before)
+            throws CommitFailedException {
+        for (Editor editor : editors) {
+            editor.propertyDeleted(before);
+        }
+    }
+
+    @Override @Nonnull
+    public Editor childNodeAdded(String name, NodeState after)
+            throws CommitFailedException {
+        List<Editor> children = newArrayListWithCapacity(1 + editors.size());
+        children.add(new IndexUpdate(this, name));
+        for (Editor editor : editors) {
+            Editor child = editor.childNodeAdded(name, after);
+            if (child != null) {
+                children.add(child);
+            }
+        }
+        return CompositeEditor.compose(children);
+    }
+
+    @Override @Nonnull
+    public Editor childNodeChanged(
+            String name, NodeState before, NodeState after)
+            throws CommitFailedException {
+        List<Editor> children = newArrayListWithCapacity(1 + editors.size());
+        children.add(new IndexUpdate(this, name));
+        for (Editor editor : editors) {
+            Editor child = editor.childNodeChanged(name, before, after);
+            if (child != null) {
+                children.add(child);
+            }
+        }
+        return CompositeEditor.compose(children);
+    }
+
+    @Override @CheckForNull
+    public Editor childNodeDeleted(String name, NodeState before)
+            throws CommitFailedException {
+        List<Editor> children = newArrayListWithCapacity(editors.size());
+        for (Editor editor : editors) {
+            Editor child = editor.childNodeDeleted(name, before);
+            if (child != null) {
+                children.add(child);
+            }
+        }
+        return CompositeEditor.compose(children);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java?rev=1475754&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java Thu Apr 25 13:20:23 2013
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import javax.annotation.CheckForNull;
+
+import org.apache.jackrabbit.oak.spi.commit.Editor;
+import org.apache.jackrabbit.oak.spi.commit.EditorProvider;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+public class IndexUpdateProvider implements EditorProvider {
+
+    private final IndexEditorProvider provider;
+
+    private final boolean async;
+
+    public IndexUpdateProvider(IndexEditorProvider provider) {
+        this(provider, false);
+    }
+
+    public IndexUpdateProvider(IndexEditorProvider provider, boolean async) {
+        this.provider = provider;
+        this.async = async;
+    }
+
+    @Override @CheckForNull
+    public Editor getRootEditor(
+            NodeState before, NodeState after, NodeBuilder builder) {
+        return new IndexUpdate(provider, async, after, builder);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=1475754&r1=1475753&r2=1475754&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 Thu Apr 25 13:20:23 2013
@@ -18,26 +18,14 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.nodetype;
 
-import java.util.Set;
-
-import javax.jcr.RepositoryException;
-import javax.jcr.nodetype.NodeType;
-import javax.jcr.nodetype.NodeTypeIterator;
-
 import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.core.ReadOnlyTree;
-import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
-import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
+import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexLookup;
 import org.apache.jackrabbit.oak.spi.query.Cursor;
 import org.apache.jackrabbit.oak.spi.query.Cursors;
 import org.apache.jackrabbit.oak.spi.query.Filter;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
-import com.google.common.collect.Sets;
-
 /**
  * <code>NodeTypeIndex</code> implements a {@link QueryIndex} using
  * {@link Property2IndexLookup}s on <code>jcr:primaryType</code> and

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=1475754&r1=1475753&r2=1475754&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 Thu Apr 25 13:20:23 2013
@@ -43,9 +43,10 @@ import java.util.Set;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.index.IndexHook;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
 import org.apache.jackrabbit.oak.plugins.index.p2.strategy.ContentMirrorStoreStrategy;
 import org.apache.jackrabbit.oak.plugins.index.p2.strategy.IndexStoreStrategy;
+import org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -54,7 +55,7 @@ import com.google.common.collect.Immutab
 import com.google.common.collect.Lists;
 
 /**
- * {@link IndexHook} implementation that is responsible for keeping the
+ * {@link IndexEditor} implementation that is responsible for keeping the
  * {@link Property2Index} up to date.
  * <br>
  * There is a tree of PropertyIndexDiff objects, each object represents the
@@ -63,7 +64,7 @@ import com.google.common.collect.Lists;
  * @see Property2Index
  * @see Property2IndexLookup
  */
-class Property2IndexHook implements IndexHook, Closeable {
+class Property2IndexHook implements IndexEditor, Closeable {
 
     protected static String propertyNames = "propertyNames";
 
@@ -77,7 +78,7 @@ class Property2IndexHook implements Inde
     private final Property2IndexHook parent;
 
     /**
-     * The node (never null).
+     * The node (can be null in the case of a deleted node).
      */
     private final NodeBuilder node;
 
@@ -101,36 +102,38 @@ class Property2IndexHook implements Inde
     private final Map<String, List<Property2IndexHookUpdate>> indexMap;
 
     /**
-     * The root node state.
-     */
-    private final NodeState root;
-
-    /**
      * 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);
+    public Property2IndexHook(NodeBuilder builder) {
+        this(null, builder, null, "/");
     }
 
     private Property2IndexHook(Property2IndexHook parent, String nodeName) {
-        this(parent, getChildNode(parent.node, nodeName), nodeName, null,
-                parent.indexMap, parent.root);
+        this(parent, getChildNode(parent.node, nodeName), nodeName, null);
     }
 
     private Property2IndexHook(Property2IndexHook parent, NodeBuilder node,
-            String nodeName, String path,
-            Map<String, List<Property2IndexHookUpdate>> indexMap,
-            NodeState root) {
+            String nodeName, String path) {
         this.parent = parent;
         this.node = node;
         this.nodeName = nodeName;
         this.path = path;
-        this.indexMap = indexMap;
-        this.root = root;
-        this.types = root.getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
+
+        if (parent == null) {
+            this.indexMap = new HashMap<String, List<Property2IndexHookUpdate>>();
+            if (node.hasChildNode(JCR_SYSTEM)) {
+                NodeBuilder typeNB = node.getChildNode(JCR_SYSTEM)
+                        .getChildNode(JCR_NODE_TYPES);
+                this.types = typeNB.getNodeState();
+            } else {
+                this.types = EmptyNodeState.MISSING_NODE;
+            }
+        } else {
+            this.indexMap = parent.indexMap;
+            this.types = parent.types;
+        }
     }
 
     private static NodeBuilder getChildNode(NodeBuilder node, String name) {
@@ -297,22 +300,6 @@ class Property2IndexHook implements Inde
         return childNodeChanged(name, before, EMPTY_NODE);
     }
 
-    @Override
-    public Editor reindex(NodeState state) {
-        boolean reindex = false;
-        for (List<Property2IndexHookUpdate> updateList : indexMap.values()) {
-            for (Property2IndexHookUpdate update : updateList) {
-                if (update.getAndResetReindexFlag()) {
-                    reindex = true;
-                }
-            }
-        }
-        if (reindex) {
-            return new Property2IndexHook(node, root);
-        }
-        return null;
-    }
-
     // -----------------------------------------------------< Closeable >--
 
     @Override

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=1475754&r1=1475753&r2=1475754&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 Thu Apr 25 13:20:23 2013
@@ -16,37 +16,31 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.p2;
 
-import java.util.List;
-
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
-import org.apache.jackrabbit.oak.plugins.index.IndexHook;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
-
-import com.google.common.collect.ImmutableList;
 
 /**
  * Service that provides PropertyIndex based IndexHooks.
  * 
  * @see Property2IndexHook
- * @see IndexHookProvider
+ * @see IndexEditorProvider
  * 
  */
 @Component
-@Service(IndexHookProvider.class)
-public class Property2IndexHookProvider implements IndexHookProvider {
+@Service(IndexEditorProvider.class)
+public class Property2IndexHookProvider implements IndexEditorProvider {
 
     public static final String TYPE = "p2";
 
     @Override
-    public List<? extends IndexHook> getIndexHooks(
-            String type, NodeBuilder builder, NodeState root) {
+    public Editor getIndexEditor(String type, NodeBuilder builder) {
         if (TYPE.equals(type)) {
-            return ImmutableList.of(new Property2IndexHook(builder, root));
+            return new Property2IndexHook(builder);
         }
-        return ImmutableList.of();
+        return null;
     }
 
 }
\ No newline at end of file

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=1475754&r1=1475753&r2=1475754&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 Thu Apr 25 13:20:23 2013
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.plugin
 
 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;
@@ -161,14 +160,6 @@ class Property2IndexHookUpdate {
         return path;
     }
 
-    boolean getAndResetReindexFlag() {
-        PropertyState reindexPS = node.getProperty(REINDEX_PROPERTY_NAME);
-        boolean reindex = reindexPS == null
-                || (reindexPS != null && reindexPS.getValue(Type.BOOLEAN));
-        node.setProperty(REINDEX_PROPERTY_NAME, false);
-        return reindex;
-    }
-
     public boolean matches(
             String path, Set<String> primaryTypes, Set<String> mixinTypes) {
         if (this.primaryTypes == null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/OakInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/OakInitializer.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/OakInitializer.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/OakInitializer.java Thu Apr 25 13:20:23 2013
@@ -21,8 +21,8 @@ package org.apache.jackrabbit.oak.spi.li
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookManager;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.EditorHook;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
@@ -37,12 +37,12 @@ public final class OakInitializer {
 
     public static void initialize(@Nonnull NodeStore store,
                                   @Nonnull RepositoryInitializer initializer,
-                                  @Nonnull IndexHookProvider indexHook) {
+                                  @Nonnull IndexEditorProvider indexHook) {
         NodeStoreBranch branch = store.branch();
         NodeState before = branch.getHead();
         branch.setRoot(initializer.initialize(before));
         try {
-            branch.merge(new EditorHook(IndexHookManager.of(indexHook)));
+            branch.merge(new EditorHook(new IndexUpdateProvider(indexHook)));
         } catch (CommitFailedException e) {
             throw new RuntimeException(e);
         }
@@ -51,7 +51,7 @@ public final class OakInitializer {
     public static void initialize(@Nonnull Iterable<WorkspaceInitializer> initializer,
                                   @Nonnull NodeStore store,
                                   @Nonnull String workspaceName,
-                                  @Nonnull IndexHookProvider indexHook,
+                                  @Nonnull IndexEditorProvider indexHook,
                                   @Nonnull QueryIndexProvider indexProvider,
                                   @Nonnull CommitHook commitHook) {
         NodeStoreBranch branch = store.branch();
@@ -61,7 +61,7 @@ public final class OakInitializer {
         }
         branch.setRoot(root);
         try {
-            branch.merge(new EditorHook(IndexHookManager.of(indexHook)));
+            branch.merge(new EditorHook(new IndexUpdateProvider(indexHook)));
         } catch (CommitFailedException e) {
             throw new RuntimeException(e);
         }

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java?rev=1475754&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java Thu Apr 25 13:20:23 2013
@@ -0,0 +1,218 @@
+/*
+ * 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;
+
+import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
+import static org.apache.jackrabbit.JcrConstants.NT_BASE;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.REINDEX_PROPERTY_NAME;
+import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.createIndexDefinition;
+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.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexLookup;
+import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
+import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
+import org.apache.jackrabbit.oak.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.commit.EditorHook;
+import org.apache.jackrabbit.oak.spi.query.Filter;
+import org.apache.jackrabbit.oak.spi.query.PropertyValues;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
+
+public class IndexUpdateTest {
+
+    private NodeState root = new InitialContent().initialize(EMPTY_NODE);
+
+    private NodeBuilder builder = root.builder();
+
+    /**
+     * Simple Test
+     * <ul>
+     * <li>Add an index definition</li>
+     * <li>Add some content</li>
+     * <li>Search & verify</li>
+     * </ul>
+     * 
+     */
+    @Test
+    public void test() throws Exception {
+        createIndexDefinition(builder.child("oak:index"), "rootIndex", true,
+                false, ImmutableSet.of("foo"), null);
+        createIndexDefinition(
+                builder.child("newchild").child("other").child("oak:index"),
+                "subIndex", true, false, ImmutableSet.of("foo"), null);
+
+        NodeState before = builder.getNodeState();
+
+        // Add nodes
+        builder.child("testRoot").setProperty("foo", "abc");
+        builder.child("newchild").child("other").child("testChild")
+                .setProperty("foo", "xyz");
+
+        NodeState after = builder.getNodeState();
+
+        IndexUpdateProvider p = new IndexUpdateProvider(
+                new Property2IndexHookProvider());
+        EditorHook hook = new EditorHook(p);
+        NodeState indexed = hook.processCommit(before, after);
+
+        // first check that the index content nodes exist
+        checkPathExists(indexed, "oak:index", "rootIndex", ":index");
+        checkPathExists(indexed, "newchild", "other", "oak:index", "subIndex",
+                ":index");
+
+        Property2IndexLookup lookup = new Property2IndexLookup(indexed);
+        assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
+
+        Property2IndexLookup lookupChild = new Property2IndexLookup(indexed
+                .getChildNode("newchild").getChildNode("other"));
+        assertEquals(ImmutableSet.of("testChild"),
+                find(lookupChild, "foo", "xyz"));
+        assertEquals(ImmutableSet.of(), find(lookupChild, "foo", "abc"));
+
+    }
+
+    /**
+     * Reindex Test
+     * <ul>
+     * <li>Add some content</li>
+     * <li>Add an index definition with the reindex flag set</li>
+     * <li>Search & verify</li>
+     * </ul>
+     */
+    @Test
+    public void testReindex() throws Exception {
+        builder.child("testRoot").setProperty("foo", "abc");
+        NodeState before = builder.getNodeState();
+        createIndexDefinition(builder.child("oak:index"), "rootIndex", true,
+                false, ImmutableSet.of("foo"), null);
+
+        NodeState after = builder.getNodeState();
+
+        IndexUpdateProvider p = new IndexUpdateProvider(
+                new Property2IndexHookProvider());
+        EditorHook hook = new EditorHook(p);
+        NodeState indexed = hook.processCommit(before, after);
+
+        // first check that the index content nodes exist
+        NodeState ns = checkPathExists(indexed, "oak:index", "rootIndex");
+        checkPathExists(ns, ":index");
+        PropertyState ps = ns.getProperty(REINDEX_PROPERTY_NAME);
+        assertNotNull(ps);
+        assertFalse(ps.getValue(Type.BOOLEAN));
+
+        // next, lookup
+        Property2IndexLookup lookup = new Property2IndexLookup(indexed);
+        assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
+    }
+
+    /**
+     * Reindex Test
+     * <ul>
+     * <li>Add some content & an index definition</li>
+     * <li>Update the index def by setting the reindex flag to true</li>
+     * <li>Search & verify</li>
+     * </ul>
+     */
+    @Test
+    public void testReindex2() throws Exception {
+        builder.child("testRoot").setProperty("foo", "abc");
+
+        createIndexDefinition(builder.child("oak:index"), "rootIndex", true,
+                false, ImmutableSet.of("foo"), null).removeProperty("reindex");
+
+        NodeState before = builder.getNodeState();
+        builder.child("oak:index").child("rootIndex")
+                .setProperty(REINDEX_PROPERTY_NAME, true);
+        NodeState after = builder.getNodeState();
+
+        IndexUpdateProvider p = new IndexUpdateProvider(
+                new Property2IndexHookProvider());
+        EditorHook hook = new EditorHook(p);
+        NodeState indexed = hook.processCommit(before, after);
+
+        // first check that the index content nodes exist
+        NodeState ns = checkPathExists(indexed, "oak:index", "rootIndex");
+        checkPathExists(ns, ":index");
+        PropertyState ps = ns.getProperty(REINDEX_PROPERTY_NAME);
+        assertNotNull(ps);
+        assertFalse(ps.getValue(Type.BOOLEAN));
+
+        // next, lookup
+        Property2IndexLookup lookup = new Property2IndexLookup(indexed);
+        assertEquals(ImmutableSet.of("testRoot"), find(lookup, "foo", "abc"));
+    }
+
+    @Test
+    public void testIndexDefinitions() throws Exception {
+        createIndexDefinition(builder.child("oak:index"), "existing", true,
+                false, ImmutableSet.of("foo"), null);
+
+        NodeState before = builder.getNodeState();
+        // Add index definition
+        createIndexDefinition(builder.child("oak:index"), "foo", true, false,
+                ImmutableSet.of("foo"), null);
+        createIndexDefinition(
+                builder.child("test").child("other").child("oak:index"),
+                "index2", true, false, ImmutableSet.of("foo"), null);
+        NodeState after = builder.getNodeState();
+
+        IndexUpdateProvider p = new IndexUpdateProvider(
+                new Property2IndexHookProvider());
+        EditorHook hook = new EditorHook(p);
+        NodeState indexed = hook.processCommit(before, after);
+
+        // check that the index content nodes exist
+        checkPathExists(indexed, "oak:index", "existing", ":index");
+        checkPathExists(indexed, "test", "other", "oak:index", "index2",
+                ":index");
+    }
+
+    private Set<String> find(Property2IndexLookup lookup, String name,
+            String value) {
+        NodeState system = root.getChildNode(JCR_SYSTEM);
+        NodeState types = system.getChildNode(JCR_NODE_TYPES);
+        NodeState type = types.getChildNode(NT_BASE);
+        SelectorImpl selector = new SelectorImpl(type, NT_BASE);
+        Filter filter = new FilterImpl(selector, "SELECT * FROM [nt:base]");
+        return Sets.newHashSet(lookup.query(filter, name,
+                PropertyValues.newString(value)));
+    }
+
+    private static NodeState checkPathExists(NodeState state, String... verify) {
+        NodeState c = state;
+        for (String p : verify) {
+            c = c.getChildNode(p);
+            assertTrue(c.exists());
+        }
+        return c;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java Thu Apr 25 13:20:23 2013
@@ -28,9 +28,9 @@ import org.apache.jackrabbit.mk.core.Mic
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
-import org.apache.jackrabbit.oak.plugins.index.CompositeIndexHookProvider;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookManager;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.CompositeIndexEditorProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexHookProvider;
 import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.query.ast.SelectorImpl;
@@ -64,8 +64,8 @@ public class NodeTypeIndexTest {
         store = new KernelNodeStore(mk);
         // initialize node types & index definitions
         OakInitializer.initialize(store, new InitialContent(),
-                CompositeIndexHookProvider
-                        .compose(new ArrayList<IndexHookProvider>()));
+                CompositeIndexEditorProvider
+                        .compose(new ArrayList<IndexEditorProvider>()));
     }
 
     @Test
@@ -79,8 +79,8 @@ public class NodeTypeIndexTest {
         addFile(root, "file-1");
 
         branch.setRoot(root.getNodeState());
-        branch.merge(new EditorHook(IndexHookManager
-                .of(new Property2IndexHookProvider())));
+        branch.merge(new EditorHook(new IndexUpdateProvider(
+                new Property2IndexHookProvider())));
 
         NodeState rootState = store.getRoot();
         NodeTypeIndex index = new NodeTypeIndex();

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=1475754&r1=1475753&r2=1475754&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 Thu Apr 25 13:20:23 2013
@@ -75,7 +75,7 @@ public class Property2IndexTest {
         }
         NodeState after = builder.getNodeState();
 
-        EditorDiff.process(new Property2IndexHook(builder, after), before, after);
+        EditorDiff.process(new Property2IndexHook(builder), 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, after), before, after);
+        EditorDiff.process(new Property2IndexHook(builder), 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, after), before, after);
+        EditorDiff.process(new Property2IndexHook(builder), 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, after), before, after);
+        EditorDiff.process(new Property2IndexHook(builder), 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, after), before, after);
+                EditorDiff.process(new Property2IndexHook(builder), 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, after), before, after);
+                new Property2IndexHook(builder), before, after);
         assertNull(unexpected);
     }
 
@@ -356,7 +356,7 @@ public class Property2IndexTest {
         NodeState after = builder.getNodeState();
 
         CommitFailedException expected = EditorDiff.process(
-                new Property2IndexHook(builder, after), before, after);
+                new Property2IndexHook(builder), 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, after), before, after);
+                new Property2IndexHook(builder), before, after);
         assertNull(unexpected);
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java Thu Apr 25 13:20:23 2013
@@ -25,7 +25,7 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider;
 import org.apache.jackrabbit.oak.plugins.commit.JcrConflictHandler;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.nodetype.NodeTypeIndexProvider;
 import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexHookProvider;
 import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexProvider;
@@ -96,7 +96,7 @@ public class Jcr {
     }
 
     @Nonnull
-    public final Jcr with(@Nonnull IndexHookProvider indexHookProvider) {
+    public final Jcr with(@Nonnull IndexEditorProvider indexHookProvider) {
         oak.with(checkNotNull(indexHookProvider));
         return this;
     }

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexDiff.java Thu Apr 25 13:20:23 2013
@@ -32,7 +32,7 @@ import java.util.Map;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.index.IndexHook;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -43,13 +43,13 @@ import org.apache.tika.parser.AutoDetect
 import org.apache.tika.parser.Parser;
 
 /**
- * {@link IndexHook} implementation that is responsible for keeping the
+ * {@link IndexEditor} implementation that is responsible for keeping the
  * {@link LuceneIndex} up to date
  * 
  * @see LuceneIndex
  * 
  */
-public class LuceneIndexDiff implements IndexHook, Closeable {
+public class LuceneIndexDiff implements IndexEditor, Closeable {
 
     private final LuceneIndexDiff parent;
 
@@ -203,20 +203,6 @@ public class LuceneIndexDiff implements 
         return null;
     }
 
-    @Override
-    public Editor reindex(NodeState state) {
-        boolean reindex = false;
-        for (LuceneIndexUpdate update : updates.values()) {
-            if (update.getAndResetReindexFlag()) {
-                reindex = true;
-            }
-        }
-        if (reindex) {
-            return new LuceneIndexDiff(node);
-        }
-        return null;
-    }
-
     // -----------------------------------------------------< Closeable >--
 
     @Override

Copied: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java (from r1475736, 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/LuceneIndexEditorProvider.java?p2=jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java&p1=jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexHookProvider.java&r1=1475736&r2=1475754&rev=1475754&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/LuceneIndexEditorProvider.java Thu Apr 25 13:20:23 2013
@@ -18,35 +18,30 @@ package org.apache.jackrabbit.oak.plugin
 
 import static org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexConstants.TYPE_LUCENE;
 
-import java.util.List;
-
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
-import org.apache.jackrabbit.oak.plugins.index.IndexHook;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
+import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
-
-import com.google.common.collect.ImmutableList;
 
 /**
- * Service that provides Lucene based {@link IndexHook}s
+ * Service that provides Lucene based {@link IndexEditor}s
  * 
  * @see LuceneIndexDiff
- * @see IndexHookProvider
+ * @see IndexEditorProvider
  * 
  */
 @Component
-@Service(IndexHookProvider.class)
-public class LuceneIndexHookProvider implements IndexHookProvider {
+@Service(IndexEditorProvider.class)
+public class LuceneIndexEditorProvider implements IndexEditorProvider {
 
     @Override
-    public List<? extends IndexHook> getIndexHooks(
-            String type, NodeBuilder builder, NodeState root) {
+    public Editor getIndexEditor(String type, NodeBuilder builder) {
         if (TYPE_LUCENE.equals(type)) {
-            return ImmutableList.of(new LuceneIndexDiff(builder));
+            return new LuceneIndexDiff(builder);
         }
-        return ImmutableList.of();
+        return null;
     }
 
 }

Propchange: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexEditorProvider.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/LuceneOakRepositoryStub.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/LuceneOakRepositoryStub.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/LuceneOakRepositoryStub.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/jcr/LuceneOakRepositoryStub.java Thu Apr 25 13:20:23 2013
@@ -21,7 +21,7 @@ import java.util.Properties;
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.plugins.index.lucene.LowCostLuceneIndexProvider;
-import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneInitializerHelper;
 
 public class LuceneOakRepositoryStub extends OakRepositoryStubBase {
@@ -35,6 +35,6 @@ public class LuceneOakRepositoryStub ext
     protected void preCreateRepository(Jcr jcr) {
         jcr.with(new LuceneInitializerHelper("/oak:index/luceneGlobal"))
                 .with(new LowCostLuceneIndexProvider())
-                .with(new LuceneIndexHookProvider());
+                .with(new LuceneIndexEditorProvider());
     }
 }

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java (original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexQueryTest.java Thu Apr 25 13:20:23 2013
@@ -50,7 +50,7 @@ public class LuceneIndexQueryTest extend
         return new Oak().with(new InitialContent())
             .with(new OpenSecurityProvider())
             .with(new LowCostLuceneIndexProvider())
-            .with(new LuceneIndexHookProvider())
+            .with(new LuceneIndexEditorProvider())
             .createContentRepository();
     }
 

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/OakSolrUtils.java Thu Apr 25 13:20:23 2013
@@ -19,7 +19,7 @@ package org.apache.jackrabbit.oak.plugin
 import java.io.IOException;
 import javax.annotation.Nonnull;
 
-import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.index.SolrIndexHookProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
@@ -47,19 +47,19 @@ public class OakSolrUtils {
     }
 
     /**
-     * adapts the OSGi Solr {@link IndexHookProvider} service
+     * adapts the OSGi Solr {@link IndexEditorProvider} service
      *
      * @return a {@link SolrIndexHookProvider}
      */
-    public static IndexHookProvider adaptOsgiIndexHookProvider() {
-        IndexHookProvider indexHookProvider = null;
+    public static IndexEditorProvider adaptOsgiIndexHookProvider() {
+        IndexEditorProvider indexHookProvider = null;
         try {
             BundleContext ctx = BundleReference.class.cast(SolrIndexHookProvider.class
                     .getClassLoader()).getBundle().getBundleContext();
 
-            ServiceReference serviceReference = ctx.getServiceReference(IndexHookProvider.class.getName());
+            ServiceReference serviceReference = ctx.getServiceReference(IndexEditorProvider.class.getName());
             if (serviceReference != null) {
-                indexHookProvider = IndexHookProvider.class.cast(ctx.getService(serviceReference));
+                indexHookProvider = IndexEditorProvider.class.cast(ctx.getService(serviceReference));
             }
         } catch (Throwable e) {
             // do nothing

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexDiff.java Thu Apr 25 13:20:23 2013
@@ -24,7 +24,7 @@ import java.util.Map;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.index.IndexHook;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfiguration;
 import org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
@@ -39,7 +39,7 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 
 /**
- * {@link IndexHook} implementation that is responsible for keeping the
+ * {@link IndexEditor} implementation that is responsible for keeping the
  * {@link org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex} up to date
  * <p/>
  * This handles index updates by keeping a {@link Map} of <code>String</code>
@@ -48,7 +48,7 @@ import static org.apache.jackrabbit.oak.
  * @see org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex
  * @see SolrIndexHook
  */
-public class SolrIndexDiff implements IndexHook, Closeable {
+public class SolrIndexDiff implements IndexEditor, Closeable {
 
     private final SolrIndexDiff parent;
 
@@ -202,20 +202,6 @@ public class SolrIndexDiff implements In
     }
 
     @Override
-    public Editor reindex(NodeState state) {
-        boolean reindex = false;
-        for (SolrIndexUpdate update : updates.values()) {
-            if (update.getAndResetReindexFlag()) {
-                reindex = true;
-            }
-        }
-        if (reindex) {
-            return new SolrIndexDiff(node, solrServer, configuration);
-        }
-        return null;
-    }
-
-    @Override
     public void close() throws IOException {
         for (SolrIndexUpdate update : updates.values()) {
             update.close();

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrIndexHook.java Thu Apr 25 13:20:23 2013
@@ -26,7 +26,7 @@ import javax.annotation.Nonnull;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.index.IndexHook;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
 import org.apache.jackrabbit.oak.spi.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -39,7 +39,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * {@link IndexHook} implementation that is responsible for keeping the
+ * {@link IndexEditor} implementation that is responsible for keeping the
  * {@link org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex} up to date
  * <p/>
  * This handles the status of the index update inside a flat list of {@link SolrInputDocument}s
@@ -51,7 +51,7 @@ import org.slf4j.LoggerFactory;
  * @see org.apache.jackrabbit.oak.plugins.index.solr.query.SolrQueryIndex
  * @see SolrIndexDiff
  */
-public class SolrIndexHook implements IndexHook, Closeable {
+public class SolrIndexHook implements IndexEditor, Closeable {
 
     private static final Logger log = LoggerFactory.getLogger(SolrNodeStateDiff.class);
 
@@ -235,19 +235,6 @@ public class SolrIndexHook implements In
     }
 
     @Override
-    public Editor reindex(NodeState state) throws CommitFailedException {
-        try {
-            close();
-            deleteByIdQueryBuilder.append(getPath()).append("*");
-            solrInputDocuments.addAll(docsFromState(getPath(), state));
-            apply();
-        } catch (IOException e) {
-            throw new CommitFailedException("Solr", 2, "Re-index failure", e);
-        }
-        return null;
-    }
-
-    @Override
     public void close() throws IOException {
         solrInputDocuments.clear();
         deleteByIdQueryBuilder.delete(4, deleteByIdQueryBuilder.length());

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=1475754&r1=1475753&r2=1475754&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 Thu Apr 25 13:20:23 2013
@@ -16,34 +16,32 @@
  */
 package org.apache.jackrabbit.oak.plugins.index.solr.index;
 
-import java.util.List;
-import javax.annotation.Nonnull;
+
+import javax.annotation.CheckForNull;
 
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Reference;
 import org.apache.felix.scr.annotations.ReferencePolicy;
 import org.apache.felix.scr.annotations.ReferencePolicyOption;
 import org.apache.felix.scr.annotations.Service;
-import org.apache.jackrabbit.oak.plugins.index.IndexHook;
-import org.apache.jackrabbit.oak.plugins.index.IndexHookProvider;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.solr.OakSolrConfigurationProvider;
 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.commit.Editor;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.collect.ImmutableList;
-
 /**
- * Service that provides {@link SolrIndexHookProvider} based {@link IndexHook}s.
+ * Service that provides {@link SolrIndexHookProvider} based {@link IndexEditor}s.
  *
- * @see org.apache.jackrabbit.oak.plugins.index.IndexHookProvider
+ * @see org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider
  */
 @Component
-@Service(IndexHookProvider.class)
-public class SolrIndexHookProvider implements IndexHookProvider {
+@Service(IndexEditorProvider.class)
+public class SolrIndexHookProvider implements IndexEditorProvider {
 
     private final Logger log = LoggerFactory.getLogger(SolrIndexHookProvider.class);
 
@@ -61,22 +59,20 @@ public class SolrIndexHookProvider imple
         this.oakSolrConfigurationProvider = oakSolrConfigurationProvider;
     }
 
-    @Override
-    @Nonnull
-    public List<? extends IndexHook> getIndexHooks(
-            String type, NodeBuilder builder, NodeState root) {
+    @Override @CheckForNull
+    public Editor getIndexEditor(String type, NodeBuilder builder) {
         if (SolrQueryIndex.TYPE.equals(type) && solrServerProvider != null && oakSolrConfigurationProvider != null) {
             try {
                 if (log.isDebugEnabled()) {
                     log.debug("Creating a Solr index hook");
                 }
-                IndexHook indexHook = new SolrIndexDiff(builder, solrServerProvider.getSolrServer(), oakSolrConfigurationProvider.getConfiguration());
-                return ImmutableList.of(indexHook);
+                IndexEditor indexHook = new SolrIndexDiff(builder, solrServerProvider.getSolrServer(), oakSolrConfigurationProvider.getConfiguration());
+                return indexHook;
             } catch (Exception e) {
                 log.error("unable to create Solr IndexHook ", e);
             }
         }
-        return ImmutableList.of();
+        return null;
     }
 
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrNodeStateDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrNodeStateDiff.java?rev=1475754&r1=1475753&r2=1475754&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrNodeStateDiff.java (original)
+++ jackrabbit/oak/trunk/oak-solr-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/solr/index/SolrNodeStateDiff.java Thu Apr 25 13:20:23 2013
@@ -24,7 +24,7 @@ import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
-import org.apache.jackrabbit.oak.plugins.index.IndexHook;
+import org.apache.jackrabbit.oak.plugins.index.IndexEditor;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
@@ -36,7 +36,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * A Solr based {@link IndexHook}
+ * A Solr based {@link IndexEditor}
  */
 class SolrNodeStateDiff implements NodeStateDiff {
 



Mime
View raw message