jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1401737 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: plugins/memory/MemoryNodeBuilder.java spi/state/NodeBuilder.java spi/state/ReadOnlyBuilder.java
Date Wed, 24 Oct 2012 15:44:45 GMT
Author: jukka
Date: Wed Oct 24 15:44:44 2012
New Revision: 1401737

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

Introduce NodeBuilder.getBaseState() to simplify state tracking

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java

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=1401737&r1=1401736&r2=1401737&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 15:44:44 2012
@@ -100,11 +100,10 @@ public class MemoryNodeBuilder implement
     private long revision;
 
     /**
-     * The read state of this builder. Originally the immutable base state
-     * in an unconnected builder, or the shared mutable state
-     * (see {@link #writeState}) once the this builder has been connected.
+     * The base state of this builder, or {@code null} if this builder
+     * represents a new node that didn't yet exist in the base content tree.
      */
-    private NodeState readState;
+    private final NodeState baseState;
 
     /**
      * The shared mutable state of connected builder instances, or
@@ -117,7 +116,7 @@ public class MemoryNodeBuilder implement
      *
      * @param parent parent node state builder
      * @param name name of this node
-     * @param base base state of this node
+     * @param base base state of this node, or {@code null}
      */
     protected MemoryNodeBuilder(
             MemoryNodeBuilder parent, String name, NodeState base) {
@@ -127,7 +126,7 @@ public class MemoryNodeBuilder implement
         this.root = parent.root;
         this.revision = parent.revision;
 
-        this.readState = checkNotNull(base);
+        this.baseState = base;
         this.writeState = null;
     }
 
@@ -136,16 +135,15 @@ public class MemoryNodeBuilder implement
      *
      * @param base base state of the new builder
      */
-    public MemoryNodeBuilder(NodeState base) {
+    public MemoryNodeBuilder(@Nonnull NodeState base) {
         this.parent = null;
         this.name = null;
 
         this.root = this;
         this.revision = 0;
 
-        MutableNodeState mstate = new MutableNodeState(checkNotNull(base));
-        this.readState = mstate;
-        this.writeState = mstate;
+        this.baseState = checkNotNull(base);
+        this.writeState = new MutableNodeState(baseState);
     }
 
     private NodeState read() {
@@ -161,13 +159,17 @@ public class MemoryNodeBuilder implement
                                 "This node has been removed.");
                     }
                 } else if (mstate != writeState) {
-                    readState = mstate;
                     writeState = mstate;
                 }
             }
             revision = root.revision;
         }
-        return readState;
+        if (writeState != null) {
+            return writeState;
+        } else {
+            assert baseState != null; // new nodes must have a writeState
+            return baseState;
+        }
     }
 
     private MutableNodeState write() {
@@ -184,11 +186,14 @@ public class MemoryNodeBuilder implement
                     throw new IllegalStateException(
                             "This node has been removed.");
                 }
-                mstate = new MutableNodeState(readState);
+                NodeState base = baseState;
+                if (base == null) {
+                    base = NULL_STATE;
+                }
+                mstate = new MutableNodeState(base);
                 pstate.nodes.put(name, mstate);
             }
             if (mstate != writeState) {
-                readState = mstate;
                 writeState = mstate;
             }
         }
@@ -243,6 +248,11 @@ public class MemoryNodeBuilder implement
     }
 
     @Override
+    public NodeState getBaseState() {
+        return baseState;
+    }
+
+    @Override
     public long getChildNodeCount() {
         return read().getChildNodeCount();
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java?rev=1401737&r1=1401736&r2=1401737&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
Wed Oct 24 15:44:44 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.spi.state;
 
+import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
@@ -36,6 +37,16 @@ public interface NodeBuilder {
     NodeState getNodeState();
 
     /**
+     * Returns the original base state that this builder is modifying.
+     * Returns {@code null} if this builder represents a new node that
+     * didn't exist in the base content tree.
+     *
+     * @return base node state, or {@code null}
+     */
+    @CheckForNull
+    NodeState getBaseState();
+
+    /**
      * Returns the current number of child nodes.
      *
      * @return number of child nodes
@@ -59,7 +70,7 @@ public interface NodeBuilder {
     Iterable<String> getChildNodeNames();
 
     /**
-     * Adds or replaces a sub-ree.
+     * Adds or replaces a subtree.
      *
      * @param name name of the child node containing the new subtree
      * @param nodeState subtree

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java?rev=1401737&r1=1401736&r2=1401737&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/ReadOnlyBuilder.java
Wed Oct 24 15:44:44 2012
@@ -43,6 +43,11 @@ public class ReadOnlyBuilder implements 
     }
 
     @Override
+    public NodeState getBaseState() {
+        return state;
+    }
+
+    @Override
     public long getChildNodeCount() {
         return state.getChildNodeCount();
     }



Mime
View raw message