jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1525189 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/osgi/ main/java/org/apache/jackrabbit/oak/plugins/memory/ main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ main/java/org/apache/jackrabbit/oak/...
Date Sat, 21 Sep 2013 02:24:22 GMT
Author: jukka
Date: Sat Sep 21 02:24:21 2013
New Revision: 1525189

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

Use NodeBuilders in RepositoryInitializers

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ApplyDiff.java
  (with props)
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/privilege/PrivilegeInitializer.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/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

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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 2013
@@ -18,9 +18,11 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
+import javax.annotation.Nonnull;
+
 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 +41,8 @@ public class OsgiRepositoryInitializer
     }
 
     @Override
-    public NodeState initialize(NodeState state) {
-        return new CompositeInitializer(getServices()).initialize(state);
+    public void initialize(@Nonnull 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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 2013
@@ -47,11 +47,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
     protected void reset(NodeBuilder builder, NodeState state) {
         checkArgument(builder instanceof MemoryNodeBuilder);

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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 2013
@@ -16,26 +16,27 @@
  */
 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.ApplyDiff;
 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 +46,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 +70,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 +81,13 @@ 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);
-        }
-        BuiltInNodeTypes.register(new SystemRoot(store, new EditorHook(new RegistrationEditorProvider())));
-        return store.getRoot();
+
+        NodeState base = builder.getNodeState();
+        NodeStore store = new MemoryNodeStore(base);
+        BuiltInNodeTypes.register(new SystemRoot(
+                store, new EditorHook(new RegistrationEditorProvider())));
+        NodeState target = store.getRoot();
+        target.compareAgainstBaseState(base, new ApplyDiff(builder));
     }
 
 }

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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 2013
@@ -16,23 +16,19 @@
  */
 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.ApplyDiff;
 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 +43,24 @@ 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);
-            }
-
+            NodeState base = builder.getNodeState();
+            NodeStore store = new MemoryNodeStore(base);
             try {
                 new PrivilegeDefinitionWriter(new SystemRoot(store)).writeBuiltInDefinitions();
             } catch (RepositoryException e) {
                 log.error("Failed to register built-in privileges", e);
                 throw new RuntimeException(e);
             }
-            return store.getRoot();
+            NodeState target = store.getRoot();
+            target.compareAgainstBaseState(base, new ApplyDiff(builder));
         }
-        return root.getNodeState();
     }
 }

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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 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,13 @@ 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));
         try {
-            branch.merge(new EditorHook(new IndexUpdateProvider(indexEditor)), PostCommitHook.EMPTY);
+            NodeBuilder builder = store.getRoot().builder();
+            initializer.initialize(builder);
+            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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 2013
@@ -18,7 +18,9 @@
  */
 package org.apache.jackrabbit.oak.spi.lifecycle;
 
-import org.apache.jackrabbit.oak.spi.state.NodeState;
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 
 /**
  * Initializer of repository content. A component that needs to add specific
@@ -29,13 +31,11 @@ import org.apache.jackrabbit.oak.spi.sta
 public interface RepositoryInitializer {
 
     /**
-     * Default implementation that returns the given {@code state} without
-     * making any changes.
+     * Default implementation makes no changes to the repository.
      */
     RepositoryInitializer DEFAULT = new RepositoryInitializer() {
         @Override
-        public NodeState initialize(NodeState state) {
-            return state;
+        public void initialize(@Nonnull NodeBuilder builder) {
         }
     };
 
@@ -45,7 +45,7 @@ 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);
 }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ApplyDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ApplyDiff.java?rev=1525189&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ApplyDiff.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ApplyDiff.java
