jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1103869 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store: CommitBuilder.java NodeDelta.java
Date Mon, 16 May 2011 20:22:46 GMT
Author: stefan
Date: Mon May 16 20:22:45 2011
New Revision: 1103869

URL: http://svn.apache.org/viewvc?rev=1103869&view=rev
Log:
MicroKernel prototype (WIP)

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java?rev=1103869&r1=1103868&r2=1103869&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/CommitBuilder.java
Mon May 16 20:22:45 2011
@@ -200,9 +200,21 @@ public class CommitBuilder {
         try {
             currentHead = rep.getHeadRevision();
             if (!currentHead.equals(baseRevId)) {
-                // todo recursively merge root of currentHead with new root (rootNodeId)
-
-
+                // recursively merge root of currentHead with new root (rootNodeId)
+/*
+                Node base = rep.getNode(baseRevId, "/");
+                Node node1 = rep.getNode(currentHead, "/");
+                Node node2 = rep.getStore().getNode(rootNodeId);
+                NodeDelta delta1 = new NodeDelta(base, node1);
+                NodeDelta delta2 = new NodeDelta(base, node2);
+                if (!delta1.conflictsWith(delta2)) {
+                    // todo merge
+                } else {
+                    // todo merge and/or traverse
+                }
+                // todo persist merged tree
+                rootNodeId = ...
+*/
                 baseRevId = currentHead;
             }
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java?rev=1103869&r1=1103868&r2=1103869&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/NodeDelta.java
Mon May 16 20:22:45 2011
@@ -60,6 +60,85 @@ public class NodeDelta implements NodeDi
         return changedChildNodes;
     }
 
+    public boolean conflictsWith(NodeDelta other) {
+        // assume that both delta's were built with the *same* base node revision
+
+        /*
+            (potentially) conflicting if:
+
+            added1 != added2
+            mod1 != mod2
+            mod1 != del2
+            del1 != mod2
+        */
+
+        // properties
+
+        Map<String, String> otherAdded = other.getAddedProperties();
+        for (Map.Entry added : addedProperties.entrySet()) {
+            String otherValue = otherAdded.get(added.getKey());
+            if (otherValue != null && !added.getValue().equals(otherValue)) {
+                // same property added with conflicting values
+                return true;
+            }
+        }
+
+        Map<String, String> otherChanged = other.getChangedProperties();
+        Map<String, String> otherRemoved = other.getRemovedProperties();
+        for (Map.Entry changed : changedProperties.entrySet()) {
+            String otherValue = otherChanged.get(changed.getKey());
+            if (otherValue != null && !changed.getValue().equals(otherValue)) {
+                // same property changed with conflicting values
+                return true;
+            }
+            if (otherRemoved.containsKey(changed.getKey())) {
+                // changed property has been removed
+                return true;
+            }
+        }
+
+        for (Map.Entry removed : removedProperties.entrySet()) {
+            if (otherChanged.containsKey(removed.getKey())) {
+                // removed property has been changed
+                return true;
+            }
+        }
+
+        // child node entries
+
+        otherAdded = other.getAddedChildNodes();
+        for (Map.Entry added : addedChildNodes.entrySet()) {
+            String otherValue = otherAdded.get(added.getKey());
+            if (otherValue != null && !added.getValue().equals(otherValue)) {
+                // same child node entry added with different target id's
+                return true;
+            }
+        }
+
+        otherChanged = other.getChangedChildNodes();
+        otherRemoved = other.getRemovedChildNodes();
+        for (Map.Entry changed : changedChildNodes.entrySet()) {
+            String otherValue = otherChanged.get(changed.getKey());
+            if (otherValue != null && !changed.getValue().equals(otherValue)) {
+                // same child node entry changed with different target id's
+                return true;
+            }
+            if (otherRemoved.containsKey(changed.getKey())) {
+                // changed child node entry has been removed
+                return true;
+            }
+        }
+
+        for (Map.Entry removed : removedChildNodes.entrySet()) {
+            if (otherChanged.containsKey(removed.getKey())) {
+                // removed child node entry has been changed
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     //------------------------------------------------------< NodeDiffHandler >
 
     public void propAdded(String nodePath, String propName, String value) {
@@ -82,7 +161,8 @@ public class NodeDelta implements NodeDi
         removedChildNodes.put(childName, id);
     }
 
-    public void childNodeChanged(String nodePath, String childName, String oldId, String
newId) {
+    public void childNodeChanged(String nodePath, String childName,
+                                 String oldId, String newId) {
         changedChildNodes.put(childName, newId);
     }
 }



Mime
View raw message