jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1354080 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/kernel/ main/java/org/apache/jackrabbit/oak/spi/commit/ test/java/org/apache/jackrabbit/oak/core/ test/java/org/apache/jackrabbit/oak/kernel/
Date Tue, 26 Jun 2012 16:06:31 GMT
Author: jukka
Date: Tue Jun 26 16:06:27 2012
New Revision: 1354080

URL: http://svn.apache.org/viewvc?rev=1354080&view=rev
Log:
OAK-153: Split the CommitHook interface

Rename hooks to editors

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/AbstractOakTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java?rev=1354080&r1=1354079&r2=1354080&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
Tue Jun 26 16:06:27 2012
@@ -127,11 +127,11 @@ class KernelNodeStoreBranch implements N
 
         NodeState preMergeRoot = store.getRoot();
         NodeState oldRoot = preMergeRoot;
-        NodeState toCommit = editor.beforeCommit(store, oldRoot, currentRoot);
+        NodeState toCommit = editor.editCommit(store, oldRoot, currentRoot);
         while (!currentRoot.equals(toCommit)) {
             setRoot(toCommit);
             oldRoot = store.getRoot();
-            toCommit = editor.beforeCommit(store, oldRoot, currentRoot);
+            toCommit = editor.editCommit(store, oldRoot, currentRoot);
         }
 
         try {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java?rev=1354080&r1=1354079&r2=1354080&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitEditor.java
Tue Jun 26 16:06:27 2012
@@ -38,16 +38,8 @@ import javax.annotation.Nonnull;
 public interface CommitEditor {
 
     /**
-     * Before-commit hook. The implementation can validate, record or
-     * modify the staged commit. After all available before-commit hooks
-     * have been processed and none of them has thrown an exception the
-     * collected changes are committed to the underlying storage model.
-     * <p>
-     * Note that a before-commit hook can be executed multiple times for
-     * the same change, for example when a change needs to be retried
-     * after possible merge conflicts have been resolved. Use the
-     * after-commit hook if you need to be notified only once for each
-     * change.
+     * Validates and/or modifies the given content change before it gets
+     * persisted.
      *
      * @param store the node store that contains the repository content
      * @param before content tree before the commit
@@ -56,7 +48,7 @@ public interface CommitEditor {
      * @throws CommitFailedException if the commit should be rejected
      */
     @Nonnull
-    NodeState beforeCommit(NodeStore store, NodeState before, NodeState after)
+    NodeState editCommit(NodeStore store, NodeState before, NodeState after)
         throws CommitFailedException;
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java?rev=1354080&r1=1354079&r2=1354080&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeEditor.java
Tue Jun 26 16:06:27 2012
@@ -23,25 +23,28 @@ import org.apache.jackrabbit.oak.spi.sta
 import java.util.List;
 
 /**
- * This {@code CommitHook} aggregates a list of commit hooks into
- * a single commit hook.
+ * Composite commit editor. Maintains a list of component editors and takes
+ * care of calling them in proper sequence in the
+ * {@link #editCommit(NodeStore, NodeState, NodeState)} method.
  */
 public class CompositeEditor implements CommitEditor {
-    private final List<CommitEditor> hooks;
 
-    public CompositeEditor(List<CommitEditor> hooks) {
-        this.hooks = hooks;
+    private final List<CommitEditor> editors;
+
+    public CompositeEditor(List<CommitEditor> editors) {
+        this.editors = editors;
     }
 
     @Override
-    public NodeState beforeCommit(NodeStore store, NodeState before, NodeState after)
+    public NodeState editCommit(
+            NodeStore store, NodeState before, NodeState after)
             throws CommitFailedException {
 
         NodeState oldState = before;
         NodeState newState = after;
-        for (CommitEditor hook : hooks) {
+        for (CommitEditor editor : editors) {
             NodeState newOldState = newState;
-            newState = hook.beforeCommit(store, oldState, newState);
+            newState = editor.editCommit(store, oldState, newState);
             oldState = newOldState;
         }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java?rev=1354080&r1=1354079&r2=1354080&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/EmptyEditor.java
Tue Jun 26 16:06:27 2012
@@ -43,7 +43,7 @@ public class EmptyEditor implements Comm
     public static final CommitEditor INSTANCE = new EmptyEditor();
 
     @Override
-    public NodeState beforeCommit(
+    public NodeState editCommit(
             NodeStore store, NodeState before, NodeState after)
             throws CommitFailedException {
         return after;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java?rev=1354080&r1=1354079&r2=1354080&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ValidatingEditor.java
Tue Jun 26 16:06:27 2012
@@ -43,7 +43,7 @@ public class ValidatingEditor implements
     }
 
     @Override
-    public NodeState beforeCommit(
+    public NodeState editCommit(
             NodeStore store, NodeState before, NodeState after)
             throws CommitFailedException {
         Validator validator = validatorProvider.getRootValidator(before, after);

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/AbstractOakTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/AbstractOakTest.java?rev=1354080&r1=1354079&r2=1354080&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/AbstractOakTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/AbstractOakTest.java
Tue Jun 26 16:06:27 2012
@@ -47,13 +47,13 @@ public abstract class AbstractOakTest {
     @Before
     public void setUp() {
         MicroKernel microKernel = new MicroKernelImpl();
-        store = new KernelNodeStore(microKernel, createCommitHook());
+        store = new KernelNodeStore(microKernel, createCommitEditor());
         valueFactory = store.getValueFactory();
 
         state = createInitialState(microKernel);
     }
 
-    protected CommitEditor createCommitHook() {
+    protected CommitEditor createCommitEditor() {
         return new EmptyEditor();
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java?rev=1354080&r1=1354079&r2=1354080&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java
Tue Jun 26 16:06:27 2012
@@ -36,7 +36,7 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertNull;
 
 public class KernelNodeStoreTest extends AbstractOakTest {
-    private final CommitHookDelegate commitHookDelegate = new CommitHookDelegate();
+    private final CommitEditorDelegate commitHookDelegate = new CommitEditorDelegate();
 
     private NodeState root;
 
@@ -51,7 +51,7 @@ public class KernelNodeStoreTest extends
     }
 
     @Override
-    protected CommitEditor createCommitHook() {
+    protected CommitEditor createCommitEditor() {
         return commitHookDelegate;
     }
 
@@ -139,7 +139,7 @@ public class KernelNodeStoreTest extends
         rootBuilder.setNode("test", testBuilder.getNodeState());
         final NodeState newRoot = rootBuilder.getNodeState();
 
-        commitWithHook(newRoot, new EmptyEditor() {
+        commitWithEditor(newRoot, new EmptyEditor() {
 // TODO: OAK-153 - use the Observer interface to observe content changes
 //            @Override
 //            public void afterCommit(NodeStore store, NodeState before, NodeState after)
{
@@ -170,9 +170,9 @@ public class KernelNodeStoreTest extends
         rootBuilder.setNode("test", testBuilder.getNodeState());
         final NodeState newRoot = rootBuilder.getNodeState();
 
-        commitWithHook(newRoot, new EmptyEditor() {
+        commitWithEditor(newRoot, new EmptyEditor() {
             @Override
-            public NodeState beforeCommit(NodeStore store, NodeState before, NodeState after)
{
+            public NodeState editCommit(NodeStore store, NodeState before, NodeState after)
{
                 NodeStateBuilder rootBuilder = store.getBuilder(after);
                 NodeStateBuilder testBuilder = store.getBuilder(after.getChildNode("test"));
                 testBuilder.setNode("fromHook", MemoryNodeState.EMPTY_NODE);
@@ -191,10 +191,10 @@ public class KernelNodeStoreTest extends
 
     //------------------------------------------------------------< private >---
 
-    private void commitWithHook(NodeState nodeState, CommitEditor commitHook)
+    private void commitWithEditor(NodeState nodeState, CommitEditor editor)
             throws CommitFailedException {
 
-        commitHookDelegate.set(commitHook);
+        commitHookDelegate.set(editor);
         try {
             NodeStoreBranch branch = store.branch();
             branch.setRoot(nodeState);
@@ -205,18 +205,18 @@ public class KernelNodeStoreTest extends
         }
     }
 
-    private static class CommitHookDelegate implements CommitEditor {
+    private static class CommitEditorDelegate implements CommitEditor {
         private CommitEditor delegate = new EmptyEditor();
 
-        public void set(CommitEditor commitHook) {
-            delegate = commitHook;
+        public void set(CommitEditor editor) {
+            delegate = editor;
         }
 
         @Override
-        public NodeState beforeCommit(NodeStore store, NodeState before, NodeState after)
+        public NodeState editCommit(NodeStore store, NodeState before, NodeState after)
                 throws CommitFailedException {
 
-            return delegate.beforeCommit(store, before, after);
+            return delegate.editCommit(store, before, after);
         }
 
     }



Mime
View raw message