jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1308129 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/ oak-jcr/src/main/java/org/apache/jack...
Date Sun, 01 Apr 2012 15:10:43 GMT
Author: mduerig
Date: Sun Apr  1 15:10:42 2012
New Revision: 1308129

URL: http://svn.apache.org/viewvc?rev=1308129&view=rev
Log:
OAK-9: Internal tree builder
use branch to private copy and merge for editing trees

Added:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java
Removed:
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeBuilder.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java?rev=1308129&r1=1308128&r2=1308129&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
Sun Apr  1 15:10:42 2012
@@ -16,8 +16,8 @@
  */
 package org.apache.jackrabbit.oak.api;
 
-import org.apache.jackrabbit.mk.model.NodeBuilder;
 import org.apache.jackrabbit.mk.model.NodeState;
+import org.apache.jackrabbit.mk.model.NodeStateEditor;
 
 import java.io.Closeable;
 
@@ -83,9 +83,9 @@ public interface Connection extends Clos
 
     NodeState getCurrentRoot();
 
-    NodeState commit(NodeState newRoot) throws CommitFailedException;
+    NodeState commit(NodeStateEditor editor) throws CommitFailedException;
 
-    NodeBuilder getNodeBuilder(NodeState state);
+    NodeStateEditor getNodeStateEditor(NodeState state);
 
     // TODO : add versioning operations
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java?rev=1308129&r1=1308128&r2=1308129&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
Sun Apr  1 15:10:42 2012
@@ -17,8 +17,8 @@
 package org.apache.jackrabbit.oak.core;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.model.NodeBuilder;
 import org.apache.jackrabbit.mk.model.NodeState;
+import org.apache.jackrabbit.mk.model.NodeStateEditor;
 import org.apache.jackrabbit.mk.model.NodeStore;
 import org.apache.jackrabbit.oak.api.AuthInfo;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
@@ -94,21 +94,20 @@ public class ConnectionImpl implements C
     }
 
     @Override
