jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1525140 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ oak-core/s...
Date Fri, 20 Sep 2013 20:46:02 GMT
Author: jukka
Date: Fri Sep 20 20:46:01 2013
New Revision: 1525140

URL: http://svn.apache.org/r1525140
Log:
OAK-659: Move purge logic for transient changes below the NodeBuilder interface

Use NodeBuilders instead of NodeStates in initializers

Modified:
    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/memory/MemoryNodeStore.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/AuthorizationInitializer.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/main/java/org/apache/jackrabbit/oak/spi/lifecycle/WorkspaceInitializer.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/RelativePathTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
    jackrabbit/oak/trunk/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/LuceneInitializerHelper.java
    jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java

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=1525140&r1=1525139&r2=1525140&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
Fri Sep 20 20:46:01 2013
@@ -20,7 +20,7 @@ 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.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.osgi.framework.ServiceReference;
 
 /**
@@ -39,8 +39,8 @@ public class OsgiRepositoryInitializer
     }
 
     @Override
-    public NodeState initialize(NodeState state) {
-        return new CompositeInitializer(getServices()).initialize(state);
+    public void initialize(NodeBuilder builder) {
+        new CompositeInitializer(getServices()).initialize(builder);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java?rev=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
Fri Sep 20 20:46:01 2013
@@ -45,11 +45,18 @@ import org.apache.jackrabbit.oak.spi.sta
  */
 public class MemoryNodeStore extends AbstractNodeStore {
 
-    private final AtomicReference<NodeState> root =
-            new AtomicReference<NodeState>(EMPTY_NODE);
+    private final AtomicReference<NodeState> root;
 
     private final Map<String, NodeState> checkpoints = newHashMap();
 
+    public MemoryNodeStore(NodeState state) {
+        this.root = new AtomicReference<NodeState>(state);
+    }
+
+    public MemoryNodeStore() {
+        this(EMPTY_NODE);
+    }
+
     @Override
     public NodeState getRoot() {
         return root.get();

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=1525140&r1=1525139&r2=1525140&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
Fri Sep 20 20:46:01 2013
@@ -16,26 +16,26 @@
  */
 package org.apache.jackrabbit.oak.plugins.nodetype.write;
 
+import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+
 import com.google.common.collect.ImmutableList;
+
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.core.SystemRoot;
 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.plugins.memory.ModifiedNodeState;
 import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
 import org.apache.jackrabbit.oak.plugins.nodetype.RegistrationEditorProvider;
 import org.apache.jackrabbit.oak.plugins.version.VersionConstants;
 import org.apache.jackrabbit.oak.spi.commit.EditorHook;
-import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
-import org.apache.jackrabbit.oak.spi.commit.PostCommitHook;
 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;
 
 /**
  * {@code InitialContent} implements a {@link RepositoryInitializer} and
@@ -45,13 +45,20 @@ import org.apache.jackrabbit.oak.spi.sta
 @Service(RepositoryInitializer.class)
 public class InitialContent implements RepositoryInitializer, NodeTypeConstants {
 
+    public static final NodeState INITIAL_CONTENT = createInitialContent();
+
+    private static NodeState createInitialContent() {
+        NodeBuilder builder = EMPTY_NODE.builder();
+        new InitialContent().initialize(builder);
+        return ModifiedNodeState.squeeze(builder.getNodeState());
+    }
+
     @Override
-    public NodeState initialize(NodeState state) {
-        NodeBuilder root = state.builder();
-        root.setProperty(JCR_PRIMARYTYPE, NT_REP_ROOT, Type.NAME);
+    public void initialize(NodeBuilder builder) {
+        builder.setProperty(JCR_PRIMARYTYPE, NT_REP_ROOT, Type.NAME);
 
-        if (!root.hasChildNode(JCR_SYSTEM)) {
-            NodeBuilder system = root.child(JCR_SYSTEM);
+        if (!builder.hasChildNode(JCR_SYSTEM)) {
+            NodeBuilder system = builder.child(JCR_SYSTEM);
             system.setProperty(JCR_PRIMARYTYPE, NT_REP_SYSTEM, Type.NAME);
 
             system.child(JCR_VERSIONSTORAGE)
@@ -62,8 +69,8 @@ public class InitialContent implements R
                     .setProperty(JCR_PRIMARYTYPE, VersionConstants.REP_ACTIVITIES, Type.NAME);
         }
 
-        if (!root.hasChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)) {
-            NodeBuilder index = IndexUtils.getOrCreateOakIndex(root);
+        if (!builder.hasChildNode(IndexConstants.INDEX_DEFINITIONS_NAME)) {
+            NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder);
 
             IndexUtils.createIndexDefinition(index, "uuid", true, true,
                     ImmutableList.<String>of(JCR_UUID), null);
@@ -73,16 +80,10 @@ public class InitialContent implements R
             // the cost of using the property index for "@primaryType is not null" is very
high
             nt.setProperty(IndexConstants.ENTRY_COUNT_PROPERTY_NAME, Long.valueOf(Long.MAX_VALUE));
         }
-        NodeStore store = new MemoryNodeStore();
-        NodeStoreBranch branch = store.branch();
-        branch.setRoot(root.getNodeState());
-        try {
-            branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
-        } catch (CommitFailedException e) {
-            throw new RuntimeException(e);
-        }
+
+        NodeStore store = new MemoryNodeStore(builder.getNodeState());
         BuiltInNodeTypes.register(new SystemRoot(store, new EditorHook(new RegistrationEditorProvider())));
-        return store.getRoot();
+        builder.reset(store.getRoot());
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationInitializer.java?rev=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/AuthorizationInitializer.java
Fri Sep 20 20:46:01 2013
@@ -28,7 +28,6 @@ import org.apache.jackrabbit.oak.spi.lif
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.security.authorization.accesscontrol.AccessControlConstants;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
@@ -47,11 +46,9 @@ class AuthorizationInitializer implement
 
     @Nonnull
     @Override
-    public NodeState initialize(NodeState workspaceRoot, String workspaceName, QueryIndexProvider
indexProvider, CommitHook commitHook) {
-        NodeBuilder root = workspaceRoot.builder();
-
+    public void initialize(NodeBuilder builder, String workspaceName, QueryIndexProvider
indexProvider, CommitHook commitHook) {
         // property index for rep:principalName stored in ACEs
-        NodeBuilder index = IndexUtils.getOrCreateOakIndex(root);
+        NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder);
         if (!index.hasChildNode("acPrincipalName")) {
             IndexUtils.createIndexDefinition(index, "acPrincipalName", true, false,
                     ImmutableList.<String>of(REP_PRINCIPAL_NAME),
@@ -59,13 +56,12 @@ class AuthorizationInitializer implement
         }
 
         // create the permission store and the root for this workspace.
-        NodeBuilder permissionStore = root.child(JCR_SYSTEM).child(REP_PERMISSION_STORE);
+        NodeBuilder permissionStore = builder.child(JCR_SYSTEM).child(REP_PERMISSION_STORE);
         if (!permissionStore.hasProperty(JCR_PRIMARYTYPE)) {
             permissionStore.setProperty(JCR_PRIMARYTYPE, NT_REP_PERMISSION_STORE, Type.NAME);
         }
         if (!permissionStore.hasChildNode(workspaceName)) {
             permissionStore.child(workspaceName).setProperty(JcrConstants.JCR_PRIMARYTYPE,
NT_REP_PERMISSION_STORE, Type.NAME);
         }
-        return root.getNodeState();
     }
 }

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=1525140&r1=1525139&r2=1525140&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
Fri Sep 20 20:46:01 2013
@@ -16,23 +16,17 @@
  */
 package org.apache.jackrabbit.oak.security.privilege;
 
-
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.core.SystemRoot;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
 import org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants;
-import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
-import org.apache.jackrabbit.oak.spi.commit.PostCommitHook;
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
 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;
 import org.slf4j.LoggerFactory;
 
@@ -47,33 +41,22 @@ class PrivilegeInitializer implements Re
     private static final Logger log = LoggerFactory.getLogger(PrivilegeInitializer.class);
 
     @Override
-    public NodeState initialize(NodeState state) {
-        NodeBuilder root = state.builder();
-        NodeBuilder system = root.child(JcrConstants.JCR_SYSTEM);
+    public void initialize(NodeBuilder builder) {
+        NodeBuilder system = builder.child(JcrConstants.JCR_SYSTEM);
         system.setProperty(JcrConstants.JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_SYSTEM,
Type.NAME);
 
         if (!system.hasChildNode(REP_PRIVILEGES)) {
             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(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
-            } catch (CommitFailedException e) {
-                log.error("Failed to initialize privilege content ", e);
-                throw new RuntimeException(e);
-            }
-
+            NodeStore store = new MemoryNodeStore(builder.getNodeState());
             try {
                 new PrivilegeDefinitionWriter(new SystemRoot(store)).writeBuiltInDefinitions();
+                builder.reset(store.getRoot());
             } catch (RepositoryException e) {
                 log.error("Failed to register built-in privileges", e);
                 throw new RuntimeException(e);
             }
-            return store.getRoot();
         }
-        return root.getNodeState();
     }
 }

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=1525140&r1=1525139&r2=1525140&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
Fri Sep 20 20:46:01 2013
@@ -16,10 +16,10 @@
  */
 package org.apache.jackrabbit.oak.security.user;
 
-
-import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
+
 import com.google.common.base.Strings;
+
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -38,7 +38,7 @@ import org.apache.jackrabbit.oak.spi.sec
 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.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 import org.apache.jackrabbit.oak.util.NodeUtil;
 import org.slf4j.Logger;
@@ -84,14 +84,14 @@ class UserInitializer implements Workspa
     }
 
     //-----------------------------------------------< WorkspaceInitializer >---
-    @Nonnull
+
     @Override
-    public NodeState initialize(NodeState workspaceRoot, String workspaceName,
+    public void initialize(NodeBuilder builder, String workspaceName,
                                 QueryIndexProvider indexProvider,
                                 CommitHook commitHook) {
         MemoryNodeStore store = new MemoryNodeStore();
         NodeStoreBranch branch = store.branch();
-        branch.setRoot(workspaceRoot);
+        branch.setRoot(builder.getNodeState());
         try {
             branch.merge(EmptyHook.INSTANCE, PostCommitHook.EMPTY);
         } catch (CommitFailedException e) {
@@ -133,6 +133,8 @@ class UserInitializer implements Workspa
             if (root.hasPendingChanges()) {
                 root.commit();
             }
+
+            builder.reset(store.getRoot());
         } catch (RepositoryException e) {
             log.error(errorMsg, e);
             throw new RuntimeException(e);
@@ -140,6 +142,5 @@ class UserInitializer implements Workspa
             log.error(errorMsg, 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=1525140&r1=1525139&r2=1525140&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
Fri Sep 20 20:46:01 2013
@@ -21,6 +21,9 @@ package org.apache.jackrabbit.oak.spi.li
 import java.util.Arrays;
 import java.util.Collection;
 
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
@@ -41,11 +44,9 @@ public class CompositeInitializer implem
     }
 
     @Override
-    public NodeState initialize(NodeState state) {
-        NodeState newState = state;
+    public void initialize(@Nonnull NodeBuilder builder) {
         for (RepositoryInitializer tracker : initializers) {
-            newState = tracker.initialize(newState);
+            tracker.initialize(builder);
         }
-        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=1525140&r1=1525139&r2=1525140&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
Fri Sep 20 20:46:01 2013
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.commit.EditorHook;
 import org.apache.jackrabbit.oak.spi.commit.PostCommitHook;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
+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;
@@ -39,11 +40,10 @@ public final class OakInitializer {
     public static void initialize(@Nonnull NodeStore store,
                                   @Nonnull RepositoryInitializer initializer,
                                   @Nonnull IndexEditorProvider indexEditor) {
-        NodeStoreBranch branch = store.branch();
-        NodeState before = branch.getHead();
-        branch.setRoot(initializer.initialize(before));
+        NodeBuilder builder = store.getRoot().builder();
+        initializer.initialize(builder);
         try {
-            branch.merge(new EditorHook(new IndexUpdateProvider(indexEditor)), PostCommitHook.EMPTY);
+            store.merge(builder, new EditorHook(new IndexUpdateProvider(indexEditor)), PostCommitHook.EMPTY);
         } catch (CommitFailedException e) {
             throw new RuntimeException(e);
         }
@@ -55,14 +55,12 @@ public final class OakInitializer {
                                   @Nonnull IndexEditorProvider indexEditor,
                                   @Nonnull QueryIndexProvider indexProvider,
                                   @Nonnull CommitHook commitHook) {
-        NodeStoreBranch branch = store.branch();
-        NodeState root = branch.getHead();
+        NodeBuilder builder = store.getRoot().builder();
         for (WorkspaceInitializer wspInit : initializer) {
-            root = wspInit.initialize(root, workspaceName, indexProvider, commitHook);
+            wspInit.initialize(builder, workspaceName, indexProvider, commitHook);
         }
-        branch.setRoot(root);
         try {
-            branch.merge(new EditorHook(new IndexUpdateProvider(indexEditor)), PostCommitHook.EMPTY);
+            store.merge(builder, new EditorHook(new IndexUpdateProvider(indexEditor)), PostCommitHook.EMPTY);
         } 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=1525140&r1=1525139&r2=1525140&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
Fri Sep 20 20:46:01 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.spi.lifecycle;
 
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
@@ -34,8 +37,7 @@ public interface RepositoryInitializer {
      */
     RepositoryInitializer DEFAULT = new RepositoryInitializer() {
         @Override
-        public NodeState initialize(NodeState state) {
-            return state;
+        public void initialize(NodeBuilder builder) {
         }
     };
 
@@ -45,7 +47,8 @@ public interface RepositoryInitializer {
      * have been initialized, so the implementation of this method should
      * check for that before blindly adding new content.
      *
-     * @param state the current state of the repository
+     * @param builder builder for accessing and modifying repository content
      */
-    NodeState initialize(NodeState state);
+    void initialize(@Nonnull NodeBuilder builder);
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/WorkspaceInitializer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/WorkspaceInitializer.java?rev=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/WorkspaceInitializer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/lifecycle/WorkspaceInitializer.java
Fri Sep 20 20:46:01 2013
@@ -16,11 +16,9 @@
  */
 package org.apache.jackrabbit.oak.spi.lifecycle;
 
-import javax.annotation.Nonnull;
-
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 
 /**
  * Initializer of a workspace and it's initial content. A module that needs
@@ -32,10 +30,8 @@ import org.apache.jackrabbit.oak.spi.sta
 public interface WorkspaceInitializer {
 
     WorkspaceInitializer DEFAULT = new WorkspaceInitializer() {
-        @Nonnull
         @Override
-        public NodeState initialize(NodeState workspaceRoot, String workspaceName, QueryIndexProvider
indexProvider, CommitHook commitHook) {
-            return workspaceRoot;
+        public void initialize(NodeBuilder builder, String workspaceName, QueryIndexProvider
indexProvider, CommitHook commitHook) {
         }
     };
 
@@ -43,15 +39,15 @@ public interface WorkspaceInitializer {
      * Initialize the content of a new workspace. This method is called before
      * the workspace becomes available.
      *
-     * @param workspaceRoot The workspace root state.
+     * @param builder       Builder for accessing and modifying the workspace
      * @param workspaceName The name of the workspace that is being initialized.
      * @param indexProvider The query index provider used within this workspace.
      * @param commitHook    The commit hook(s) defined for this workspace.
      * @return The modified workspace root state.
      */
-    @Nonnull
-    NodeState initialize(NodeState workspaceRoot, 
+    void initialize(NodeBuilder builder, 
                          String workspaceName,
                          QueryIndexProvider indexProvider,
                          CommitHook commitHook);
+
 }

Modified: 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=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/IndexUpdateTest.java
Fri Sep 20 20:46:01 2013
@@ -22,7 +22,6 @@ import static org.apache.jackrabbit.oak.
 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.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;
@@ -53,7 +52,7 @@ public class IndexUpdateTest {
     private static final EditorHook HOOK = new EditorHook(
             new IndexUpdateProvider(new PropertyIndexEditorProvider()));
 
-    private NodeState root = new InitialContent().initialize(EMPTY_NODE);
+    private NodeState root = InitialContent.INITIAL_CONTENT;
 
     private NodeBuilder builder = root.builder();
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java?rev=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/MultipleIndicesTest.java
Fri Sep 20 20:46:01 2013
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.oak.query.A
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
 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.ImmutableList;
@@ -43,17 +42,17 @@ public class MultipleIndicesTest extends
                 .with(new InitialContent())
                 .with(new RepositoryInitializer() {
                     @Override
-                    public NodeState initialize(NodeState state) {
-                        NodeBuilder root = state.builder();
-                        createIndexDefinition(getOrCreateOakIndex(root), "pid",
+                    public void initialize(NodeBuilder builder) {
+                        createIndexDefinition(
+                                getOrCreateOakIndex(builder), "pid",
                                 true, false, ImmutableList.of("pid"), null);
                         createIndexDefinition(
-                                getOrCreateOakIndex(root.child("content")),
+                                getOrCreateOakIndex(builder.child("content")),
                                 "pid", true, false, ImmutableList.of("pid"),
                                 null);
-                        return root.getNodeState();
                     }
-                }).with(new OpenSecurityProvider())
+                })
+                .with(new OpenSecurityProvider())
                 .with(new PropertyIndexProvider())
                 .with(new PropertyIndexEditorProvider())
                 .createContentRepository();

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java?rev=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/PropertyIndexTest.java
Fri Sep 20 20:46:01 2013
@@ -60,7 +60,7 @@ public class PropertyIndexTest {
 
     @Test
     public void testPropertyLookup() throws Exception {
-        NodeState root = new InitialContent().initialize(EMPTY_NODE);
+        NodeState root = InitialContent.INITIAL_CONTENT;
 
         // Add index definition
         NodeBuilder builder = root.builder();
@@ -105,7 +105,7 @@ public class PropertyIndexTest {
 
     @Test
     public void testCustomConfigPropertyLookup() throws Exception {
-        NodeState root = new InitialContent().initialize(EMPTY_NODE);
+        NodeState root = InitialContent.INITIAL_CONTENT;
 
         // Add index definition
         NodeBuilder builder = root.builder();
@@ -153,7 +153,7 @@ public class PropertyIndexTest {
      */
     @Test
     public void testCustomConfigNodeType() throws Exception {
-        NodeState root = new InitialContent().initialize(EMPTY_NODE);
+        NodeState root = InitialContent.INITIAL_CONTENT;
 
         // Add index definitions
         NodeBuilder builder = root.builder();

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/RelativePathTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/RelativePathTest.java?rev=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/RelativePathTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/property/RelativePathTest.java
Fri Sep 20 20:46:01 2013
@@ -33,7 +33,6 @@ import org.apache.jackrabbit.oak.query.A
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.junit.Test;
 
 /**
@@ -46,12 +45,10 @@ public class RelativePathTest extends Ab
         return new Oak().with(new InitialContent())
                 .with(new RepositoryInitializer() {
                     @Override
-                    public NodeState initialize(NodeState state) {
-                        NodeBuilder root = state.builder();
-                        NodeBuilder index = IndexUtils.getOrCreateOakIndex(root);
+                    public void initialize(NodeBuilder builder) {
+                        NodeBuilder index = IndexUtils.getOrCreateOakIndex(builder);
                         IndexUtils.createIndexDefinition(index, "myProp", true,
                                 false, ImmutableList.<String>of("myProp"), null);
-                        return root.getNodeState();
                     }
                 })
                 .with(new OpenSecurityProvider())

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java?rev=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeEditorTest.java
Fri Sep 20 20:46:01 2013
@@ -38,7 +38,7 @@ public class TypeEditorTest {
     public void ignoreHidden() throws CommitFailedException {
         EditorHook hook = new EditorHook(new TypeEditorProvider());
 
-        NodeState root = new InitialContent().initialize(EMPTY_NODE);
+        NodeState root = InitialContent.INITIAL_CONTENT;
         NodeBuilder builder = root.builder();
 
         NodeState before = builder.getNodeState();

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java?rev=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/SQL2ParserTest.java
Fri Sep 20 20:46:01 2013
@@ -18,7 +18,6 @@ package org.apache.jackrabbit.oak.query;
 
 import static junit.framework.Assert.assertTrue;
 import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
-import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES;
 
 import java.text.ParseException;
@@ -32,8 +31,10 @@ import org.junit.Test;
  */
 public class SQL2ParserTest {
 
-    private final NodeState types = new InitialContent().initialize(EMPTY_NODE)
-            .getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
+    private final NodeState types = InitialContent.INITIAL_CONTENT
+            .getChildNode(JCR_SYSTEM)
+            .getChildNode(JCR_NODE_TYPES);
+
     private final SQL2Parser p = new SQL2Parser(types);
 
     @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=1525140&r1=1525139&r2=1525140&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
Fri Sep 20 20:46:01 2013
@@ -24,7 +24,6 @@ import java.util.Set;
 
 import org.apache.jackrabbit.oak.spi.lifecycle.RepositoryInitializer;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 public class LuceneInitializerHelper implements RepositoryInitializer {
 
@@ -70,22 +69,19 @@ public class LuceneInitializerHelper imp
     }
 
     @Override
-    public NodeState initialize(NodeState state) {
-        if (state.hasChildNode(INDEX_DEFINITIONS_NAME)
-                && state.getChildNode(INDEX_DEFINITIONS_NAME)
-                        .hasChildNode(name)) {
-            return state;
-        }
-        NodeBuilder builder = state.builder();
-
-        if (filePath == null) {
-            newLuceneIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
+    public void initialize(NodeBuilder builder) {
+        if (builder.hasChildNode(INDEX_DEFINITIONS_NAME)
+                && builder.getChildNode(INDEX_DEFINITIONS_NAME).hasChildNode(name))
{
+            // do nothing
+        } else if (filePath == null) {
+            newLuceneIndexDefinition(
+                    builder.child(INDEX_DEFINITIONS_NAME),
                     name, propertyTypes, excludes, async);
         } else {
-            newLuceneFileIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME),
+            newLuceneFileIndexDefinition(
+                    builder.child(INDEX_DEFINITIONS_NAME),
                     name, propertyTypes, excludes, filePath, async);
         }
-        return builder.getNodeState();
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java?rev=1525140&r1=1525139&r2=1525140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-lucene/src/test/java/org/apache/jackrabbit/oak/plugins/index/lucene/LuceneIndexTest.java
Fri Sep 20 20:46:01 2013
@@ -55,7 +55,7 @@ public class LuceneIndexTest {
             new IndexUpdateProvider(
                     new LuceneIndexEditorProvider().with(analyzer)));
 
-    private NodeState root = new InitialContent().initialize(EMPTY_NODE);
+    private NodeState root = InitialContent.INITIAL_CONTENT;
 
     private NodeBuilder builder = root.builder();
 



Mime
View raw message