jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1401801 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: kernel/KernelNodeBuilder.java kernel/KernelRootBuilder.java plugins/memory/MemoryNodeBuilder.java
Date Wed, 24 Oct 2012 18:04:38 GMT
Author: jukka
Date: Wed Oct 24 18:04:37 2012
New Revision: 1401801

URL: http://svn.apache.org/viewvc?rev=1401801&view=rev
Log:
OAK-170: Child node state builder

Fix base state tracking in MemoryNodeBuilder.setNode().
The child builder will be based on the original base state, but the associated MutableNodeState
instance will use the given new state as its base.
This makes it easier for things like KernelRootBuilder to automatically detecting moves and
copies.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java?rev=1401801&r1=1401800&r2=1401801&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
Wed Oct 24 18:04:37 2012
@@ -19,25 +19,22 @@ package org.apache.jackrabbit.oak.kernel
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 class KernelNodeBuilder extends MemoryNodeBuilder {
 
     private final KernelRootBuilder root;
 
     public KernelNodeBuilder(
-            MemoryNodeBuilder parent, String name,
-            NodeState base, KernelRootBuilder root) {
-        super(parent, name, base);
+            MemoryNodeBuilder parent, String name, KernelRootBuilder root) {
+        super(parent, name);
         this.root = checkNotNull(root);
     }
 
     //--------------------------------------------------< MemoryNodeBuilder >---
 
     @Override
-    protected MemoryNodeBuilder createChildBuilder(
-            String name, NodeState child) {
-        return new KernelNodeBuilder(this, name, child, root);
+    protected MemoryNodeBuilder createChildBuilder(String name) {
+        return new KernelNodeBuilder(this, name, root);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java?rev=1401801&r1=1401800&r2=1401801&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelRootBuilder.java
Wed Oct 24 18:04:37 2012
@@ -55,9 +55,8 @@ class KernelRootBuilder extends MemoryNo
     //--------------------------------------------------< MemoryNodeBuilder >---
 
     @Override
-    protected MemoryNodeBuilder createChildBuilder(
-            String name, NodeState child) {
-        return new KernelNodeBuilder(this, name, child, this);
+    protected MemoryNodeBuilder createChildBuilder(String name) {
+        return new KernelNodeBuilder(this, name, this);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1401801&r1=1401800&r2=1401801&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Wed Oct 24 18:04:37 2012
@@ -116,17 +116,15 @@ public class MemoryNodeBuilder implement
      *
      * @param parent parent node state builder
      * @param name name of this node
-     * @param base base state of this node, or {@code null}
      */
-    protected MemoryNodeBuilder(
-            MemoryNodeBuilder parent, String name, NodeState base) {
+    protected MemoryNodeBuilder(MemoryNodeBuilder parent, String name) {
         this.parent = checkNotNull(parent);
         this.name = checkNotNull(name);
 
         this.root = parent.root;
         this.revision = parent.revision;
 
-        this.baseState = base;
+        this.baseState = null;
         this.writeState = null;
     }
 
@@ -222,12 +220,10 @@ public class MemoryNodeBuilder implement
      * Factory method for creating new child state builders. Subclasses may
      * override this method to control the behavior of child state builders.
      *
-     * @param child base state of the new builder, or {@code null}
      * @return new builder
      */
-    protected MemoryNodeBuilder createChildBuilder(
-            String name, NodeState child) {
-        return new MemoryNodeBuilder(this, name, child);
+    protected MemoryNodeBuilder createChildBuilder(String name) {
+        return new MemoryNodeBuilder(this, name);
     }
 
     /**
@@ -293,15 +289,14 @@ public class MemoryNodeBuilder implement
 
     @Override @Nonnull
     public NodeBuilder setNode(String name, NodeState state) {
-        MutableNodeState mstate = write();
+        write();
 
-        MutableNodeState cstate = mstate.nodes.get(name);
-        if (cstate != null) {
-            cstate.reset(state);
-        } else {
-            mstate.nodes.remove(name);
-            createChildBuilder(name, state).write();
+        MutableNodeState childState = writeState.nodes.get(name);
+        if (childState == null) {
+            writeState.nodes.remove(name);
+            childState = createChildBuilder(name).write();
         }
+        childState.reset(state);
 
         updated();
         return this;
@@ -373,14 +368,9 @@ public class MemoryNodeBuilder implement
 
     @Override
     public NodeBuilder child(String name) {
-        // look for a read-only child node
-        read();
-        if (writeState == null) {
-            assert baseState != null; // guaranteed by read()
-            NodeState childBase = baseState.getChildNode(name);
-            if (childBase != null) { // read-only shortcut
-                return createChildBuilder(name, childBase);
-            }
+        read(); // shortcut when dealing with a read-only child node
+        if (writeState == null && baseState.hasChildNode(name)) {
+            return createChildBuilder(name);
         }
 
         // no read-only child node found, switch to write mode
@@ -402,7 +392,7 @@ public class MemoryNodeBuilder implement
             writeState.nodes.put(name, new MutableNodeState(childBase));
         }
 
-        MemoryNodeBuilder builder = createChildBuilder(name, childBase);
+        MemoryNodeBuilder builder = createChildBuilder(name);
         builder.write();
         return builder;
     }



Mime
View raw message