jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1329963 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Date Tue, 24 Apr 2012 19:39:01 GMT
Author: jukka
Date: Tue Apr 24 19:39:00 2012
New Revision: 1329963

URL: http://svn.apache.org/viewvc?rev=1329963&view=rev
Log:
OAK-68: Extension point for commit validation

Implement KernelNodeStore.compare()

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.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=1329963&r1=1329962&r2=1329963&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 Apr 24 19:39:00 2012
@@ -18,9 +18,12 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
-
+import org.apache.jackrabbit.oak.api.PropertyState;
 /**
  * {@link MicroKernel}-based {@link NodeStore} implementation.
  */
@@ -41,7 +44,72 @@ public class KernelNodeStore implements 
 
     @Override
     public void compare(NodeState before, NodeState after, NodeStateDiff diff) {
-        throw new UnsupportedOperationException(); // TODO
+        compareProperties(before, after, diff);
+        compareChildNodes(before, after, diff);
+    }
+
+    /**
+     * Compares the properties of the given two node states.
+     *
+     * @param before node state before changes
+     * @param after node state after changes
+     * @param diff handler of node state differences
+     */
+    protected void compareProperties(
+            NodeState before, NodeState after, NodeStateDiff diff) {
+        Set<String> beforeProperties = new HashSet<String>();
+
+        for (PropertyState beforeProperty : before.getProperties()) {
+            String name = beforeProperty.getName();
+            PropertyState afterProperty = after.getProperty(name);
+            if (afterProperty == null) {
+                diff.propertyDeleted(beforeProperty);
+            } else {
+                beforeProperties.add(name);
+                if (!beforeProperty.equals(afterProperty)) {
+                    diff.propertyChanged(beforeProperty, afterProperty);
+                }
+            }
+        }
+
+        for (PropertyState afterProperty : after.getProperties()) {
+            if (!beforeProperties.contains(afterProperty.getName())) {
+                diff.propertyAdded(afterProperty);
+            }
+        }
+    }
+
+    /**
+     * Compares the child nodes of the given two node states.
+     *
+     * @param before node state before changes
+     * @param after node state after changes
+     * @param diff handler of node state differences
+     */
+    protected void compareChildNodes(
+            NodeState before, NodeState after, NodeStateDiff diff) {
+        Set<String> beforeChildNodes = new HashSet<String>();
+
+        for (ChildNodeEntry beforeCNE : before.getChildNodeEntries(0, -1)) {
+            String name = beforeCNE.getName();
+            NodeState beforeChild = beforeCNE.getNodeState();
+            NodeState afterChild = after.getChildNode(name);
+            if (afterChild == null) {
+                diff.childNodeDeleted(name, beforeChild);
+            } else {
+                beforeChildNodes.add(name);
+                if (!beforeChild.equals(afterChild)) {
+                    diff.childNodeChanged(name, beforeChild, afterChild);
+                }
+            }
+        }
+
+        for (ChildNodeEntry afterChild : after.getChildNodeEntries(0, -1)) {
+            String name = afterChild.getName();
+            if (!beforeChildNodes.contains(name)) {
+                diff.childNodeAdded(name, afterChild.getNodeState());
+            }
+        }
     }
 
     // TODO clarify write access to store. Expose through interface



Mime
View raw message