Package org.apache.jackrabbit.mk.model.tree

Examples of org.apache.jackrabbit.mk.model.tree.NodeDelta


            throws Exception {
        assert from != null;
        assert to != null;
        assert base != null;

        NodeDelta theirDelta = new NodeDelta(store, store.getNodeState(from), store.getNodeState(base));
        NodeDelta ourDelta = new NodeDelta(store, store.getNodeState(from), store.getNodeState(to));

        // apply the changes
        StagedNode stagedNode = getStagedNode(path, true);

        for (Entry<String, String> added : ourDelta.getAddedProperties().entrySet()) {
            String name = added.getKey();
            String ourValue = added.getValue();
            String theirValue = theirDelta.getAddedProperties().get(name);

            if (theirValue != null && !theirValue.equals(ourValue)) {
                markConflict(stagedNode, "addExistingProperty", name, ourValue);
            }
            else {
                stagedNode.getProperties().put(name, ourValue);
            }
        }

        for (Entry<String, String> removed : ourDelta.getRemovedProperties().entrySet()) {
            String name = removed.getKey();
            String ourValue = removed.getValue();

            if (theirDelta.getRemovedProperties().containsKey(name)) {
                markConflict(stagedNode, "deleteDeletedProperty", name, ourValue);
            }
            else if (theirDelta.getChangedProperties().containsKey(name)) {
                markConflict(stagedNode, "deleteChangedProperty", name, ourValue);
            }
            else {
                stagedNode.getProperties().remove(name);
            }
        }

        for (Entry<String, String> changed : ourDelta.getChangedProperties().entrySet()) {
            String name = changed.getKey();
            String ourValue = changed.getValue();
            String theirValue = theirDelta.getChangedProperties().get(name);

            if (theirDelta.getRemovedProperties().containsKey(name)) {
                markConflict(stagedNode, "changeDeletedProperty", name, ourValue);
            }
            else if (theirValue != null && !theirValue.equals(ourValue)) {
                markConflict(stagedNode, "changeChangedProperty", name, ourValue);
            }
            else {
                stagedNode.getProperties().put(name, ourValue);
            }
        }

        for (Entry<String, Id> added : ourDelta.getAddedChildNodes().entrySet()) {
            String name = added.getKey();
            Id ourId = added.getValue();
            Id theirId = theirDelta.getAddedChildNodes().get(name);

            if (theirId != null && !theirId.equals(ourId)) {
                markConflict(stagedNode, "addExistingNode", name, ourId);
            }
            else {
                stagedNode.add(new ChildNodeEntry(name, ourId));
            }
        }

        for (Entry<String, Id> removed : ourDelta.getRemovedChildNodes().entrySet()) {
            String name = removed.getKey();
            Id ourId = removed.getValue();

            if (theirDelta.getRemovedChildNodes().containsKey(name)) {
                markConflict(stagedNode, "deleteDeletedNode", name, ourId);
            }
            else if (theirDelta.getChangedChildNodes().containsKey(name)) {
                markConflict(stagedNode, "deleteChangedNode", name, ourId);
            }
            else {
                stagedNode.remove(name);
            }
        }

        for (Entry<String, Id> changed : ourDelta.getChangedChildNodes().entrySet()) {
            String name = changed.getKey();
            Id ourId = changed.getValue();

            StoredNode changedBase = getChildNode(base, name);
            if (changedBase == null) {
View Full Code Here


    /**
     * Performs a three-way merge of the trees rooted at {@code ourRoot},
     * {@code theirRoot}, using the tree at {@code baseRoot} as reference.
     */
    private void mergeNode(StoredNode baseNode, StoredNode ourNode, StoredNode theirNode, String path) throws Exception {
        NodeDelta theirChanges = new NodeDelta(
                store, store.getNodeState(baseNode), store.getNodeState(theirNode));
        NodeDelta ourChanges = new NodeDelta(
                store, store.getNodeState(baseNode), store.getNodeState(ourNode));

        StagedNode stagedNode = getStagedNode(path, true);

        // apply our changes
        stagedNode.getProperties().putAll(ourChanges.getAddedProperties());
        stagedNode.getProperties().putAll(ourChanges.getChangedProperties());
        for (String name : ourChanges.getRemovedProperties().keySet()) {
            stagedNode.getProperties().remove(name);
        }

        for (Map.Entry<String, Id> entry : ourChanges.getAddedChildNodes().entrySet()) {
            stagedNode.add(new ChildNodeEntry(entry.getKey(), entry.getValue()));
        }
        for (Map.Entry<String, Id> entry : ourChanges.getChangedChildNodes().entrySet()) {
            if (!theirChanges.getChangedChildNodes().containsKey(entry.getKey())) {
                stagedNode.add(new ChildNodeEntry(entry.getKey(), entry.getValue()));
            }
        }
        for (String name : ourChanges.getRemovedChildNodes().keySet()) {
            stagedNode.remove(name);
        }

        List<NodeDelta.Conflict> conflicts = theirChanges.listConflicts(ourChanges);
        // resolve/report merge conflicts
        for (NodeDelta.Conflict conflict : conflicts) {
            String conflictName = conflict.getName();
            String conflictPath = PathUtils.concat(path, conflictName);
            switch (conflict.getType()) {
                case PROPERTY_VALUE_CONFLICT:
                    throw new Exception(
                            "concurrent modification of property " + conflictPath
                                    + " with conflicting values: \""
                                    + ourNode.getProperties().get(conflictName)
                                    + "\", \""
                                    + theirNode.getProperties().get(conflictName));

                case NODE_CONTENT_CONFLICT: {
                    if (ourChanges.getChangedChildNodes().containsKey(conflictName)) {
                        // modified subtrees
                        StoredNode baseChild = store.getNode(baseNode.getChildNodeEntry(conflictName).getId());
                        StoredNode ourChild = store.getNode(ourNode.getChildNodeEntry(conflictName).getId());
                        StoredNode theirChild = store.getNode(theirNode.getChildNodeEntry(conflictName).getId());
                        // merge the dirty subtrees recursively
View Full Code Here

    /**
     * Performs a three-way merge of the trees rooted at {@code ourRoot},
     * {@code theirRoot}, using the tree at {@code baseRoot} as reference.
     */
    private void mergeNode(StoredNode baseNode, StoredNode ourNode, StoredNode theirNode, String path) throws Exception {
        NodeDelta theirChanges = new NodeDelta(
                store, store.getNodeState(baseNode), store.getNodeState(theirNode));
        NodeDelta ourChanges = new NodeDelta(
                store, store.getNodeState(baseNode), store.getNodeState(ourNode));

        StagedNode stagedNode = getStagedNode(path, true);

        // merge non-conflicting changes
        stagedNode.getProperties().putAll(ourChanges.getAddedProperties());
        stagedNode.getProperties().putAll(ourChanges.getChangedProperties());
        for (String name : ourChanges.getRemovedProperties().keySet()) {
            stagedNode.getProperties().remove(name);
        }

        for (Map.Entry<String, Id> entry : ourChanges.getAddedChildNodes().entrySet()) {
            stagedNode.add(new ChildNodeEntry(entry.getKey(), entry.getValue()));
        }
        for (Map.Entry<String, Id> entry : ourChanges.getChangedChildNodes().entrySet()) {
            stagedNode.add(new ChildNodeEntry(entry.getKey(), entry.getValue()));
        }
        for (String name : ourChanges.getRemovedChildNodes().keySet()) {
            stagedNode.remove(name);
        }

        List<NodeDelta.Conflict> conflicts = theirChanges.listConflicts(ourChanges);
        // resolve/report merge conflicts
        for (NodeDelta.Conflict conflict : conflicts) {
            String conflictName = conflict.getName();
            String conflictPath = PathUtils.concat(path, conflictName);
            switch (conflict.getType()) {
                case PROPERTY_VALUE_CONFLICT:
                    throw new Exception(
                            "concurrent modification of property " + conflictPath
                                    + " with conflicting values: \""
                                    + ourNode.getProperties().get(conflictName)
                                    + "\", \""
                                    + theirNode.getProperties().get(conflictName));

                case NODE_CONTENT_CONFLICT: {
                    if (ourChanges.getChangedChildNodes().containsKey(conflictName)) {
                        // modified subtrees
                        StoredNode baseChild = store.getNode(baseNode.getChildNodeEntry(conflictName).getId());
                        StoredNode ourChild = store.getNode(ourNode.getChildNodeEntry(conflictName).getId());
                        StoredNode theirChild = store.getNode(theirNode.getChildNodeEntry(conflictName).getId());
                        // merge the dirty subtrees recursively
View Full Code Here

    /**
     * Performs a three-way merge of the trees rooted at {@code ourRoot},
     * {@code theirRoot}, using the tree at {@code baseRoot} as reference.
     */
    private void mergeNode(StoredNode baseNode, StoredNode ourNode, StoredNode theirNode, String path) throws Exception {
        NodeDelta theirChanges = new NodeDelta(
                store, store.getNodeState(baseNode), store.getNodeState(theirNode));
        NodeDelta ourChanges = new NodeDelta(
                store, store.getNodeState(baseNode), store.getNodeState(ourNode));

        StagedNode stagedNode = getStagedNode(path, true);

        // apply our changes
        stagedNode.getProperties().putAll(ourChanges.getAddedProperties());
        stagedNode.getProperties().putAll(ourChanges.getChangedProperties());
        for (String name : ourChanges.getRemovedProperties().keySet()) {
            stagedNode.getProperties().remove(name);
        }

        for (Map.Entry<String, Id> entry : ourChanges.getAddedChildNodes().entrySet()) {
            stagedNode.add(new ChildNodeEntry(entry.getKey(), entry.getValue()));
        }
        for (Map.Entry<String, Id> entry : ourChanges.getChangedChildNodes().entrySet()) {
            if (!theirChanges.getChangedChildNodes().containsKey(entry.getKey())) {
                stagedNode.add(new ChildNodeEntry(entry.getKey(), entry.getValue()));
            }
        }
        for (String name : ourChanges.getRemovedChildNodes().keySet()) {
            stagedNode.remove(name);
        }

        List<NodeDelta.Conflict> conflicts = theirChanges.listConflicts(ourChanges);
        // resolve/report merge conflicts
        for (NodeDelta.Conflict conflict : conflicts) {
            String conflictName = conflict.getName();
            String conflictPath = PathUtils.concat(path, conflictName);
            switch (conflict.getType()) {
                case PROPERTY_VALUE_CONFLICT:
                    throw new Exception(
                            "concurrent modification of property " + conflictPath
                                    + " with conflicting values: \""
                                    + ourNode.getProperties().get(conflictName)
                                    + "\", \""
                                    + theirNode.getProperties().get(conflictName));

                case NODE_CONTENT_CONFLICT: {
                    if (ourChanges.getChangedChildNodes().containsKey(conflictName)) {
                        // modified subtrees
                        StoredNode baseChild = store.getNode(baseNode.getChildNodeEntry(conflictName).getId());
                        StoredNode ourChild = store.getNode(ourNode.getChildNodeEntry(conflictName).getId());
                        StoredNode theirChild = store.getNode(theirNode.getChildNodeEntry(conflictName).getId());
                        // merge the dirty subtrees recursively
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.mk.model.tree.NodeDelta

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.