Examples of NodeDelta


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

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

    /**
     * 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

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

    /**
     * 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

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

    /**
     * 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

Examples of org.apache.jackrabbit.oak.jcr.state.ChangeTree.NodeDelta

    }

    public TransientNodeState getNodeState(Path path) {
        TransientNodeState state = cache == null ? null : cache.get(path);
        if (state == null) {
            NodeDelta delta = transientSpace.getNodeDelta(path);
            if (delta == null) {
                return null;
            }
            state = new TransientNodeState(sessionContext, delta);
            if (cache != null) {
View Full Code Here

Examples of org.apache.jackrabbit.oak.jcr.state.ChangeTree.NodeDelta

    /**
     * @return {@code true} iff this node has been transiently added.
     */
    public boolean isNew() {
        NodeDelta delta = getNodeDelta();
        return delta.isTransient() && !delta.isRemoved();
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.jcr.state.ChangeTree.NodeDelta

     * @param name The name of the new node.
     * @return the added node
     * @throws javax.jcr.ItemExistsException if a node with that name exists already.
     */
    public TransientNodeState addNode(String name) throws ItemExistsException {
        NodeDelta child = getNodeDelta().addNode(name);
        return getNodeState(child);
    }
View Full Code Here

Examples of org.apache.jackrabbit.oak.jcr.state.ChangeTree.NodeDelta

                    protected Iterator<? extends ChildNodeEntry> getPage(long pos, int size) {
                        return getPersistentNodeState().getChildNodeEntries(pos, size).iterator();
                    }
                });

        final NodeDelta delta = getNodeDelta();

        Iterator<ChildNodeEntry> unmodifiedEntries = Iterators.filter(persistedEntries,
            new Predicate<ChildNodeEntry>() {
                @Override
                public boolean evaluate(ChildNodeEntry entry) {
                    return !delta.isNodeModified(entry.getName());
                }
            });

        Iterator<TransientNodeState> unmodifiedStates = Iterators.map(unmodifiedEntries,
            new Function1<ChildNodeEntry, TransientNodeState>() {
                @Override
                public TransientNodeState apply(ChildNodeEntry entry) {
                    return getNodeState(delta.getNode(entry.getName()));
                }
            });

        Iterator<TransientNodeState> modifiedStates = Iterators.map(toIterable(delta.getNodes()).iterator(),
            new Function1<NodeDelta, TransientNodeState>() {
                @Override
                public TransientNodeState apply(NodeDelta delta) {
                    return getNodeState(delta);
                }
View Full Code Here

Examples of org.apache.jackrabbit.oak.jcr.state.ChangeTree.NodeDelta

    /**
     * @return Iterator of all property states of this instance.
     */
    public Iterator<PropertyState> getProperties() {
        Iterable<? extends PropertyState> propertyStates = getPersistentNodeState().getProperties();
        final NodeDelta delta = getNodeDelta();

        Iterator<PropertyState> propertyEntries =
            Iterators.filter(propertyStates.iterator(),
                new Predicate<PropertyState>() {
                    @Override
                    public boolean evaluate(PropertyState state) {
                        return !state.getName().startsWith(":") && !delta.hasProperty(state.getName());
                    }
                });

        Iterator<PropertyState> modifiedProperties = delta.getPropertyStates();
        return Iterators.chain(propertyEntries, Iterators.toIterable(modifiedProperties).iterator());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.