jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1364252 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory: MemoryNodeStateBuilder.java MemoryNodeStore.java
Date Sun, 22 Jul 2012 10:43:56 GMT
Author: jukka
Date: Sun Jul 22 10:43:55 2012
New Revision: 1364252

URL: http://svn.apache.org/viewvc?rev=1364252&view=rev
Log:
OAK-167: Caching NodeStore implementation

Introduce a mechanism for MNSB subclasses to track the number of updates

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

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java?rev=1364252&r1=1364251&r2=1364252&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
Sun Jul 22 10:43:55 2012
@@ -45,15 +45,13 @@ public class MemoryNodeStateBuilder impl
     /**
      * Set of added, modified or removed ({@code null} value) property states.
      */
-    private Map<String, PropertyState> properties =
-            new HashMap<String, PropertyState>();
+    private Map<String, PropertyState> properties = Maps.newHashMap();
 
     /**
      * Set of builders for added, modified or removed ({@code null} value)
      * child nodes.
      */
-    private final Map<String, NodeStateBuilder> builders =
-            new HashMap<String, NodeStateBuilder>();
+    private final Map<String, NodeStateBuilder> builders = Maps.newHashMap();
 
     /**
      * Flag to indicate that the current {@link #properties} map is being
@@ -63,9 +61,39 @@ public class MemoryNodeStateBuilder impl
      */
     private boolean frozen = false;
 
+    /**
+     * Creates a new in-memory node state builder.
+     *
+     * @param base base state of the new builder, or {@code null}
+     */
     public MemoryNodeStateBuilder(NodeState base) {
-        assert base != null;
-        this.base = base;
+        if (base != null) {
+            this.base = base;
+        } else {
+            this.base = MemoryNodeState.EMPTY_NODE;
+        }
+    }
+
+    /**
+     * Factory method for creating new child state builders. Subclasses may
+     * override this method to control the behavior of child state builders.
+     *
+     * @param child base state of the new builder, or {@code null}
+     * @return new builder
+     */
+    protected MemoryNodeStateBuilder createChildBuilder(NodeState child) {
+        return new MemoryNodeStateBuilder(child);
+    }
+
+    /**
+     * Called whenever <em>this</em> node is modified, i.e. a property is
+     * added, changed or removed, or a child node is added or removed. Changes
+     * inside child nodes or the subtrees below are not reported. The default
+     * implementation does nothing, but subclasses may override this method
+     * to better track changes.
+     */
+    protected void updated() {
+        // do nothing
     }
 
     /**
@@ -160,8 +188,9 @@ public class MemoryNodeStateBuilder impl
             if (nodeState.equals(base.getChildNode(name))) {
                 builders.remove(name);
             } else {
-                builders.put(name, new MemoryNodeStateBuilder(nodeState));
+                builders.put(name, createChildBuilder(nodeState));
             }
+            updated();
         }
     }
 
@@ -172,6 +201,7 @@ public class MemoryNodeStateBuilder impl
         } else {
             builders.remove(name);
         }
+        updated();
     }
 
     @Override
@@ -219,6 +249,7 @@ public class MemoryNodeStateBuilder impl
     public void setProperty(String name, CoreValue value) {
         unfreeze();
         properties.put(name, new SinglePropertyState(name, value));
+        updated();
     }
 
     @Override
@@ -229,6 +260,7 @@ public class MemoryNodeStateBuilder impl
         } else {
             properties.put(name, new MultiPropertyState(name, values));
         }
+        updated();
     }
 
     @Override
@@ -239,6 +271,7 @@ public class MemoryNodeStateBuilder impl
         } else {
             properties.remove(name);
         }
+        updated();
     }
 
     @Override
@@ -246,10 +279,7 @@ public class MemoryNodeStateBuilder impl
         NodeStateBuilder builder = builders.get(name);
         if (builder == null) {
             NodeState baseState = base.getChildNode(name);
-            if (baseState == null) {
-                baseState = MemoryNodeState.EMPTY_NODE;
-            }
-            builder = new MemoryNodeStateBuilder(baseState);
+            builder = createChildBuilder(baseState);
             builders.put(name, builder);
         }
         return builder;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java?rev=1364252&r1=1364251&r2=1364252&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
Sun Jul 22 10:43:55 2012
@@ -41,9 +41,6 @@ public class MemoryNodeStore implements 
 
     @Override
     public NodeStateBuilder getBuilder(NodeState base) {
-        if (base == null) {
-            base = MemoryNodeState.EMPTY_NODE;
-        }
         return new MemoryNodeStateBuilder(base);
     }
 



Mime
View raw message