jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1243634 - in /jackrabbit/sandbox/jackrabbit-microkernel/src: main/java/org/apache/jackrabbit/state/ChangeTree.java main/java/org/apache/jackrabbit/state/NodeState.java test/java/org/apache/jackrabbit/RepositoryTest.java
Date Mon, 13 Feb 2012 18:15:22 GMT
Author: mduerig
Date: Mon Feb 13 18:15:21 2012
New Revision: 1243634

URL: http://svn.apache.org/viewvc?rev=1243634&view=rev
Log:
Microkernel based prototype of JCR implementation (WIP)
- correctly overlay persisted child nodes with transiently modified child nodes  

Modified:
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeState.java
    jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java?rev=1243634&r1=1243633&r2=1243634&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/ChangeTree.java
Mon Feb 13 18:15:21 2012
@@ -237,6 +237,15 @@ public class ChangeTree {
 
         /**
          * @param name
+         * @return  {@code true} iff this node has a modified child node of the given {@code
name}.
+         */
+        public boolean isNodeModified(String name) {
+            NodeDelta node = childNodes.get(name);
+            return node != null && node.isTransient();
+        }
+
+        /**
+         * @param name
          * @return {@code true} iff a property with the given name has been added,
          * removed or modified.
          */

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeState.java?rev=1243634&r1=1243633&r2=1243634&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeState.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/main/java/org/apache/jackrabbit/state/NodeState.java
Mon Feb 13 18:15:21 2012
@@ -41,7 +41,7 @@ import java.util.Map.Entry;
 
 public class NodeState {
     private final Context sessionContext;
-    private final NodeDelta nodeDelta;
+    private final NodeDelta nodeDelta;  // fixme: re-resolve on refresh/save
 
     private String revision;
     private JsonObject jsonObject;
@@ -96,24 +96,34 @@ public class NodeState {
     }
 
     public Iterator<NodeState> getChildNodeStates() {
-        Iterator<NodeState> persisted = Iterators.filterIterator(getPersistedChildNodeStates(),
-            new Predicate<NodeState>() {
+        Map<String, JsonValue> childEntries = getJsonObject().value();
+
+        Iterator<Entry<String, JsonValue>> childNodeEntries =
+            Iterators.filterIterator(childEntries.entrySet().iterator(),
+                new Predicate<Entry<String, JsonValue>>() {
+                    @Override
+                    public boolean evaluate(Entry<String, JsonValue> entry) {
+                        return isNode(entry.getValue()) && !nodeDelta.isNodeModified(entry.getKey());
+                    }
+                });
+
+        Iterator<NodeState> childNodeStates = Iterators.transformIterator(childNodeEntries,
+            new Transformer<Entry<String, JsonValue>, NodeState>() {
                 @Override
-                public boolean evaluate(NodeState nodeState) {
-                    return !nodeDelta.hasChild(nodeState.getName())
-                            || !nodeDelta.getNode(nodeState.getName()).isRemoved();
+                public NodeState transform(Entry<String, JsonValue> entry) {
+                    return getNodeState(sessionContext, nodeDelta.getNode(entry.getKey()));
                 }
         });
 
-        Iterator<NodeState> added = Iterators.transformIterator(nodeDelta.getNodes(),
+        Iterator<NodeState> modifiedNodeStates = Iterators.transformIterator(nodeDelta.getNodes(),
             new Transformer<NodeDelta, NodeState>() {
                 @Override
                 public NodeState transform(NodeDelta delta) {
-                    return getNodeState(sessionContext, nodeDelta);
+                    return getNodeState(sessionContext, delta);
                 }
         });
 
-        return Iterators.iteratorChain(added, persisted);
+        return Iterators.iteratorChain(childNodeStates, modifiedNodeStates);
     }
 
     public Iterator<NodeState> getChildNodeStates(Predicate<NodeState> condition)
{
@@ -199,30 +209,10 @@ public class NodeState {
         return nodeState;
     }
 
-    private static final Predicate<Entry<String, JsonValue>> IS_NODE = new Predicate<Entry<String,
JsonValue>>() {
-        @Override
-        public boolean evaluate(Entry<String, JsonValue> entry) {
-            return isNode(entry.getValue());
-        }
-    };
-
     private static boolean isNode(JsonValue value) {
         return value.isObject();
     }
 
-    private Iterator<NodeState> getPersistedChildNodeStates() {
-        Map<String, JsonValue> childEntries = getJsonObject().value();
-        Iterator<Entry<String, JsonValue>> nodeEntries =
-                Iterators.filterIterator(childEntries.entrySet().iterator(), IS_NODE);
-
-        return Iterators.transformIterator(nodeEntries, new Transformer<Entry<String,
JsonValue>, NodeState>() {
-            @Override
-            public NodeState transform(Entry<String, JsonValue> entry) {
-                return getNodeState(sessionContext, nodeDelta.getNode(entry.getKey()));
-            }
-        });
-    }
-
     private Iterator<Entry<String, JsonValue>> getPersistedProperties() {
         Map<String, JsonValue> childEntries = getJsonObject().value();
 

Modified: jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java?rev=1243634&r1=1243633&r2=1243634&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-microkernel/src/test/java/org/apache/jackrabbit/RepositoryTest.java
Mon Feb 13 18:15:21 2012
@@ -225,12 +225,16 @@ public class RepositoryTest {
     @Test
     public void getNodes() throws RepositoryException {
         Set<String> nodeNames = new HashSet<String>() {{
-            add("foo");
             add("bar");
+            add("added");
             add(TEST_NODE);
         }};
 
         Node root = getNode("/");
+        root.addNode("added");         // transiently added
+        root.getNode("foo").remove();  // transiently removed
+        root.getNode("bar").remove();  // transiently removed and...
+        root.addNode("bar");           // ... added again
         NodeIterator nodes = root.getNodes();
         while (nodes.hasNext()) {
             assertTrue(nodeNames.remove(nodes.nextNode().getName()));



Mime
View raw message