-    public NodeState commit(NodeState newRoot) throws CommitFailedException {
+    public NodeState commit(NodeStateEditor editor) throws CommitFailedException {
         if (workspaceName == null) {
-// todo            store.setRoot(newRoot);
+// todo            merge changes from editor into base
             return root = store.getRoot();
         }
         else {
-// todo            NodeBuilder builder = store.getNodeBuilder(store.getRoot());
-//            builder.setChildNode(workspaceName, newRoot);
+// todo            merge changes from editor into base
             return root = store.getRoot().getChildNode(workspaceName);
         }
     }
 
     @Override
-    public NodeBuilder getNodeBuilder(NodeState state) {
-        return store.getNodeBuilder(state);
+    public NodeStateEditor getNodeStateEditor(NodeState state) {
+        return store.branch(state);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1308129&r1=1308128&r2=1308129&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Sun Apr  1 15:10:42 2012
@@ -19,8 +19,8 @@
 package org.apache.jackrabbit.oak.kernel;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.model.NodeBuilder;
 import org.apache.jackrabbit.mk.model.NodeState;
+import org.apache.jackrabbit.mk.model.NodeStateEditor;
 import org.apache.jackrabbit.mk.model.NodeStore;
 
 /**
@@ -40,13 +40,13 @@ public class KernelNodeStore implements 
     }
 
     @Override
-    public void setRoot(NodeState newRoot) {
-        throw new UnsupportedOperationException(); // FIXME
+    public NodeStateEditor branch(NodeState base) {
+        return null; // todo implement branch
     }
 
     @Override
-    public NodeBuilder getNodeBuilder(NodeState base) {
-        throw new UnsupportedOperationException(); // FIXME
+    public NodeState merge(NodeStateEditor branch, NodeState base) {
+        return null; // todo implement merge
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1308129&r1=1308128&r2=1308129&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Sun Apr  1 15:10:42 2012
@@ -213,7 +213,7 @@ public class SessionImpl extends Abstrac
         checkIsAlive();
         try {
             transientSpace.save();
-            connection.commit(connection.getCurrentRoot());  // todo: need a better way to
update a connection to head
+            connection.commit(connection.getNodeStateEditor(connection.getCurrentRoot()));
 // todo: need a better way to update a connection to head
             nodeStateProvider.clear();
         }
         catch (CommitFailedException e) {
@@ -226,7 +226,7 @@ public class SessionImpl extends Abstrac
         checkIsAlive();
         try {
             transientSpace.refresh(keepChanges);
-            connection.commit(connection.getCurrentRoot());  // todo: need a better way to
update a connection to head
+            connection.commit(connection.getNodeStateEditor(connection.getCurrentRoot()));
 // todo: need a better way to update a connection to head
             nodeStateProvider.clear();
         }
         catch (CommitFailedException e) {

Added: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java?rev=1308129&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java
(added)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStateEditor.java
Sun Apr  1 15:10:42 2012
@@ -0,0 +1,72 @@
+package org.apache.jackrabbit.mk.model;
+
+/**
+ * An editor for modifying existing and creating new
+ * {@link NodeState node states}.
+ */
+public interface NodeStateEditor {
+
+    /**
+     * Add or replace the child node state with the given {@code name}.
+     * @param name name of the new node state
+     * @return editor for the added node state
+     */
+    NodeStateEditor addNode(String name);
+
+    /**
+     * Remove the child node state with the given {@code name}.
+     * @param name  name of the node state to remove
+     */
+    void removeNode(String name);
+
+    /**
+     * Set a property on this node state
+     * @param name name of the property
+     * @param value value of the property
+     */
+    void setProperty(String name, Scalar value);
+
+    /**
+     * Remove a property from this node state
+     * @param name name of the property
+     */
+    void removeProperty(String name);
+
+    /**
+     * Move the node state located at {@code sourcePath} to a node
+     * state at {@code destPath}.
+     * @param sourcePath source path relative to this node state
+     * @param destPath destination path relative to this node state
+     */
+    void move(String sourcePath, String destPath);
+
+    /**
+     * Copy the node state located at {@code sourcePath} to a node
+     * state at {@code destPath}.
+     * @param sourcePath source path relative to this node state
+     * @param destPath destination path relative to this node state
+     */
+    void copy(String sourcePath, String destPath);
+
+    /**
+     * Edit the child node state with the given {@code name}.
+     * @param name name of the child node state to edit.
+     * @return editor for the child node state of the given name or
+     *         {@code null} if no such node state exists.
+     */
+    NodeStateEditor edit(String name);
+
+    /**
+     * Returns an immutable node state that matches the current state of
+     * the editor.
+     *
+     * @return immutable node state
+     */
+    NodeState getNodeState();
+
+    /**
+     * Return the base node state of this private branch
+     * @return base node state
+     */
+    NodeState getBaseNodeState();
+}

Modified: jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java?rev=1308129&r1=1308128&r2=1308129&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-mk/src/main/java/org/apache/jackrabbit/mk/model/NodeStore.java
Sun Apr  1 15:10:42 2012
@@ -19,10 +19,10 @@ package org.apache.jackrabbit.mk.model;
 /**
  * Storage abstraction for content trees. At any given point in time
  * the stored content tree is rooted at a single immutable node state.
- * Changes in the tree are constructed using {@link NodeBuilder} instances
- * based on the root and other node states in the tree. The state of the
- * entire tree can then be changed by setting the resulting modified root
- * node state as the new root of the tree.
+ * Changes in the tree are constructed by branching off a private copy
+ * using the {@link #branch(NodeState)} method which can be modified
+ * and merged back using the {@link #merge(NodeStateEditor, NodeState)}
+ * method.
  * <p>
  * This is a low-level interface that doesn't cover functionality like
  * merging concurrent changes or rejecting new tree states based on some
@@ -38,22 +38,25 @@ public interface NodeStore {
     NodeState getRoot();
 
     /**
-     * Updates the state of the content tree.
+     * Creates a private branch from a {@code base} node state
+     * for editing. The branch can later be merged back into
+     * the node store using the {@link #merge(NodeStateEditor, NodeState) merge}
+     * method.
      *
-     * @param newRoot new root node state
+     * @param base base node state
+     * @return a private branch rooted at {@code base}
      */
-    void setRoot(NodeState newRoot);
+    NodeStateEditor branch(NodeState base);
 
     /**
-     * Returns a builder for constructing a new or modified node state.
-     * The builder is initialized with all the properties and child nodes
-     * from the given base node state, or with no properties or child nodes
-     * if no base node state is given.
+     * Atomically merges the changes from {@code branch} back
+     * into the sub-tree rooted at {@code base}.
      *
-     * @param base base node state,
-     *             or <code>null</code> to construct a new node state
-     * @return builder instance
+     * @param branch branch to merge into {@code base}
+     * @param base base of the sub-tree for merging
+     * @return result of the merge operation: the new node state of the
+     *         sub tree rooted at {@code base}.
      */
-    NodeBuilder getNodeBuilder(NodeState base);
+    NodeState merge(NodeStateEditor branch, NodeState base);
 
 }



Mime
View raw message