jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1341534 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: kernel/KernelNodeStore.java plugins/memory/MemoryNodeStateBuilder.java plugins/memory/MemoryNodeStore.java plugins/memory/ModifiedNodeState.java
Date Tue, 22 May 2012 15:34:54 GMT
Author: jukka
Date: Tue May 22 15:34:53 2012
New Revision: 1341534

URL: http://svn.apache.org/viewvc?rev=1341534&view=rev
Log:
OAK-109: Efficient diffing against the base node state

Add ModifiedNodeState.diffAgainstBase() and an abstract MemoryNodeStore class that leverages
this feature.

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    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/ModifiedNodeState.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=1341534&r1=1341533&r2=1341534&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
Tue May 22 15:34:53 2012
@@ -18,18 +18,16 @@ package org.apache.jackrabbit.oak.kernel
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
-import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStateBuilder;
+import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.EmptyCommitHook;
-import org.apache.jackrabbit.oak.spi.state.AbstractNodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
-import org.apache.jackrabbit.oak.spi.state.NodeStateBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStoreBranch;
 
 /**
  * {@code NodeStore} implementations against {@link MicroKernel}.
  */
-public class KernelNodeStore extends AbstractNodeStore {
+public class KernelNodeStore extends MemoryNodeStore {
 
     /**
      * The {@link MicroKernel} instance used to store the content tree.
@@ -79,11 +77,6 @@ public class KernelNodeStore extends Abs
     }
 
     @Override
-    public NodeStateBuilder getBuilder(NodeState base) {
-        return new MemoryNodeStateBuilder(base);
-    }
-
-    @Override
     public CoreValueFactory getValueFactory() {
         return valueFactory;
     }

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=1341534&r1=1341533&r2=1341534&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
Tue May 22 15:34:53 2012
@@ -29,7 +29,7 @@ import java.util.Map;
 /**
  * Basic in-memory node state builder.
  */
-public class MemoryNodeStateBuilder implements NodeStateBuilder {
+class MemoryNodeStateBuilder implements NodeStateBuilder {
 
     private final NodeState base;
 

Added: 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=1341534&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
Tue May 22 15:34:53 2012
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.memory;
+
+import org.apache.jackrabbit.oak.spi.state.AbstractNodeStore;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateBuilder;
+import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
+
+/**
+ * Abstract node store base class with in-memory node state builder
+ * functionality.
+ */
+public abstract class MemoryNodeStore extends AbstractNodeStore {
+
+    @Override
+    public NodeStateBuilder getBuilder(NodeState base) {
+        return new MemoryNodeStateBuilder(base);
+    }
+
+    @Override
+    public void compare(NodeState before, NodeState after, NodeStateDiff diff) {
+        if (after instanceof ModifiedNodeState) {
+            ModifiedNodeState modified = (ModifiedNodeState) after;
+            if (before.equals(modified.getBase())) {
+                modified.diffAgainstBase(diff);
+            } else {
+                super.compare(before, after, diff);
+            }
+        } else {
+            super.compare(before, after, diff);
+        }
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java?rev=1341534&r1=1341533&r2=1341534&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/ModifiedNodeState.java
Tue May 22 15:34:53 2012
@@ -22,6 +22,7 @@ import org.apache.commons.collections.Pr
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.apache.jackrabbit.oak.spi.state.ProxyNodeState;
 
 import java.util.Iterator;
@@ -46,6 +47,33 @@ public class ModifiedNodeState extends P
         return delegate;
     }
 
+    void diffAgainstBase(NodeStateDiff diff) {
+        for (Map.Entry<String, PropertyState> entry : properties.entrySet()) {
+            PropertyState before = super.getProperty(entry.getKey());
+            PropertyState after = entry.getValue();
+            if (before == null) {
+                diff.propertyAdded(after);
+            } else if (after == null) {
+                diff.propertyDeleted(before);
+            } else {
+                diff.propertyChanged(before, after);
+            }
+        }
+
+        for (Map.Entry<String, NodeState> entry : nodes.entrySet()) {
+            String name = entry.getKey();
+            NodeState before = super.getChildNode(name);
+            NodeState after = entry.getValue();
+            if (before == null) {
+                diff.childNodeAdded(name, after);
+            } else if (after == null) {
+                diff.childNodeDeleted(name, before);
+            } else {
+                diff.childNodeChanged(name, before, after);
+            }
+        }
+    }
+
     //---------------------------------------------------------< NodeState >--
 
     @Override



Mime
View raw message