You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2013/09/23 22:22:34 UTC

svn commit: r1525682 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java

Author: jukka
Date: Mon Sep 23 20:22:33 2013
New Revision: 1525682

URL: http://svn.apache.org/r1525682
Log:
OAK-1036: SegmentMK: Auto-flushing SegmentNodeBuilder

Make it possible for a subclass to set the head state of a MemoryNodeBuilder without affecting the base state

Modified:
    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/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=1525682&r1=1525681&r2=1525682&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 Mon Sep 23 20:22:33 2013
@@ -213,10 +213,27 @@ public class MemoryNodeBuilder implement
         return name;
     }
 
+    /**
+     * Throws away all changes in this builder and resets the base to the
+     * given node state.
+     *
+     * @param newBase new base state
+     */
     public void reset(NodeState newBase) {
         base = checkNotNull(newBase);
         baseRevision++;
-        head().reset();
+        head().setState(newBase);
+    }
+
+    /**
+     * Replaces the current state of this builder with the given node state.
+     * The base state remains unchanged.
+     *
+     * @param newHead new head state
+     */
+    protected void set(NodeState newHead) {
+        baseRevision++; // this forces all sub-builders to refresh their heads
+        head().setState(newHead);
     }
 
     //--------------------------------------------------------< NodeBuilder >---
@@ -483,9 +500,10 @@ public class MemoryNodeBuilder implement
          */
         public abstract boolean isModified();
 
-        public void reset() {
+        public void setState(NodeState state) {
             throw new IllegalStateException("Cannot reset a non-root builder");
         }
+
     }
 
     private class UnconnectedHead extends Head {
@@ -603,10 +621,11 @@ public class MemoryNodeBuilder implement
         }
 
         @Override
-        public final void reset() {
-            state = new MutableNodeState(base);
+        public final void setState(NodeState state) {
+            this.state = new MutableNodeState(state);
             revision++;
         }
+
     }
 
 }