Search in sources :

Example 26 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class VersionItemStateManager method setNodeReferences.

/**
 * Sets the
 * @param references
 * @return
 */
public boolean setNodeReferences(ChangeLog references) {
    try {
        ChangeLog log = new ChangeLog();
        for (NodeReferences source : references.modifiedRefs()) {
            // filter out version storage intern ones
            NodeReferences target = new NodeReferences(source.getTargetId());
            for (PropertyId id : source.getReferences()) {
                if (!hasNonVirtualItemState(id.getParentId())) {
                    target.addReference(id);
                }
            }
            log.modified(target);
        }
        if (log.hasUpdates()) {
            pMgr.store(log);
        }
        return true;
    } catch (ItemStateException e) {
        log.error("Error while setting references: " + e.toString());
        return false;
    }
}
Also used : NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) PropertyId(org.apache.jackrabbit.core.id.PropertyId) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 27 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class LocalItemStateManager method createNew.

/**
 * {@inheritDoc}
 */
public PropertyState createNew(Name propName, NodeId parentId) throws IllegalStateException {
    if (!editMode) {
        throw new IllegalStateException("Not in edit mode");
    }
    PropertyState state = new PropertyState(new PropertyId(parentId, propName), ItemState.STATUS_NEW, false);
    changeLog.added(state);
    state.setContainer(this);
    return state;
}
Also used : PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 28 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeStateMerger method conflicts.

/**
 * @param state The state of the node to be saved.
 * @param addedMixins The added mixins to be used for testing
 * @param ctx
 * @param compareToOverlayed
 * @return true if a conflict can be determined, false otherwise.
 */
private static boolean conflicts(NodeState state, Set<Name> addedMixins, MergeContext ctx, boolean compareToOverlayed) {
    try {
        // if the mixin defines residual item definitions -> return false.
        for (Name mixinName : addedMixins) {
            EffectiveNodeType ent = ctx.getEffectiveNodeType(mixinName);
            if (ent.getUnnamedItemDefs().length > 0) {
                // easily determine conflicts
                return false;
            }
            NodeState overlayed = (NodeState) state.getOverlayedState();
            for (ChildNodeEntry cne : state.getChildNodeEntries()) {
                if (ent.getNamedNodeDefs(cne.getName()).length > 0) {
                    if (ctx.isAdded(cne.getId()) || isAutoCreated(cne, ent)) {
                        if (!compareToOverlayed || overlayed.hasChildNodeEntry(cne.getName())) {
                            return true;
                        }
                    }
                // else: neither added nor autocreated in 'state' .
                }
            // else: child node not defined by the added mixin type
            }
            for (Name propName : state.getPropertyNames()) {
                if (ent.getNamedPropDefs(propName).length > 0) {
                    PropertyId pid = new PropertyId(state.getNodeId(), propName);
                    if (ctx.isAdded(pid) || isAutoCreated(propName, ent)) {
                        if (!compareToOverlayed || overlayed.hasPropertyName(propName)) {
                            return true;
                        }
                    }
                // else: neither added nor autocreated in 'state'
                }
            // else: property not defined by added mixin
            }
        }
    } catch (NoSuchNodeTypeException e) {
        // unable to determine collision
        return true;
    }
    // no conflict detected
    return false;
}
Also used : EffectiveNodeType(org.apache.jackrabbit.core.nodetype.EffectiveNodeType) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) NoSuchNodeTypeException(javax.jcr.nodetype.NoSuchNodeTypeException)

Example 29 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class NodeStateMerger method mergeMixinTypes.

/**
 * @param state
 * @param overlayedState
 * @return true if the mixin type names are the same in both node states or
 * if the mixin modifications do not conflict (and could be merged); false
 * otherwise.
 */
