jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1338273 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreTest.java
Date Mon, 14 May 2012 16:23:13 GMT
Author: mduerig
Date: Mon May 14 16:23:13 2012
New Revision: 1338273

URL: http://svn.apache.org/viewvc?rev=1338273&view=rev
Log:
OAK-100: Proper CommitHook handling in NodeStore
- make NodeStore.getBuilder() work for NodeDecorator instances

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.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/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1338273&r1=1338272&r2=1338273&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
Mon May 14 16:23:13 2012
@@ -97,12 +97,21 @@ public class KernelNodeStore extends Abs
 
     @Override
     public NodeStateBuilder getBuilder(NodeState base) {
-        if (!(base instanceof KernelNodeState)) {
-            throw new IllegalArgumentException("Alien node state " + base.getClass() + ":
" + root);
+        if (base instanceof KernelNodeState) {
+                NodeStateBuilderContext context = new NodeStateBuilderContext((KernelNodeState)
base);
+                return KernelNodeStateBuilder.create(context);
         }
+        else if (base instanceof NodeStateBuilderContext.NodeDecorator) {
+            NodeState root = ((NodeStateBuilderContext.NodeDecorator) base).getRoot();
+            if (root != base) {
+                throw new IllegalArgumentException("Not root:" + base);
+            }
 
-        NodeStateBuilderContext context = new NodeStateBuilderContext((KernelNodeState) base);
-        return KernelNodeStateBuilder.create(context);
+            return KernelNodeStateBuilder.create(((NodeStateBuilderContext.NodeDecorator)
base).getContext());
+        }
+        else {
+            throw new IllegalArgumentException("Alien node state " + base.getClass() + ":
" + root);
+        }
     }
 
     @Override
@@ -505,9 +514,17 @@ public class KernelNodeStore extends Abs
                 return applyPendingChanges();
             }
 
-            NodeState getBase() {
+            KernelNodeState getBase() {
                 return base;
             }
+
+            NodeStateBuilderContext getContext() {
+                return NodeStateBuilderContext.this;
+            }
+
+            NodeState getRoot() {
+                return root;
+            }
         }
 
         private class RootNodeDecorator extends NodeDecorator {

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=1338273&r1=1338272&r2=1338273&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
Mon May 14 16:23:13 2012
@@ -27,7 +27,6 @@ import org.apache.jackrabbit.oak.spi.com
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -111,7 +110,6 @@ public class KernelNodeStoreTest extends
     }
 
     @Test
-    @Ignore ("WIP") // TODO OAK-100: NodeStore.getBuilder() only works for KernelNodeState
type arguments
     public void beforeCommitHook() throws CommitFailedException {
         NodeState test = store.getRoot().getChildNode("test");
         NodeStateBuilder testBuilder = store.getBuilder(test);
@@ -120,7 +118,6 @@ public class KernelNodeStoreTest extends
         testBuilder.removeNode("a");
         final CoreValue fortyTwo = store.getValueFactory().createValue(42);
         newNodeBuilder.setProperty("n", fortyTwo);
-        final NodeState testState = testBuilder.getNodeState();
 
         commitWithHook(testBuilder.getNodeState(), new EmptyCommitHook() {
             @Override
@@ -131,11 +128,12 @@ public class KernelNodeStoreTest extends
             }
         });
 
-        assertNotNull(testState.getChildNode("newNode"));
-        assertNotNull(testState.getChildNode("fromHook"));
-        assertNull(testState.getChildNode("a"));
-        assertEquals(fortyTwo, testState.getChildNode("newNode").getProperty("n").getValue());
-        assertEquals(testState, store.getRoot().getChildNode("test"));
+        test = store.getRoot().getChildNode("test");
+        assertNotNull(test.getChildNode("newNode"));
+        assertNotNull(test.getChildNode("fromHook"));
+        assertNull(test.getChildNode("a"));
+        assertEquals(fortyTwo, test.getChildNode("newNode").getProperty("n").getValue());
+        assertEquals(test, store.getRoot().getChildNode("test"));
 
     }
 



Mime
View raw message