Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/MergingNodeStateDiff.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/MergingNodeStateDiff.java (revision 1396938) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/MergingNodeStateDiff.java (working copy) @@ -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 @@ */ 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 @@ @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 @@ @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 @@ @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 @@ switch (resolution) { case OURS: if (n != null) { - n.remove(); + target.removeNode(name); } break; case THEIRS: @@ -204,8 +199,8 @@ //---------------------------------------------------------------- - 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); } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (revision 1396938) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (working copy) @@ -181,7 +181,7 @@ NodeState base = getBaseState(); NodeState head = rootTree.getNodeState(); refresh(); - MergingNodeStateDiff.merge(base, head, rootTree, conflictHandler); + MergingNodeStateDiff.merge(base, head, rootTree.getNodeBuilder(), conflictHandler); } } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java (revision 1396938) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/AnnotatingConflictHandler.java (working copy) @@ -18,13 +18,14 @@ 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 @@ 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 mixins; if (jcrMixin == null) { @@ -131,19 +132,11 @@ parent.setProperty(JCR_MIXINTYPES, mixins, NAMES); } - return getOrCreateNode(parent, REP_OURS); + return parent.child(REP_OURS); } - private static Tree getOrCreateNode(Tree parent, String name) { - Tree child = parent.getChild(name); - if (child == null) { - child = parent.addChild(name); - } - return child; - } - - 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 @@ } } - private static void markChild(Tree parent, String name) { - parent.addChild(name); + private static void markChild(NodeBuilder parent, String name) { + parent.child(name); } } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/DefaultConflictHandler.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/DefaultConflictHandler.java (revision 1396938) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/DefaultConflictHandler.java (working copy) @@ -20,7 +20,7 @@ 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 @@ } @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; } } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ConflictHandler.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ConflictHandler.java (revision 1396938) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/ConflictHandler.java (working copy) @@ -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 @@ * @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 @@ * @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 @@ * @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 @@ * @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 @@ * @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 @@ * @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 @@ * @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 @@ * * @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 @@ * @param name name of the node * @return {@link Resolution} of the conflict */ - Resolution deleteDeletedNode(Tree parent, String name); + Resolution deleteDeletedNode(NodeBuilder parent, String name); }