private static boolean mergeMixinTypes(NodeState state, NodeState overlayedState, MergeContext ctx) {
    Set<Name> mixins = new HashSet<Name>(state.getMixinTypeNames());
    Set<Name> overlayedMixins = new HashSet<Name>(overlayedState.getMixinTypeNames());
    if (mixins.equals(overlayedMixins)) {
        // by the mixins according to the general rule.
        return true;
    }
    PropertyId mixinPropId = new PropertyId(state.getNodeId(), NameConstants.JCR_MIXINTYPES);
    boolean mergeDone;
    if (ctx.isAdded(mixinPropId)) {
        // existing items on the overlayed state
        if (overlayedMixins.isEmpty() || mixins.containsAll(overlayedMixins)) {
            mixins.removeAll(overlayedMixins);
            mergeDone = !conflicts(state, mixins, ctx, true);
        } else {
            // different mixins added in overlayedState and state
            // -> don't merge
            mergeDone = false;
        }
    } else if (ctx.isDeleted(mixinPropId)) {
        // jcr:mixinTypes property was removed in 'state'.
        // we can't determine if there was any change to mixin types in the
        // overlayed state.
        // -> don't merge.
        mergeDone = false;
    } else if (ctx.isModified(mixinPropId)) {
        /* jcr:mixinTypes property was modified in 'state'.
               NOTE: if the mixins of the overlayed state was modified as well
               the property (jcr:mixinTypes) cannot not be persisted (stale).

               since there is not way to determine if the overlayed mixins have
               been modified just check for conflicts related to a net mixin
               addition.
             */
        if (mixins.containsAll(overlayedMixins)) {
            // net result of modifications is only addition.
            // -> so far the changes are save if there are no conflicts
            // caused by mixins modification in 'state'.
            // NOTE: the save may still fail if the mixin property has
            // been modified in the overlayed state as well.
            mixins.removeAll(overlayedMixins);
            mergeDone = !conflicts(state, mixins, ctx, true);
        } else {
            // net result is either a removal in 'state' or modifications
            // in both node states.
            // -> don't merge.
            mergeDone = false;
        }
    } else {
        // state but neither added nor modified in 'state'.
        if (overlayedMixins.containsAll(mixins)) {
            // the modification in the overlayed state only includes the
            // addition of mixin node types, but no removal.
            // -> need to check if any added items from state would
            // collide with the items defined by the new mixin on the
            // overlayed state.
            overlayedMixins.removeAll(mixins);
            if (!conflicts(state, overlayedMixins, ctx, false)) {
                // update the mixin names in 'state'. the child items defined
                // by the new mixins will be added later on during merge of
                // child nodes and properties.
                state.setMixinTypeNames(overlayedMixins);
                mergeDone = true;
            } else {
                mergeDone = false;
            }
        } else {
            // either remove-mixin(s) or both add and removal of mixin in
            // the overlayed state.
            // -> we cannot merge easily
            mergeDone = false;
        }
    }
    return mergeDone;
}
Also used : Name(org.apache.jackrabbit.spi.Name) HashSet(java.util.HashSet) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 30 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class SharedItemStateManager method createInstance.

/**
 * Create a new property state instance
 *
 * @param propName   property name
 * @param parentId parent Id
 * @return new property state instance
 */
private PropertyState createInstance(Name propName, NodeId parentId) {
    PropertyState state = persistMgr.createNew(new PropertyId(parentId, propName));
    state.setStatus(ItemState.STATUS_NEW);
    state.setContainer(this);
    return state;
}
Also used : PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Aggregations

PropertyId (org.apache.jackrabbit.core.id.PropertyId)59 Name (org.apache.jackrabbit.spi.Name)29 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 NodeState (org.apache.jackrabbit.core.state.NodeState)23 RepositoryException (javax.jcr.RepositoryException)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)22 NodeId (org.apache.jackrabbit.core.id.NodeId)16 InternalValue (org.apache.jackrabbit.core.value.InternalValue)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 HashSet (java.util.HashSet)10 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)7 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)5 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)5 ItemId (org.apache.jackrabbit.core.id.ItemId)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)4