Author: mreutegg Date: Mon Feb 25 10:44:36 2013 New Revision: 1449653 URL: http://svn.apache.org/r1449653 Log: OAK-650: Move SegmentNodeStoreBranch.RebaseDiff to utility package
Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/RebaseDiff.java (with props) Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/MergingNodeStateDiff.java jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/MergingNodeStateDiff.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/MergingNodeStateDiff.java?rev=1449653&r1=1449652&r2=1449653&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/MergingNodeStateDiff.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/commit/MergingNodeStateDiff.java Mon Feb 25 10:44:36 2013 @@ -33,23 +33,23 @@ import org.apache.jackrabbit.oak.spi.sta import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.ADD_EXISTING_NODE; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.ADD_EXISTING_PROPERTY; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.CHANGE_CHANGED_PROPERTY; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.CHANGE_DELETED_NODE; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.CHANGE_DELETED_PROPERTY; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.CONFLICT; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.DELETE_CHANGED_NODE; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.DELETE_CHANGED_PROPERTY; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.DELETE_DELETED_NODE; +import static org.apache.jackrabbit.oak.spi.state.RebaseDiff.DELETE_DELETED_PROPERTY; + /** * MergingNodeStateDiff... TODO */ public final class MergingNodeStateDiff extends DefaultNodeStateDiff { private static final Logger LOG = LoggerFactory.getLogger(MergingNodeStateDiff.class); - public static final String CONFLICT = ":conflict"; - public static final String DELETE_CHANGED_PROPERTY = "deleteChangedProperty"; - public static final String DELETE_CHANGED_NODE = "deleteChangedNode"; - public static final String ADD_EXISTING_PROPERTY = "addExistingProperty"; - public static final String CHANGE_DELETED_PROPERTY = "changeDeletedProperty"; - public static final String CHANGE_CHANGED_PROPERTY = "changeChangedProperty"; - public static final String DELETE_DELETED_PROPERTY = "deleteDeletedProperty"; - public static final String ADD_EXISTING_NODE = "addExistingNode"; - public static final String CHANGE_DELETED_NODE = "changeDeletedNode"; - public static final String DELETE_DELETED_NODE = "deleteDeletedNode"; - private final NodeState parent; private final NodeBuilder target; private final ConflictHandler conflictHandler; Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java?rev=1449653&r1=1449652&r2=1449653&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentNodeStoreBranch.java Mon Feb 25 10:44:36 2013 @@ -16,30 +16,18 @@ */ package org.apache.jackrabbit.oak.plugins.segment; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.ADD_EXISTING_NODE; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.ADD_EXISTING_PROPERTY; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.CHANGE_CHANGED_PROPERTY; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.CHANGE_DELETED_NODE; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.CHANGE_DELETED_PROPERTY; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.CONFLICT; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.DELETE_CHANGED_NODE; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.DELETE_CHANGED_PROPERTY; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.DELETE_DELETED_NODE; -import static org.apache.jackrabbit.oak.plugins.commit.MergingNodeStateDiff.DELETE_DELETED_PROPERTY; - import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; import org.apache.jackrabbit.oak.api.CommitFailedException; -import org.apache.jackrabbit.oak.api.PropertyState; import org.apache.jackrabbit.oak.commons.PathUtils; import org.apache.jackrabbit.oak.plugins.memory.MemoryNodeBuilder; import org.apache.jackrabbit.oak.spi.commit.CommitHook; 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.apache.jackrabbit.oak.spi.state.NodeStoreBranch; +import org.apache.jackrabbit.oak.spi.state.RebaseDiff; class SegmentNodeStoreBranch implements NodeStoreBranch { @@ -80,86 +68,6 @@ class SegmentNodeStoreBranch implements writer.flush(); } - // FIXME: Proper rebase needed - private class RebaseDiff implements NodeStateDiff { - - private final NodeBuilder builder; - - RebaseDiff(NodeBuilder builder) { - this.builder = builder; - } - - @Override - public void propertyAdded(PropertyState after) { - PropertyState other = builder.getProperty(after.getName()); - if (other == null) { - builder.setProperty(after); - } else if (!other.equals(after)) { - conflictMarker(ADD_EXISTING_PROPERTY).setProperty(after); - } - } - - @Override - public void propertyChanged(PropertyState before, PropertyState after) { - PropertyState other = builder.getProperty(before.getName()); - if (other == null) { - conflictMarker(CHANGE_DELETED_PROPERTY).setProperty(after); - } else if (other.equals(before)) { - builder.setProperty(after); - } else if (!other.equals(after)) { - conflictMarker(CHANGE_CHANGED_PROPERTY).setProperty(after); - } - } - - @Override - public void propertyDeleted(PropertyState before) { - PropertyState other = builder.getProperty(before.getName()); - if (other == null) { - conflictMarker(DELETE_DELETED_PROPERTY).setProperty(before); - } else if (other.equals(before)) { - builder.removeProperty(before.getName()); - } else { - conflictMarker(DELETE_CHANGED_PROPERTY).setProperty(before); - } - } - - @Override - public void childNodeAdded(String name, NodeState after) { - if (builder.hasChildNode(name)) { - conflictMarker(ADD_EXISTING_NODE).setNode(name, after); - } else { - builder.setNode(name, after); - } - } - - @Override - public void childNodeChanged( - String name, NodeState before, NodeState after) { - if (builder.hasChildNode(name)) { - after.compareAgainstBaseState( - before, new RebaseDiff(builder.child(name))); - } else { - conflictMarker(CHANGE_DELETED_NODE).setNode(name, after); - } - } - - @Override - public void childNodeDeleted(String name, NodeState before) { - if (!builder.hasChildNode(name)) { - conflictMarker(DELETE_DELETED_NODE).setNode(name, before); - } else if (before.equals(builder.child(name).getNodeState())) { - builder.removeNode(name); - } else { - conflictMarker(DELETE_CHANGED_NODE).setNode(name, before); - } - } - - private NodeBuilder conflictMarker(String name) { - return builder.child(CONFLICT).child(name); - } - - } - @Override public synchronized void rebase() { RecordId newBaseId = store.getJournalHead(journal); Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/RebaseDiff.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/RebaseDiff.java?rev=1449653&view=auto ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/RebaseDiff.java (added) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/RebaseDiff.java Mon Feb 25 10:44:36 2013 @@ -0,0 +1,146 @@ +/* + * 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.spi.state; + +import org.apache.jackrabbit.mk.api.MicroKernel; +import org.apache.jackrabbit.oak.api.PropertyState; + +/** + * <code>RebaseDiff</code> implements a {@link NodeStateDiff}, which performs + * the conflict handling as defined in {@link MicroKernel#rebase(String, String)} + * on the Oak SPI state level. + * <p/> + * Intended use of this class is to re-base a branched version of the node state + * tree. Given below situation: + * <pre> + * + head (master) + * | + * | + branch + * |/ + * + base + * | + * </pre> + * The current state on the master branch is <code>head</code> and a branch + * was created at <code>base</code>. The current state on the branch is + * <code>branch</code>. Re-basing <code>branch</code> to the current + * <code>head</code> works as follows: + * <pre> + * NodeState head = ... + * NodeState branch = ... + * NodeState base = ... + * NodeBuilder builder = new MemoryNodeBuilder(head); + * branch.compareAgainstBaseState(base, new RebaseDiff(builder)); + * branch = builder.getNodeState(); + * </pre> + * The result is: + * <pre> + * + branch + * / + * + head (master) + * | + * </pre> + * <p/> + */ +public class RebaseDiff implements NodeStateDiff { + + public static final String CONFLICT = ":conflict"; + public static final String DELETE_CHANGED_PROPERTY = "deleteChangedProperty"; + public static final String DELETE_CHANGED_NODE = "deleteChangedNode"; + public static final String ADD_EXISTING_PROPERTY = "addExistingProperty"; + public static final String CHANGE_DELETED_PROPERTY = "changeDeletedProperty"; + public static final String CHANGE_CHANGED_PROPERTY = "changeChangedProperty"; + public static final String DELETE_DELETED_PROPERTY = "deleteDeletedProperty"; + public static final String ADD_EXISTING_NODE = "addExistingNode"; + public static final String CHANGE_DELETED_NODE = "changeDeletedNode"; + public static final String DELETE_DELETED_NODE = "deleteDeletedNode"; + + private final NodeBuilder builder; + + public RebaseDiff(NodeBuilder builder) { + this.builder = builder; + } + + @Override + public void propertyAdded(PropertyState after) { + PropertyState other = builder.getProperty(after.getName()); + if (other == null) { + builder.setProperty(after); + } else if (!other.equals(after)) { + conflictMarker(ADD_EXISTING_PROPERTY).setProperty(after); + } + } + + @Override + public void propertyChanged(PropertyState before, PropertyState after) { + PropertyState other = builder.getProperty(before.getName()); + if (other == null) { + conflictMarker(CHANGE_DELETED_PROPERTY).setProperty(after); + } else if (other.equals(before)) { + builder.setProperty(after); + } else if (!other.equals(after)) { + conflictMarker(CHANGE_CHANGED_PROPERTY).setProperty(after); + } + } + + @Override + public void propertyDeleted(PropertyState before) { + PropertyState other = builder.getProperty(before.getName()); + if (other == null) { + conflictMarker(DELETE_DELETED_PROPERTY).setProperty(before); + } else if (other.equals(before)) { + builder.removeProperty(before.getName()); + } else { + conflictMarker(DELETE_CHANGED_PROPERTY).setProperty(before); + } + } + + @Override + public void childNodeAdded(String name, NodeState after) { + if (builder.hasChildNode(name)) { + conflictMarker(ADD_EXISTING_NODE).setNode(name, after); + } else { + builder.setNode(name, after); + } + } + + @Override + public void childNodeChanged( + String name, NodeState before, NodeState after) { + if (builder.hasChildNode(name)) { + after.compareAgainstBaseState( + before, new RebaseDiff(builder.child(name))); + } else { + conflictMarker(CHANGE_DELETED_NODE).setNode(name, after); + } + } + + @Override + public void childNodeDeleted(String name, NodeState before) { + if (!builder.hasChildNode(name)) { + conflictMarker(DELETE_DELETED_NODE).setNode(name, before); + } else if (before.equals(builder.child(name).getNodeState())) { + builder.removeNode(name); + } else { + conflictMarker(DELETE_CHANGED_NODE).setNode(name, before); + } + } + + private NodeBuilder conflictMarker(String name) { + return builder.child(CONFLICT).child(name); + } + +} Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/RebaseDiff.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/RebaseDiff.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL