jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1445518 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ oak-core/src/main/ja...
Date Wed, 13 Feb 2013 09:31:45 GMT
Author: alexparvulescu
Date: Wed Feb 13 09:31:44 2013
New Revision: 1445518

URL: http://svn.apache.org/r1445518
Log:
OAK-410 RepositoryInitializer runs before the CommitHooks are in place

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.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/osgi/OsgiRepositoryInitializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeInitializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/OakInitializer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/RepositoryInitializer.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/nodetype/NodeTypeIndexTest.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Wed Feb 13 09:31:44 2013
@@ -86,4 +86,8 @@ public class ContentRepositoryImpl imple
                 nodeStore, indexProvider);
     }
 
+    public NodeStore getNodeStore() {
+        return nodeStore;
+    }
+
 }

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=1445518&r1=1445517&r2=1445518&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
Wed Feb 13 09:31:44 2013
@@ -16,18 +16,23 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
+import org.apache.jackrabbit.oak.osgi.OsgiRepositoryInitializer.RepositoryInitializerObserver;
 import org.apache.jackrabbit.oak.plugins.nodetype.DefaultTypeEditor;
 import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
 import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
 import org.apache.jackrabbit.oak.spi.lifecycle.OakInitializer;
+import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
@@ -35,7 +40,7 @@ import org.osgi.framework.ServiceRegistr
 import org.osgi.util.tracker.ServiceTracker;
 import org.osgi.util.tracker.ServiceTrackerCustomizer;
 
