jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1513924 - 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, 14 Aug 2013 15:04:24 GMT
Author: mduerig
Date: Wed Aug 14 15:04:23 2013
New Revision: 1513924

URL: http://svn.apache.org/r1513924
Log:
OAK-659 Move purge logic for transient changes below the NodeBuilder interface
KernelNodeBuilder and RootNodeBuilder should return correct base node state

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=1513924&r1=1513923&r2=1513924&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 Aug 14 15:04:23 2013
@@ -21,6 +21,7 @@ import static com.google.common.base.Pre
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
  * This class refines move and copy operations by delegating
@@ -31,7 +32,7 @@ public class KernelNodeBuilder extends M
 
     private final KernelRootBuilder root;
 
-    public KernelNodeBuilder(MemoryNodeBuilder parent, String name, KernelRootBuilder root)
{
+    KernelNodeBuilder(MemoryNodeBuilder parent, String name, KernelRootBuilder root) {
         super(parent, name);
         this.root = checkNotNull(root);
     }
@@ -43,6 +44,17 @@ public class KernelNodeBuilder extends M
         return new KernelNodeBuilder(this, name, root);
     }
 
+    // TODO optimise this by caching similar to what we do in MemoryNodeBuilder
+    @Override
+    public NodeState getBaseState() {
+        return getParent().getBaseState().getChildNode(getName());
+    }
+
+    @Override
+    public void reset(NodeState newBase) {
+        throw new IllegalStateException("Cannot reset a non-root builder");
+    }
+
     /**
      * If {@code newParent} is a {@link KernelNodeBuilder} this implementation
      * purges all pending changes before applying the move operation. This allows the

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=1513924&r1=1513923&r2=1513924&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 Aug 14 15:04:23 2013
@@ -44,6 +44,14 @@ class KernelRootBuilder extends MemoryNo
     private final NodeStore store;
 
     /**
+     * The base state of this builder, possibly non-existent if this builder
+     * represents a new node that didn't yet exist in the base content tree.
+     * This differs from the base state of super since the latter one reflects
+     * the base created by the last purge.
+     */
+    private NodeState base;
+
+    /**
      * Private branch used to hold pending changes exceeding {@link #UPDATE_LIMIT}
      */
     private NodeStoreBranch branch;
@@ -53,14 +61,27 @@ class KernelRootBuilder extends MemoryNo
      */
     private int updates = 0;
 
-    public KernelRootBuilder(KernelNodeState base, KernelNodeStore store) {
+    KernelRootBuilder(KernelNodeState base, KernelNodeStore store) {
         super(checkNotNull(base));
+        this.base = base;
         this.store = store;
         this.branch = store.branch(base);
     }
 
     //--------------------------------------------------< MemoryNodeBuilder >---
 
+
+    @Override
+    public NodeState getBaseState() {
+        return base;
+    }
+
+    @Override
+    public void reset(NodeState newBase) {
+        base = newBase;
+        super.reset(newBase);
+    }
+
     @Override
     protected MemoryNodeBuilder createChildBuilder(String name) {
         return new KernelNodeBuilder(this, name, this);
@@ -116,7 +137,7 @@ class KernelRootBuilder extends MemoryNo
     boolean move(String source, String target) {
         purge();
         boolean success = branch.move(source, target);
-        reset(branch.getHead());
+        super.reset(branch.getHead());
         return success;
     }
 
@@ -129,13 +150,13 @@ class KernelRootBuilder extends MemoryNo
     boolean copy(String source, String target) {
         purge();
         boolean success = branch.copy(source, target);
-        reset(branch.getHead());
+        super.reset(branch.getHead());
         return success;
     }
 
     private void purge() {
         branch.setRoot(getNodeState());
-        reset(branch.getHead());
+        super.reset(branch.getHead());
         updates = 0;
     }
 }

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=1513924&r1=1513923&r2=1513924&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 Aug 14 15:04:23 2013
@@ -199,6 +199,20 @@ public class MemoryNodeBuilder implement
         }
     }
 
+    /**
+     * Accessor for parent builder
+     */
+    protected final MemoryNodeBuilder getParent() {
+        return parent;
+    }
+
+    /**
+     * Accoessor for name
+     */
+    protected final String getName() {
+        return name;
+    }
+
     //--------------------------------------------------------< NodeBuilder >---
 
     @Override



Mime
View raw message