jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1469264 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Date Thu, 18 Apr 2013 10:14:28 GMT
Author: jukka
Date: Thu Apr 18 10:14:28 2013
New Revision: 1469264

URL: http://svn.apache.org/r1469264
Log:
OAK-778: Recursive wrapping of ModifiedNodeState

Unwrap ModifiedNodeState instances passed to MemoryNodeBuilder.setNode()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1469264&r1=1469263&r2=1469264&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Thu Apr 18 10:14:28 2013
@@ -526,7 +526,38 @@ public class MemoryNodeBuilder implement
         private final Map<String, MutableNodeState> nodes = newHashMap();
 
         public MutableNodeState(NodeState base) {
-            if (base != null) {
+            if (base instanceof ModifiedNodeState) {
+                ModifiedNodeState modified = (ModifiedNodeState) base;
+                this.base = modified.getBaseState();
+                modified.compareAgainstBaseState(new NodeStateDiff() {
+                    @Override
+                    public void propertyAdded(PropertyState after) {
+                        properties.put(after.getName(), after);
+                    }
+                    @Override
+                    public void propertyChanged(
+                            PropertyState before, PropertyState after) {
+                        properties.put(after.getName(), after);
+                    }
+                    @Override
+                    public void propertyDeleted(PropertyState before) {
+                        properties.put(before.getName(), null);
+                    }
+                    @Override
+                    public void childNodeAdded(String name, NodeState after) {
+                        nodes.put(name, new MutableNodeState(after));
+                    }
+                    @Override
+                    public void childNodeChanged(
+                            String name, NodeState before, NodeState after) {
+                        nodes.put(name, new MutableNodeState(after));
+                    }
+                    @Override
+                    public void childNodeDeleted(String name, NodeState before) {
+                        nodes.put(name, null);
+                    }
+                });
+            } else if (base != null) {
                 this.base = base;
             } else {
                 this.base = EMPTY_NODE;
@@ -554,19 +585,77 @@ public class MemoryNodeBuilder implement
         }
 
         void reset(NodeState newBase) {
-            base = newBase;
-            properties.clear();
+            if (newBase instanceof ModifiedNodeState) {
+                ModifiedNodeState modified = (ModifiedNodeState) newBase;
+                base = modified.getBaseState();
+                properties.clear();
+
+                Iterator<Map.Entry<String, MutableNodeState>> iterator =
+                        nodes.entrySet().iterator();
+                while (iterator.hasNext()) {
+                    Map.Entry<String, MutableNodeState> entry = iterator.next();
+                    MutableNodeState cstate = entry.getValue();
+                    NodeState cbase = newBase.getChildNode(entry.getKey());
+                    if (!cbase.exists() || cstate == null) {
+                        iterator.remove();
+                    } else {
+                        cstate.reset(cbase);
+                    }
+                }
 
-            Iterator<Map.Entry<String, MutableNodeState>> iterator =
-                    nodes.entrySet().iterator();
-            while (iterator.hasNext()) {
-                Map.Entry<String, MutableNodeState> entry = iterator.next();
-                MutableNodeState cstate = entry.getValue();
-                NodeState cbase = newBase.getChildNode(entry.getKey());
-                if (!cbase.exists() || cstate == null) {
-                    iterator.remove();
-                } else {
-                    cstate.reset(cbase);
+                modified.compareAgainstBaseState(new NodeStateDiff() {
+                    @Override
+                    public void propertyAdded(PropertyState after) {
+                        properties.put(after.getName(), after);
+                    }
+                    @Override
+                    public void propertyChanged(
+                            PropertyState before, PropertyState after) {
+                        properties.put(after.getName(), after);
+                    }
+                    @Override
+                    public void propertyDeleted(PropertyState before) {
+                        properties.put(before.getName(), null);
+                    }
+                    @Override
+                    public void childNodeAdded(String name, NodeState after) {
+                        MutableNodeState cstate = nodes.get(name);
+                        if (cstate != null) {
+                            cstate.reset(after);
+                        } else {
+                            nodes.put(name, new MutableNodeState(after));
+                        }
+                    }
+                    @Override
+                    public void childNodeChanged(
+                            String name, NodeState before, NodeState after) {
+                        MutableNodeState cstate = nodes.get(name);
+                        if (cstate != null) {
+                            cstate.reset(after);
+                        } else {
+                            nodes.put(name, new MutableNodeState(after));
+                        }
+                    }
+                    @Override
+                    public void childNodeDeleted(String name, NodeState before) {
+                        nodes.put(name, null);
+                    }
+                });
+            } else {
+                base = newBase;
+                properties.clear();
+
+                Iterator<Map.Entry<String, MutableNodeState>> iterator =
+                        nodes.entrySet().iterator();
+                while (iterator.hasNext()) {
+                    Map.Entry<String, MutableNodeState> entry = iterator.next();
+                    MutableNodeState cstate = entry.getValue();
+                    NodeState cbase = newBase.getChildNode(entry.getKey());
+                    if (!cbase.exists() || cstate == null) {
+                        iterator.remove();
+                    } else {
+                        cstate.reset(cbase);
+                    }
                 }
             }
         }



Mime
View raw message