-public class Activator implements BundleActivator, ServiceTrackerCustomizer {
+public class Activator implements BundleActivator, ServiceTrackerCustomizer, RepositoryInitializerObserver
{
 
     private BundleContext context;
 
@@ -47,7 +52,7 @@ public class Activator implements Bundle
 
     private final OsgiValidatorProvider validatorProvider = new OsgiValidatorProvider();
 
-    private final OsgiRepositoryInitializer kernelTracker = new OsgiRepositoryInitializer();
+    private final OsgiRepositoryInitializer repositoryInitializerTracker = new OsgiRepositoryInitializer();
 
     private final Map<ServiceReference, ServiceRegistration> services =
             new HashMap<ServiceReference, ServiceRegistration>();
@@ -61,8 +66,8 @@ public class Activator implements Bundle
         indexProvider.start(bundleContext);
         indexHookProvider.start(bundleContext);
         validatorProvider.start(bundleContext);
-        kernelTracker.start(bundleContext);
-
+        repositoryInitializerTracker.setObserver(this);
+        repositoryInitializerTracker.start(bundleContext);
         tracker = new ServiceTracker(
                 context, MicroKernel.class.getName(), this);
         tracker.open();
@@ -71,22 +76,19 @@ public class Activator implements Bundle
     @Override
     public void stop(BundleContext bundleContext) throws Exception {
         tracker.close();
-
         indexProvider.stop();
         indexHookProvider.stop();
         validatorProvider.stop();
-        kernelTracker.stop();
+        repositoryInitializerTracker.stop();
     }
 
     //-------------------------------------------< ServiceTrackerCustomizer >---
 
     @Override
     public Object addingService(ServiceReference reference) {
-        Object service = context.getService(reference);
-        if (service instanceof MicroKernel) {
-            MicroKernel kernel = (MicroKernel) service;
-            OakInitializer.initialize(new KernelNodeStore(kernel),
-                    kernelTracker, indexHookProvider);
+        MicroKernel kernel = (MicroKernel) context.getService(reference);
+        OakInitializer.initialize(new KernelNodeStore(kernel),
+                repositoryInitializerTracker, indexHookProvider);
             Oak oak = new Oak(kernel)
                     .with(new CompositeHook(
                         // TODO: DefaultTypeEditor is JCR specific and does not belong here
@@ -98,11 +100,7 @@ public class Activator implements Bundle
                     ContentRepository.class.getName(),
                     oak.createContentRepository(),
                     new Properties()));
-            return service;
-        } else {
-            context.ungetService(reference);
-            return null;
-        }
+            return kernel;
     }
 
     @Override
@@ -112,9 +110,24 @@ public class Activator implements Bundle
 
     @Override
     public void removedService(ServiceReference reference, Object service) {
-        ServiceRegistration registration = services.remove(reference);
-        registration.unregister();
+        services.remove(reference).unregister();
         context.ungetService(reference);
     }
 
+    //----------------------------------------< RepositoryInitializerObserver >---
+
+    @Override
+    public void newRepositoryInitializer(RepositoryInitializer ri) {
+        List<ServiceReference> mkRefs = new ArrayList<ServiceReference>(
+                services.keySet());
+        for (ServiceReference ref : mkRefs) {
+            Object service = context.getService(ref);
+            if (service instanceof ContentRepositoryImpl) {
+                ContentRepositoryImpl repository = (ContentRepositoryImpl) service;
+                OakInitializer.initialize(repository.getNodeStore(), ri,
+                        indexHookProvider);
+            }
+        }
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiRepositoryInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiRepositoryInitializer.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiRepositoryInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiRepositoryInitializer.java
Wed Feb 13 09:31:44 2013
@@ -18,8 +18,9 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
+import org.apache.jackrabbit.oak.spi.lifecycle.CompositeInitializer;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.osgi.framework.ServiceReference;
 
 /**
@@ -31,35 +32,33 @@ public class OsgiRepositoryInitializer
         extends AbstractServiceTracker<RepositoryInitializer>
         implements RepositoryInitializer {
 
-    /**
-     * The reference to the micro kernel once available.
-     */
-    private volatile NodeStore store;
+    private RepositoryInitializerObserver observer;
 
     public OsgiRepositoryInitializer() {
         super(RepositoryInitializer.class);
     }
 
     @Override
-    public void initialize(NodeStore store) {
-        this.store = store;
-        if (store != null) {
-            for (RepositoryInitializer mki : getServices()) {
-                mki.initialize(store);
-            }
-        }
+    public NodeState initialize(NodeState state) {
+        return new CompositeInitializer(getServices()).initialize(state);
     }
 
     @Override
     public Object addingService(ServiceReference reference) {
-        RepositoryInitializer mki =
-                (RepositoryInitializer) super.addingService(reference);
-        NodeStore store = this.store;
-        if (store != null) {
-            //TODO index added content
-            mki.initialize(store);
+        RepositoryInitializer ri = (RepositoryInitializer) super
+                .addingService(reference);
+        if (observer != null) {
+            observer.newRepositoryInitializer(ri);
         }
-        return mki;
+        return ri;
+    }
+
+    public void setObserver(RepositoryInitializerObserver observer) {
+        this.observer = observer;
+    }
+
+    interface RepositoryInitializerObserver {
+        void newRepositoryInitializer(RepositoryInitializer ri);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/InitialContent.java
Wed Feb 13 09:31:44 2013
@@ -23,8 +23,10 @@ import org.apache.jackrabbit.oak.api.Typ
 import org.apache.jackrabbit.oak.core.RootImpl;
 import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
@@ -45,10 +47,8 @@ import static org.apache.jackrabbit.JcrC
 public class InitialContent implements RepositoryInitializer {
 
     @Override
-    public void initialize(NodeStore store) {
-        NodeStoreBranch branch = store.branch();
-
-        NodeBuilder root = branch.getRoot().builder();
+    public NodeState initialize(NodeState state) {
+        NodeBuilder root = state.builder();
         root.setProperty(JCR_PRIMARYTYPE, "rep:root", Type.NAME);
 
         if (!root.hasChildNode(JCR_SYSTEM)) {
@@ -71,14 +71,16 @@ public class InitialContent implements R
             IndexUtils.createIndexDefinition(index, "nodetype", true, false,
                     ImmutableList.of(JCR_PRIMARYTYPE, JCR_MIXINTYPES), null);
         }
+        NodeStore store = new MemoryNodeStore();
+        NodeStoreBranch branch = store.branch();
+        branch.setRoot(root.getNodeState());
         try {
-            branch.setRoot(root.getNodeState());
             branch.merge();
         } catch (CommitFailedException e) {
-            throw new RuntimeException(e); // TODO: shouldn't need the wrapper
+            throw new RuntimeException(e);
         }
-
         BuiltInNodeTypes.register(new RootImpl(store));
+        return store.getRoot();
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AccessControlInitializer.java
Wed Feb 13 09:31:44 2013
@@ -17,14 +17,10 @@
 package org.apache.jackrabbit.oak.security.authorization;
 
 import com.google.common.collect.ImmutableList;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
@@ -34,16 +30,10 @@ import static org.apache.jackrabbit.JcrC
  */
 public class AccessControlInitializer implements RepositoryInitializer, AccessControlConstants
{
 
-    /**
-     * logger instance
-     */
-    private static final Logger log = LoggerFactory.getLogger(AccessControlInitializer.class);
-
     @Override
-    public void initialize(NodeStore store) {
-        NodeStoreBranch branch = store.branch();
+    public NodeState initialize(NodeState state) {
+        NodeBuilder root = state.builder();
 
-        NodeBuilder root = branch.getRoot().builder();
         NodeBuilder system = root.child(JCR_SYSTEM);
         if (!system.hasChildNode(REP_PERMISSION_STORE)) {
             system.child(REP_PERMISSION_STORE)
@@ -55,12 +45,6 @@ public class AccessControlInitializer im
         IndexUtils.createIndexDefinition(index, "acPrincipalName", true, false,
                 ImmutableList.<String>of(REP_PRINCIPAL_NAME),
                 ImmutableList.<String>of(NT_REP_DENY_ACE, NT_REP_GRANT_ACE));
-        try {
-            branch.setRoot(root.getNodeState());
-            branch.merge();
-        } catch (CommitFailedException e) {
-            log.error("Failed to commit access control index definition", e);
-            throw new RuntimeException(e);
-        }
+        return root.getNodeState();
     }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeInitializer.java
Wed Feb 13 09:31:44 2013
@@ -19,6 +19,7 @@ package org.apache.jackrabbit.oak.securi
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
+
 import javax.jcr.RepositoryException;
 
 import com.google.common.collect.ImmutableMap;
@@ -26,10 +27,12 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.core.RootImpl;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
 import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 import org.slf4j.Logger;
@@ -64,10 +67,8 @@ class PrivilegeInitializer implements Re
             REP_WRITE, new String[] {JCR_WRITE, JCR_NODE_TYPE_MANAGEMENT});
 
     @Override
-    public void initialize(NodeStore store) {
-        NodeStoreBranch branch = store.branch();
-
-        NodeBuilder root = branch.getRoot().builder();
+    public NodeState initialize(NodeState state) {
+        NodeBuilder root = state.builder();
         NodeBuilder system = root.child(JcrConstants.JCR_SYSTEM);
         system.setProperty(JcrConstants.JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_SYSTEM,
Type.NAME);
 
@@ -75,6 +76,8 @@ class PrivilegeInitializer implements Re
             NodeBuilder privileges = system.child(REP_PRIVILEGES);
             privileges.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_REP_PRIVILEGES, Type.NAME);
 
+            NodeStore store = new MemoryNodeStore();
+            NodeStoreBranch branch = store.branch();
             try {
                 branch.setRoot(root.getNodeState());
                 branch.merge();
@@ -90,7 +93,9 @@ class PrivilegeInitializer implements Re
                 log.error("Failed to register built-in privileges", e);
                 throw new RuntimeException(e);
             }
+            return store.getRoot();
         }
+        return root.getNodeState();
     }
 
     private Collection<PrivilegeDefinition> getBuiltInDefinitions() {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/UserInitializer.java
Wed Feb 13 09:31:44 2013
@@ -26,11 +26,15 @@ import org.apache.jackrabbit.oak.core.Ro
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.plugins.index.IndexConstants;
 import org.apache.jackrabbit.oak.plugins.index.IndexUtils;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.apache.jackrabbit.oak.spi.security.user.UserConfiguration;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -74,7 +78,16 @@ public class UserInitializer implements 
 
     //----------------------------------------------< RepositoryInitializer >---
     @Override
-    public void initialize(NodeStore store) {
+    public NodeState initialize(NodeState state) {
+        NodeBuilder builder = state.builder();
+        NodeStore store = new MemoryNodeStore();
+        NodeStoreBranch branch = store.branch();
+        branch.setRoot(builder.getNodeState());
+        try {
+            branch.merge();
+        } catch (CommitFailedException e) {
+            throw new RuntimeException(e);
+        }
         Root root = new RootImpl(store);
 
         UserConfiguration userConfiguration = securityProvider.getUserConfiguration();
@@ -108,5 +121,6 @@ public class UserInitializer implements 
             log.error("Failed to initialize user content ", e);
             throw new RuntimeException(e);
         }
+        return store.getRoot();
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeInitializer.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/CompositeInitializer.java
Wed Feb 13 09:31:44 2013
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.spi.li
 import java.util.Arrays;
 import java.util.Collection;
 
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
 /**
@@ -41,9 +42,11 @@ public class CompositeInitializer implem
     }
 
     @Override
-    public void initialize(NodeStore store) {
+    public NodeState initialize(NodeState state) {
+        NodeState newState = state;
         for (RepositoryInitializer tracker : initializers) {
-            tracker.initialize(store);
+            newState = tracker.initialize(newState);
         }
+        return newState;
     }
 }

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=1445518&r1=1445517&r2=1445518&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
Wed Feb 13 09:31:44 2013
@@ -21,8 +21,7 @@ package org.apache.jackrabbit.oak.spi.li
 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.memory.MemoryNodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
@@ -31,18 +30,12 @@ public class OakInitializer {
     public static void initialize(NodeStore store,
             RepositoryInitializer initializer, IndexHookProvider indexHook) {
 
-        // TODO refactor initializer to be able to first #branch, then
-        // #initialize, next #index and finally #merge
-        // This means that the RepositoryInitializer should receive a
-        // NodeStoreBranch as a param
-
-        initializer.initialize(store);
-
         NodeStoreBranch branch = store.branch();
-        NodeBuilder root = branch.getRoot().builder();
+        NodeState before = branch.getRoot();
+        NodeState after = initializer.initialize(before);
         try {
-            branch.setRoot(IndexHookManager.of(indexHook).processCommit(
-                    MemoryNodeState.EMPTY_NODE, root.getNodeState()));
+            branch.setRoot(IndexHookManager.of(indexHook).processCommit(before,
+                    after));
             branch.merge();
         } catch (CommitFailedException e) {
             throw new RuntimeException(e);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/RepositoryInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/RepositoryInitializer.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/RepositoryInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/RepositoryInitializer.java
Wed Feb 13 09:31:44 2013
@@ -18,7 +18,7 @@
  */
 package org.apache.jackrabbit.oak.spi.lifecycle;
 
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
  * Initializer of repository content. A component that needs to add specific
@@ -34,8 +34,8 @@ public interface RepositoryInitializer {
      * have been initialized, so the implementation of this method should
      * check for that before blindly adding new content.
      *
-     * @param store node store of the repository
+     * @param state the current state of the repository
      */
-    void initialize(NodeStore store);
+    NodeState initialize(NodeState state);
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/AbstractSecurityTest.java
Wed Feb 13 09:31:44 2013
@@ -28,8 +28,6 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexHookProvider;
-import org.apache.jackrabbit.oak.plugins.index.p2.Property2IndexProvider;
 import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
 import org.apache.jackrabbit.oak.security.authentication.ConfigurationUtil;
@@ -57,8 +55,6 @@ public abstract class AbstractSecurityTe
     public void before() throws Exception {
         contentRepository = new Oak()
                 .with(new InitialContent())
-                .with(new Property2IndexHookProvider())
-                .with(new Property2IndexProvider())
                 .with(getSecurityProvider())
                 .createContentRepository();
 

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=1445518&r1=1445517&r2=1445518&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
Wed Feb 13 09:31:44 2013
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Set;
 
@@ -27,10 +28,13 @@ 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.p2.Property2IndexHookProvider;
 import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.query.index.FilterImpl;
+import org.apache.jackrabbit.oak.spi.lifecycle.OakInitializer;
 import org.apache.jackrabbit.oak.spi.query.Cursor;
 import org.apache.jackrabbit.oak.spi.query.Cursors;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
@@ -56,7 +60,9 @@ public class NodeTypeIndexTest {
         store = new KernelNodeStore(mk);
         store.setHook(IndexHookManager.of(new Property2IndexHookProvider()));
         // initialize node types & index definitions
-        new InitialContent().initialize(store);
+        OakInitializer.initialize(store, new InitialContent(),
+                CompositeIndexHookProvider
+                        .compose(new ArrayList<IndexHookProvider>()));
     }
 
     @Test

Modified: jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java?rev=1445518&r1=1445517&r2=1445518&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
Wed Feb 13 09:31:44 2013
@@ -17,12 +17,11 @@
 package org.apache.jackrabbit.oak.plugins.index.lucene.util;
 
 import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
 public class LuceneInitializerHelper implements RepositoryInitializer {
@@ -34,12 +33,10 @@ public class LuceneInitializerHelper imp
     }
 
     @Override
-    public void initialize(NodeStore store) {
+    public NodeState initialize(NodeState state) {
+        NodeBuilder root = state.builder();
         boolean dirty = false;
 
-        NodeStoreBranch branch = store.branch();
-        NodeBuilder root = branch.getRoot().builder();
-
         NodeBuilder index = root;
         for (String p : PathUtils.elements(path)) {
             if (!index.hasChildNode(p)) {
@@ -53,13 +50,9 @@ public class LuceneInitializerHelper imp
                     "oak:queryIndexDefinition", Type.NAME).setProperty("type",
                     "lucene");
             index.setProperty("reindex", true);
-            try {
-                branch.setRoot(root.getNodeState());
-                branch.merge();
-            } catch (CommitFailedException e) {
-                throw new RuntimeException(e);
-            }
+            return root.getNodeState();
         }
+        return state;
     }
 
 }



Mime
View raw message