Sat Sep 21 02:24:21 2013
@@ -0,0 +1,97 @@
+/*
+ * 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.spi.state;
+
+import org.apache.jackrabbit.oak.api.PropertyState;
+
+/**
+ * A node state diff handler that applies all reported changes
+ * as-is to the given node builder. No conflict detection or resolution
+ * is attempted. The main use case for this class is to call all the
+ * {@link NodeBuilder} methods necessary to go from a given base state
+ * to any given target state.
+ * <p>
+ * The expected usage pattern looks like this:
+ * <pre>
+ * NodeState base = ...;
+ * NodeState target = ...;
+ * NodeBuilder builder = base.builder();
+ * target.compareAgainstBaseState(base, new ReapplyDiff(builder));
+ * assertEquals(target, builder.getNodeState());
+ * </pre>
+ * <p>
+ * Alternatively, the {@link #apply(NodeState)} method can be used to set
+ * the content of a given builder:
+ * <pre>
+ * NodeBuilder builder = ...;
+ * NodeState target = ...;
+ * new ApplyDiff(builder).apply(target);
+ * assertEquals(target, builder.getNodeState());
+ * </pre>
+ */
+public class ApplyDiff implements NodeStateDiff {
+
+    private final NodeBuilder builder;
+
+    public ApplyDiff(NodeBuilder builder) {
+        this.builder = builder;
+    }
+
+    public void apply(NodeState target) {
+        target.compareAgainstBaseState(builder.getNodeState(), this);
+    }
+
+    @Override
+    public boolean propertyAdded(PropertyState after) {
+        builder.setProperty(after);
+        return true;
+    }
+
+    @Override
+    public boolean propertyChanged(PropertyState before, PropertyState after) {
+        builder.setProperty(after);
+        return true;
+    }
+
+    @Override
+    public boolean propertyDeleted(PropertyState before) {
+        builder.removeProperty(before.getName());
+        return true;
+    }
+
+    @Override
+    public boolean childNodeAdded(String name, NodeState after) {
+        builder.setChildNode(name, after);
+        return true;
+    }
+
+    @Override
+    public boolean childNodeChanged(
+            String name, NodeState before, NodeState after) {
+        return after.compareAgainstBaseState(
+                before, new ApplyDiff(builder.getChildNode(name)));
+    }
+
+    @Override
+    public boolean childNodeDeleted(String name, NodeState before) {
+        builder.getChildNode(name).remove();
+        return true;
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ApplyDiff.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 2013
@@ -22,8 +22,8 @@ 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.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.INITIAL_CONTENT;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -35,7 +35,6 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexEditorProvider;
 import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexLookup;
-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;
@@ -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 = 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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 2013
@@ -25,6 +25,7 @@ import static org.apache.jackrabbit.oak.
 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.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.INITIAL_CONTENT;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -60,7 +61,7 @@ public class PropertyIndexTest {
 
     @Test
     public void testPropertyLookup() throws Exception {
-        NodeState root = new InitialContent().initialize(EMPTY_NODE);
+        NodeState root = INITIAL_CONTENT;
 
         // Add index definition
         NodeBuilder builder = root.builder();
@@ -105,7 +106,7 @@ public class PropertyIndexTest {
 
     @Test
     public void testCustomConfigPropertyLookup() throws Exception {
-        NodeState root = new InitialContent().initialize(EMPTY_NODE);
+        NodeState root = INITIAL_CONTENT;
 
         // Add index definition
         NodeBuilder builder = root.builder();
@@ -153,7 +154,7 @@ public class PropertyIndexTest {
      */
     @Test
     public void testCustomConfigNodeType() throws Exception {
-        NodeState root = new InitialContent().initialize(EMPTY_NODE);
+        NodeState root = 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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 2013
@@ -17,13 +17,13 @@
 package org.apache.jackrabbit.oak.plugins.nodetype;
 
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.INITIAL_CONTENT;
 import static org.easymock.EasyMock.createControl;
 import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.replay;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
-import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.spi.commit.EditorHook;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -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 = 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=1525189&r1=1525188&r2=1525189&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
Sat Sep 21 02:24:21 2013
@@ -18,12 +18,11 @@ 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 static org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent.INITIAL_CONTENT;
 
 import java.text.ParseException;
 
-import org.apache.jackrabbit.oak.plugins.nodetype.write.InitialContent;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.junit.Test;
 
@@ -32,8 +31,9 @@ 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 =
+            INITIAL_CONTENT.getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
+
     private final SQL2Parser p = new SQL2Parser(types);
 
     @Test



Mime
View raw message