jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1325794 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/api/ main/java/org/apache/jackrabbit/oak/kernel/ test/java/org/apache/jackrabbit/oak/kernel/
Date Fri, 13 Apr 2012 14:56:21 GMT
Author: angela
Date: Fri Apr 13 14:56:20 2012
New Revision: 1325794

URL: http://svn.apache.org/viewvc?rev=1325794&view=rev
Log:
OAK-18 - Define Oak API (WIP)

- let NodeStateEditor#addNode return the TransientNodeState of the child with that name

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java?rev=1325794&r1=1325793&r2=1325794&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/NodeStateEditor.java
Fri Apr 13 14:56:20 2012
@@ -29,9 +29,11 @@ public interface NodeStateEditor {
     /**
      * Add the child node state with the given {@code name}. Does nothing
      * if such a child node already exists.
+     *
      * @param name name of the new node state
+     * @return the transient state of the child node with that name.
      */
-    void addNode(String name);
+    TransientNodeState addNode(String name);
 
     /**
      * Remove the child node state with the given {@code name}. Does nothing

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java?rev=1325794&r1=1325793&r2=1325794&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditor.java
Fri Apr 13 14:56:20 2012
@@ -79,11 +79,13 @@ public class KernelNodeStateEditor imple
     }
 
     @Override
-    public void addNode(String name) {
+    public TransientNodeState addNode(String name) {
         if (!transientState.hasNode(name)) {
             transientState.addNode(name);
             jsop.append("+\"").append(path(name)).append("\":{}");
         }
+
+        return transientState.getChildNode(name);
     }
 
     @Override
@@ -209,7 +211,7 @@ public class KernelNodeStateEditor imple
 
     /**
      * Path of the item {@code name}
-     * @param name
+     * @param name The item name.
      * @return relative path of the item {@code name}
      */
     private String path(String name) {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java?rev=1325794&r1=1325793&r2=1325794&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/KernelNodeStateEditorTest.java
Fri Apr 13 14:56:20 2012
@@ -127,7 +127,9 @@ public class KernelNodeStateEditorTest {
         TransientNodeState transientState = editor.getTransientState();
 
         assertFalse(transientState.hasNode("new"));
-        editor.addNode("new");
+        TransientNodeState newNode = editor.addNode("new");
+        assertNotNull(newNode);
+        assertEquals("new", newNode.getName());
         assertTrue(transientState.hasNode("new"));
 
         NodeState newState = editor.mergeInto(microkernel, state);
@@ -135,6 +137,23 @@ public class KernelNodeStateEditorTest {
     }
 
     @Test
+    public void addExistingNode() {
+        KernelNodeStateEditor editor = new KernelNodeStateEditor(state);
+        TransientNodeState transientState = editor.getTransientState();
+
+        assertFalse(transientState.hasNode("new"));
+        TransientNodeState newNode = editor.addNode("new");
+        NodeState newState = editor.mergeInto(microkernel, state);
+
+        editor = new KernelNodeStateEditor(newState);
+        transientState = editor.getTransientState();
+        assertTrue(transientState.hasNode("new"));
+        newNode = editor.addNode("new");
+        assertNotNull(newNode);
+        assertEquals("new", newNode.getName());
+    }
+
+    @Test
     public void removeNode() {
         KernelNodeStateEditor editor = new KernelNodeStateEditor(state);
         TransientNodeState transientState = editor.getTransientState();



Mime
View raw message