jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1341834 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
Date Wed, 23 May 2012 11:30:24 GMT
Author: mduerig
Date: Wed May 23 11:30:23 2012
New Revision: 1341834

URL: http://svn.apache.org/viewvc?rev=1341834&view=rev
Log:
OAK-100: Proper CommitHook handling in NodeStore
call CommitHook methods on commit.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.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=1341834&r1=1341833&r2=1341834&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
Wed May 23 11:30:23 2012
@@ -6,6 +6,7 @@ import org.apache.jackrabbit.oak.api.Com
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
@@ -28,7 +29,6 @@ class KernelNodeStoreBranch implements N
     /** Base state of this branch */
     private final NodeState base;
 
-
     /** Revision of this branch in the Microkernel */
     private String branchRevision;
 
@@ -41,7 +41,7 @@ class KernelNodeStoreBranch implements N
     KernelNodeStoreBranch(KernelNodeStore store) {
         this.store = store;
 
-        MicroKernel kernel = getKernel();
+        MicroKernel kernel = store.getKernel();
         this.branchRevision = kernel.branch(null);
         this.currentRoot = new KernelNodeState(kernel, getValueFactory(), "/", branchRevision);
         this.base = currentRoot;
@@ -61,7 +61,7 @@ class KernelNodeStoreBranch implements N
     @Override
     public void setRoot(NodeState newRoot) {
         currentRoot = newRoot;
-        save(buildJsop());
+        commit(buildJsop());
     }
 
     @Override
@@ -80,7 +80,7 @@ class KernelNodeStoreBranch implements N
             return false;
         }
 
-        save(buildJsop() + ">\"" + source + "\":\"" + target + '"');
+        commit(">\"" + source + "\":\"" + target + '"');
         return true;
     }
 
@@ -100,34 +100,40 @@ class KernelNodeStoreBranch implements N
             return false;
         }
 
-        save(buildJsop() + "*\"" + source + "\":\"" + target + '"');
+        commit("*\"" + source + "\":\"" + target + '"');
         return true;
     }
 
     @Override
     public KernelNodeState merge() throws CommitFailedException {
-        save(buildJsop());
-        // TODO rebase, call commitHook (OAK-100)
-        MicroKernel kernel = getKernel();
-        String mergedRevision;
+        // TODO rebase to current trunk?
+        MicroKernel kernel = store.getKernel();
+        CommitHook commitHook = store.getCommitHook();
+
+        NodeState oldRoot = store.getRoot();
+        NodeState toCommit = commitHook.beforeCommit(store, oldRoot, currentRoot);
+        while (!currentRoot.equals(toCommit)) {
+            setRoot(toCommit);
+            oldRoot = store.getRoot();
+            toCommit = commitHook.beforeCommit(store, oldRoot, currentRoot);
+        }
+
         try {
-            mergedRevision = kernel.merge(branchRevision, null);
+            String mergedRevision = kernel.merge(branchRevision, null);
             branchRevision = null;
             currentRoot = null;
             committed = null;
+            KernelNodeState committed = new KernelNodeState(kernel, getValueFactory(), "/",
mergedRevision);
+            commitHook.afterCommit(store, oldRoot, committed);
+            return committed;
         }
         catch (MicroKernelException e) {
             throw new CommitFailedException(e);
         }
-        return new KernelNodeState(kernel, getValueFactory(), "/", mergedRevision);
     }
 
     //------------------------------------------------------------< private >---
 
-    private MicroKernel getKernel() {
-        return store.getKernel();
-    }
-
     private CoreValueFactory getValueFactory() {
         return store.getValueFactory();
     }
@@ -144,8 +150,8 @@ class KernelNodeStoreBranch implements N
         return node;
     }
 
-    private void save(String jsop) {
-        MicroKernel kernel = getKernel();
+    private void commit(String jsop) {
+        MicroKernel kernel = store.getKernel();
         branchRevision = kernel.commit("/", jsop, branchRevision, null);
         currentRoot = new KernelNodeState(kernel, getValueFactory(), "/", branchRevision);
         committed = currentRoot;



Mime
View raw message