jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1397070 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: core/ plugins/commit/ spi/commit/
Date Thu, 11 Oct 2012 14:21:44 GMT
Author: mreutegg
Date: Thu Oct 11 14:21:44 2012
New Revision: 1397070

URL: http://svn.apache.org/viewvc?rev=1397070&view=rev
Log:
OAK-374: ConflictHandler must not depend on Oak API

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MergingNodeStateDiff.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/DefaultConflictHandler.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ConflictHandler.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MergingNodeStateDiff.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MergingNodeStateDiff.java?rev=1397070&r1=1397069&r2=1397070&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MergingNodeStateDiff.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/MergingNodeStateDiff.java
Thu Oct 11 14:21:44 2012
@@ -16,10 +16,10 @@
  */
 package org.apache.jackrabbit.oak.core;
 
-import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
 import org.slf4j.Logger;
@@ -40,15 +40,15 @@ class MergingNodeStateDiff implements No
      */
     private static final Logger log = LoggerFactory.getLogger(MergingNodeStateDiff.class);
 
-    private final TreeImpl target;
+    private final NodeBuilder target;
     private final ConflictHandler conflictHandler;
 
-    private MergingNodeStateDiff(TreeImpl target, ConflictHandler conflictHandler) {
+    private MergingNodeStateDiff(NodeBuilder target, ConflictHandler conflictHandler) {
         this.target = target;
         this.conflictHandler = conflictHandler;
     }
 
-    static void merge(NodeState fromState, NodeState toState, final TreeImpl target,
+    static void merge(NodeState fromState, NodeState toState, final NodeBuilder target,
             final ConflictHandler conflictHandler) {
         toState.compareAgainstBaseState(fromState, new MergingNodeStateDiff(
                 checkNotNull(target), conflictHandler));
@@ -133,12 +133,10 @@ class MergingNodeStateDiff implements No
     @Override
     public void childNodeAdded(String name, NodeState after) {
         ConflictHandler.Resolution resolution;
-        TreeImpl n = target.getChild(name);
-
-        if (n == null) {
+        if (!target.hasChildNode(name)) {
             resolution = OURS;
-        }
-        else {
+        } else {
+            NodeBuilder n = target.child(name);
             resolution = conflictHandler.addExistingNode(target, name, after, n.getNodeState());
         }
 
@@ -155,13 +153,10 @@ class MergingNodeStateDiff implements No
     @Override
     public void childNodeChanged(String name, NodeState before, NodeState after) {
         ConflictHandler.Resolution resolution;
-        TreeImpl n = target.getChild(name);
-
-        if (n == null) {
+        if (!target.hasChildNode(name)) {
             resolution = conflictHandler.changeDeletedNode(target, name, after);
-        }
-        else {
-            merge(before, after, n, conflictHandler);
+        } else {
+            merge(before, after, target.child(name), conflictHandler);
             resolution = MERGED;
         }
 
@@ -178,7 +173,7 @@ class MergingNodeStateDiff implements No
     @Override
     public void childNodeDeleted(String name, NodeState before) {
         ConflictHandler.Resolution resolution;
-        TreeImpl n = target.getChild(name);
+        NodeBuilder n = target.hasChildNode(name) ? target.child(name) : null;
 
         if (n == null) {
             resolution = conflictHandler.deleteDeletedNode(target, name);
@@ -193,7 +188,7 @@ class MergingNodeStateDiff implements No
         switch (resolution) {
             case OURS:
                 if (n != null) {
-                    n.remove();
+                    target.removeNode(name);
                 }
                 break;
             case THEIRS:
@@ -204,8 +199,8 @@ class MergingNodeStateDiff implements No
 
     //-------------------------------------------------------------<private >---
 
-    private static void addChild(Tree target, String name, NodeState state) {
-        Tree child = target.addChild(name);
+    private static void addChild(NodeBuilder target, String name, NodeState state) {
+        NodeBuilder child = target.child(name);
         for (PropertyState property : state.getProperties()) {
             child.setProperty(property);
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1397070&r1=1397069&r2=1397070&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Thu Oct 11 14:21:44 2012
@@ -181,7 +181,7 @@ public class RootImpl implements Root {
             NodeState base = getBaseState();
             NodeState head = rootTree.getNodeState();
             refresh();
-            MergingNodeStateDiff.merge(base, head, rootTree, conflictHandler);
+            MergingNodeStateDiff.merge(base, head, rootTree.getNodeBuilder(), conflictHandler);
         }
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java?rev=1397070&r1=1397069&r2=1397070&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java
Thu Oct 11 14:21:44 2012
@@ -18,13 +18,14 @@ package org.apache.jackrabbit.oak.plugin
 
 import java.util.List;
 
-import com.google.common.collect.Lists;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
 import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
+import com.google.common.collect.Lists;
+
 import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
 import static org.apache.jackrabbit.oak.api.Type.NAMES;
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.ADD_EXISTING;
@@ -55,69 +56,69 @@ import static org.apache.jackrabbit.oak.
 public class AnnotatingConflictHandler implements ConflictHandler {
 
     @Override
-    public Resolution addExistingProperty(Tree parent, PropertyState ours, PropertyState
theirs) {
-        Tree marker = addConflictMarker(parent);
-        getOrCreateNode(marker, ADD_EXISTING).setProperty(ours);
+    public Resolution addExistingProperty(NodeBuilder parent, PropertyState ours, PropertyState
theirs) {
+        NodeBuilder marker = addConflictMarker(parent);
+        marker.child(ADD_EXISTING).setProperty(ours);
         return Resolution.THEIRS;
     }
 
     @Override
-    public Resolution changeDeletedProperty(Tree parent, PropertyState ours) {
-        Tree marker = addConflictMarker(parent);
-        getOrCreateNode(marker, CHANGE_DELETED).setProperty(ours);
+    public Resolution changeDeletedProperty(NodeBuilder parent, PropertyState ours) {
+        NodeBuilder marker = addConflictMarker(parent);
+        marker.child(CHANGE_DELETED).setProperty(ours);
         return Resolution.THEIRS;
     }
 
     @Override
-    public Resolution changeChangedProperty(Tree parent, PropertyState ours, PropertyState
theirs) {
-        Tree marker = addConflictMarker(parent);
-        getOrCreateNode(marker, CHANGE_CHANGED).setProperty(ours);
+    public Resolution changeChangedProperty(NodeBuilder parent, PropertyState ours, PropertyState
theirs) {
+        NodeBuilder marker = addConflictMarker(parent);
+        marker.child(CHANGE_CHANGED).setProperty(ours);
         return Resolution.THEIRS;
     }
 
     @Override
-    public Resolution deleteChangedProperty(Tree parent, PropertyState theirs) {
-        Tree marker = addConflictMarker(parent);
-        getOrCreateNode(marker, DELETE_CHANGED).setProperty(theirs);
+    public Resolution deleteChangedProperty(NodeBuilder parent, PropertyState theirs) {
+        NodeBuilder marker = addConflictMarker(parent);
+        marker.child(DELETE_CHANGED).setProperty(theirs);
         return Resolution.THEIRS;
     }
 
     @Override
-    public Resolution deleteDeletedProperty(Tree parent, PropertyState ours) {
-        Tree marker = addConflictMarker(parent);
-        getOrCreateNode(marker, DELETE_DELETED).setProperty(ours);
+    public Resolution deleteDeletedProperty(NodeBuilder parent, PropertyState ours) {
+        NodeBuilder marker = addConflictMarker(parent);
+        marker.child(DELETE_DELETED).setProperty(ours);
         return Resolution.THEIRS;
     }
 
     @Override
-    public Resolution addExistingNode(Tree parent, String name, NodeState ours, NodeState
theirs) {
-        Tree marker = addConflictMarker(parent);
-        addChild(getOrCreateNode(marker, ADD_EXISTING), name, ours);
+    public Resolution addExistingNode(NodeBuilder parent, String name, NodeState ours, NodeState
theirs) {
+        NodeBuilder marker = addConflictMarker(parent);
+        addChild(marker.child(ADD_EXISTING), name, ours);
         return Resolution.THEIRS;
     }
 
     @Override
-    public Resolution changeDeletedNode(Tree parent, String name, NodeState ours) {
-        Tree marker = addConflictMarker(parent);
-        addChild(getOrCreateNode(marker, CHANGE_DELETED), name, ours);
+    public Resolution changeDeletedNode(NodeBuilder parent, String name, NodeState ours)
{
+        NodeBuilder marker = addConflictMarker(parent);
+        addChild(marker.child(CHANGE_DELETED), name, ours);
         return Resolution.THEIRS;
     }
 
     @Override
-    public Resolution deleteChangedNode(Tree parent, String name, NodeState theirs) {
-        Tree marker = addConflictMarker(parent);
-        markChild(getOrCreateNode(marker, DELETE_CHANGED), name);
+    public Resolution deleteChangedNode(NodeBuilder parent, String name, NodeState theirs)
{
+        NodeBuilder marker = addConflictMarker(parent);
+        markChild(marker.child(DELETE_CHANGED), name);
         return Resolution.THEIRS;
     }
 
     @Override
-    public Resolution deleteDeletedNode(Tree parent, String name) {
-        Tree marker = addConflictMarker(parent);
-        markChild(getOrCreateNode(marker, DELETE_DELETED), name);
+    public Resolution deleteDeletedNode(NodeBuilder parent, String name) {
+        NodeBuilder marker = addConflictMarker(parent);
+        markChild(marker.child(DELETE_DELETED), name);
         return Resolution.THEIRS;
     }
 
-    private static Tree addConflictMarker(Tree parent) {
+    private static NodeBuilder addConflictMarker(NodeBuilder parent) {
         PropertyState jcrMixin = parent.getProperty(JCR_MIXINTYPES);
         List<String> mixins;
         if (jcrMixin == null) {
@@ -131,19 +132,11 @@ public class AnnotatingConflictHandler i
             parent.setProperty(JCR_MIXINTYPES, mixins, NAMES);
         }
 
-        return getOrCreateNode(parent, REP_OURS);
-    }
-
-    private static Tree getOrCreateNode(Tree parent, String name) {
-        Tree child = parent.getChild(name);
-        if (child == null) {
-            child = parent.addChild(name);
-        }
-        return child;
+        return parent.child(REP_OURS);
     }
 
-    private static void addChild(Tree parent, String name, NodeState state) {
-        Tree child = parent.addChild(name);
+    private static void addChild(NodeBuilder parent, String name, NodeState state) {
+        NodeBuilder child = parent.child(name);
         for (PropertyState property : state.getProperties()) {
             child.setProperty(property);
         }
@@ -152,8 +145,8 @@ public class AnnotatingConflictHandler i
         }
     }
 
-    private static void markChild(Tree parent, String name) {
-        parent.addChild(name);
+    private static void markChild(NodeBuilder parent, String name) {
+        parent.child(name);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/DefaultConflictHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/DefaultConflictHandler.java?rev=1397070&r1=1397069&r2=1397070&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/DefaultConflictHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/DefaultConflictHandler.java
Thu Oct 11 14:21:44 2012
@@ -20,7 +20,7 @@ package org.apache.jackrabbit.oak.plugin
 
 import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
@@ -53,47 +53,47 @@ public class DefaultConflictHandler impl
     }
 
     @Override
-    public Resolution addExistingProperty(Tree parent, PropertyState ours, PropertyState
theirs) {
+    public Resolution addExistingProperty(NodeBuilder parent, PropertyState ours, PropertyState
theirs) {
         return resolution;
     }
 
     @Override
-    public Resolution changeDeletedProperty(Tree parent, PropertyState ours) {
+    public Resolution changeDeletedProperty(NodeBuilder parent, PropertyState ours) {
         return resolution;
     }
 
     @Override
-    public Resolution changeChangedProperty(Tree parent, PropertyState ours, PropertyState
theirs) {
+    public Resolution changeChangedProperty(NodeBuilder parent, PropertyState ours, PropertyState
theirs) {
         return resolution;
     }
 
     @Override
-    public Resolution deleteChangedProperty(Tree parent, PropertyState theirs) {
+    public Resolution deleteChangedProperty(NodeBuilder parent, PropertyState theirs) {
         return resolution;
     }
 
     @Override
-    public Resolution deleteDeletedProperty(Tree parent, PropertyState ours) {
+    public Resolution deleteDeletedProperty(NodeBuilder parent, PropertyState ours) {
         return resolution;
     }
 
     @Override
-    public Resolution addExistingNode(Tree parent, String name, NodeState ours, NodeState
theirs) {
+    public Resolution addExistingNode(NodeBuilder parent, String name, NodeState ours, NodeState
theirs) {
         return resolution;
     }
 
     @Override
-    public Resolution changeDeletedNode(Tree parent, String name, NodeState ours) {
+    public Resolution changeDeletedNode(NodeBuilder parent, String name, NodeState ours)
{
         return resolution;
     }
 
     @Override
-    public Resolution deleteChangedNode(Tree parent, String name, NodeState theirs) {
+    public Resolution deleteChangedNode(NodeBuilder parent, String name, NodeState theirs)
{
         return resolution;
     }
 
     @Override
-    public Resolution deleteDeletedNode(Tree parent, String name) {
+    public Resolution deleteDeletedNode(NodeBuilder parent, String name) {
         return resolution;
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ConflictHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ConflictHandler.java?rev=1397070&r1=1397069&r2=1397070&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ConflictHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ConflictHandler.java
Thu Oct 11 14:21:44 2012
@@ -19,7 +19,7 @@
 package org.apache.jackrabbit.oak.spi.commit;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
 /**
@@ -66,7 +66,7 @@ public interface ConflictHandler {
      * @param theirs  their version of the property
      * @return  {@link Resolution} of the conflict
      */
-    Resolution addExistingProperty(Tree parent, PropertyState ours, PropertyState theirs);
+    Resolution addExistingProperty(NodeBuilder parent, PropertyState ours, PropertyState
theirs);
 
     /**
      * The property {@code ours} has been changed in {@code parent} while it was
@@ -76,7 +76,7 @@ public interface ConflictHandler {
      * @param ours  our version of the property
      * @return  {@link Resolution} of the conflict
      */
-    Resolution changeDeletedProperty(Tree parent, PropertyState ours);
+    Resolution changeDeletedProperty(NodeBuilder parent, PropertyState ours);
 
     /**
      * The property {@code ours} has been changed in {@code parent} while it was
@@ -87,7 +87,7 @@ public interface ConflictHandler {
      * @param theirs  their version of the property
      * @return  {@link Resolution} of the conflict
      */
-    Resolution changeChangedProperty(Tree parent, PropertyState ours, PropertyState theirs);
+    Resolution changeChangedProperty(NodeBuilder parent, PropertyState ours, PropertyState
theirs);
 
     /**
      * The property {@code ours} has been removed in {@code parent} while it was
@@ -97,7 +97,7 @@ public interface ConflictHandler {
      * @param ours  our version of the property
      * @return  {@link Resolution} of the conflict
      */
-    Resolution deleteDeletedProperty(Tree parent, PropertyState ours);
+    Resolution deleteDeletedProperty(NodeBuilder parent, PropertyState ours);
 
     /**
      * The property {@code theirs} changed in the persistence store while it has been
@@ -107,7 +107,7 @@ public interface ConflictHandler {
      * @param theirs  their version of the property
      * @return  {@link Resolution} of the conflict
      */
-    Resolution deleteChangedProperty(Tree parent, PropertyState theirs);
+    Resolution deleteChangedProperty(NodeBuilder parent, PropertyState theirs);
 
     /**
      * The node {@code ours} has been added to {@code parent} which conflicts
@@ -119,7 +119,7 @@ public interface ConflictHandler {
      * @param theirs  their version of the node
      * @return  {@link Resolution} of the conflict
      */
-    Resolution addExistingNode(Tree parent, String name, NodeState ours, NodeState theirs);
+    Resolution addExistingNode(NodeBuilder parent, String name, NodeState ours, NodeState
theirs);
 
     /**
      * The node {@code ours} has been changed in {@code parent} while it was
@@ -130,7 +130,7 @@ public interface ConflictHandler {
      * @param ours  our version of the node
      * @return  {@link Resolution} of the conflict
      */
-    Resolution changeDeletedNode(Tree parent, String name, NodeState ours);
+    Resolution changeDeletedNode(NodeBuilder parent, String name, NodeState ours);
 
     /**
      * The node {@code theirs} changed in the persistence store while it has been
@@ -138,11 +138,10 @@ public interface ConflictHandler {
      *
      * @param parent  root of the conflict
      * @param name  name of the node
-     * @param theirs
      * @param theirs  their version of the node
      * @return  {@link Resolution} of the conflict
      */
-    Resolution deleteChangedNode(Tree parent, String name, NodeState theirs);
+    Resolution deleteChangedNode(NodeBuilder parent, String name, NodeState theirs);
 
     /**
      * The node {@code name} has been removed in {@code parent} while it was
@@ -152,5 +151,5 @@ public interface ConflictHandler {
      * @param name  name of the node
      * @return  {@link Resolution} of the conflict
      */
-    Resolution deleteDeletedNode(Tree parent, String name);
+    Resolution deleteDeletedNode(NodeBuilder parent, String name);
 }



Mime
View raw message