Search in sources :

Example 36 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class WorkspaceImporter method end.

/**
     * {@inheritDoc}
     */
public void end() throws RepositoryException {
    if (aborted) {
        // the import has been aborted, get outta here...
        return;
    }
    boolean succeeded = false;
    try {
        // check sanity of workspace/session first
        wsp.sanityCheck();
        /**
             * adjust references that refer to uuids which have been mapped to
             * newly generated uuids on import
             */
        Iterator<Object> iter = refTracker.getProcessedReferences();
        while (iter.hasNext()) {
            PropertyState prop = (PropertyState) iter.next();
            // being paranoid...
            if (prop.getType() != PropertyType.REFERENCE && prop.getType() != PropertyType.WEAKREFERENCE) {
                continue;
            }
            boolean modified = false;
            InternalValue[] values = prop.getValues();
            InternalValue[] newVals = new InternalValue[values.length];
            for (int i = 0; i < values.length; i++) {
                NodeId adjusted = refTracker.getMappedId(values[i].getNodeId());
                if (adjusted != null) {
                    newVals[i] = InternalValue.create(adjusted, prop.getType() != PropertyType.REFERENCE);
                    modified = true;
                } else {
                    // reference doesn't need adjusting, just copy old value
                    newVals[i] = values[i];
                }
            }
            if (modified) {
                prop.setValues(newVals);
                itemOps.store(prop);
            }
        }
        refTracker.clear();
        // make sure import target is valid according to its definition
        itemOps.validate(importTarget);
        // finally store the state of the import target
        // (the parent of the imported subtree)
        itemOps.store(importTarget);
        succeeded = true;
    } finally {
        if (!succeeded) {
            // update operation failed, cancel all modifications
            aborted = true;
            itemOps.cancel();
        }
    }
    if (!aborted) {
        // finish update
        itemOps.update();
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 37 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class NodeStateEx method store.

/**
     * stores the given persistent state recursively
     *
     * @param state node state to store
     * @throws ItemStateException if an error occurs
     */
private void store(NodeState state, boolean recursively) throws ItemStateException {
    if (state.getStatus() != ItemState.STATUS_EXISTING) {
        // first store all transient properties
        for (Name propName : state.getPropertyNames()) {
            PropertyState pstate = (PropertyState) stateMgr.getItemState(new PropertyId(state.getNodeId(), propName));
            if (pstate.getStatus() != ItemState.STATUS_EXISTING) {
                stateMgr.store(pstate);
            }
        }
        if (recursively) {
            // now store all child node entries
            for (ChildNodeEntry entry : state.getChildNodeEntries()) {
                NodeState nstate = (NodeState) stateMgr.getItemState(entry.getId());
                store(nstate, true);
            }
        }
        // and store itself
        stateMgr.store(state);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) Name(org.apache.jackrabbit.spi.Name) PropertyState(org.apache.jackrabbit.core.state.PropertyState) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 38 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class NodeStateEx method reload.

/**
     * reloads the given persistent state recursively
     *
     * @param state node state
     * @throws ItemStateException if an error occurs
     */
private void reload(NodeState state) throws ItemStateException {
    if (state.getStatus() != ItemState.STATUS_EXISTING) {
        // first discard all all transient properties
        for (Name propName : state.getPropertyNames()) {
            PropertyState pstate = (PropertyState) stateMgr.getItemState(new PropertyId(state.getNodeId(), propName));
            if (pstate.getStatus() != ItemState.STATUS_EXISTING) {
                pstate.discard();
            }
        }
        // now reload all child node entries
        for (ChildNodeEntry entry : state.getChildNodeEntries()) {
            NodeState nstate = (NodeState) stateMgr.getItemState(entry.getId());
            reload(nstate);
        }
        // and reload itself
        state.discard();
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) Name(org.apache.jackrabbit.spi.Name) PropertyState(org.apache.jackrabbit.core.state.PropertyState) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 39 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class BatchedItemOperations method recursiveRemoveNodeState.

//------------------------------------------------------< private methods >
/**
     * Recursively removes the given node state including its properties and
     * child nodes.
     * <p>
     * The removal of child nodes is subject to the following checks:
     * access rights, locking & versioning status. Referential integrity
     * (references) is checked on commit.
     * <p>
     * Note that the child node entry refering to <code>targetState</code> is
     * <b><i>not</i></b> automatically removed from <code>targetState</code>'s
     * parent.
     *
     * @param targetState
     * @throws RepositoryException if an error occurs
     */
private void recursiveRemoveNodeState(NodeState targetState) throws RepositoryException {
    if (targetState.hasChildNodeEntries()) {
        // remove child nodes
        // use temp array to avoid ConcurrentModificationException
        ArrayList<ChildNodeEntry> tmp = new ArrayList<ChildNodeEntry>(targetState.getChildNodeEntries());
        // remove from tail to avoid problems with same-name siblings
        for (int i = tmp.size() - 1; i >= 0; i--) {
            ChildNodeEntry entry = tmp.get(i);
            NodeId nodeId = entry.getId();
            try {
                NodeState nodeState = (NodeState) stateMgr.getItemState(nodeId);
                // check if child node can be removed
                // (access rights, locking & versioning status as well
                //  as retention and hold);
                // referential integrity (references) is checked
                // on commit
                checkRemoveNode(nodeState, targetState.getNodeId(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_HOLD | CHECK_RETENTION);
                // remove child node
                recursiveRemoveNodeState(nodeState);
            } catch (ItemStateException ise) {
                String msg = "internal error: failed to retrieve state of " + nodeId;
                log.debug(msg);
                throw new RepositoryException(msg, ise);
            }
            // remove child node entry
            targetState.removeChildNodeEntry(entry.getName(), entry.getIndex());
        }
    }
    // remove properties
    // use temp set to avoid ConcurrentModificationException
    HashSet<Name> tmp = new HashSet<Name>(targetState.getPropertyNames());
    for (Name propName : tmp) {
        PropertyId propId = new PropertyId(targetState.getNodeId(), propName);
        try {
            PropertyState propState = (PropertyState) stateMgr.getItemState(propId);
            // remove property entry
            targetState.removePropertyName(propId.getName());
            // destroy property state
            stateMgr.destroy(propState);
        } catch (ItemStateException ise) {
            String msg = "internal error: failed to retrieve state of " + propId;
            log.debug(msg);
            throw new RepositoryException(msg, ise);
        }
    }
    // now actually do unlink target state
    targetState.setParentId(null);
    // destroy target state (pass overlayed state since target state
    // might have been modified during unlinking)
    stateMgr.destroy(targetState.getOverlayedState());
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NodeId(org.apache.jackrabbit.core.id.NodeId) HashSet(java.util.HashSet)

Example 40 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class HierarchyManagerImpl method buildPath.

/**
     * Adds the path element of an item id to the path currently being built.
     * Recursively invoked method that may be overridden by some subclass to
     * either return cached responses or add response to cache. On exit,
     * <code>builder</code> contains the path of <code>state</code>.
     *
     * @param builder  builder currently being used
     * @param state    item to find path of
     * @param detector path cycle detector
     */
protected void buildPath(PathBuilder builder, ItemState state, CycleDetector detector) throws ItemStateException, RepositoryException {
    // shortcut
    if (state.getId().equals(rootNodeId)) {
        builder.addRoot();
        return;
    }
    NodeId parentId = getParentId(state);
    if (parentId == null) {
        String msg = "failed to build path of " + state.getId() + ": orphaned item";
        log.debug(msg);
        throw new ItemNotFoundException(msg);
    } else if (detector.checkCycle(parentId)) {
        throw new InvalidItemStateException("Path cycle detected: " + parentId);
    }
    NodeState parent = (NodeState) getItemState(parentId);
    // recursively build path of parent
    buildPath(builder, parent, detector);
    if (state.isNode()) {
        NodeState nodeState = (NodeState) state;
        NodeId id = nodeState.getNodeId();
        ChildNodeEntry entry = getChildNodeEntry(parent, id);
        if (entry == null) {
            String msg = "failed to build path of " + state.getId() + ": " + parent.getNodeId() + " has no child entry for " + id;
            log.debug(msg);
            throw new ItemNotFoundException(msg);
        }
        // add to path
        if (entry.getIndex() == 1) {
            builder.addLast(entry.getName());
        } else {
            builder.addLast(entry.getName(), entry.getIndex());
        }
    } else {
        PropertyState propState = (PropertyState) state;
        Name name = propState.getName();
        // add to path
        builder.addLast(name);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) InvalidItemStateException(javax.jcr.InvalidItemStateException) ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) ItemNotFoundException(javax.jcr.ItemNotFoundException) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name)

Aggregations

PropertyState (org.apache.jackrabbit.core.state.PropertyState)53 PropertyId (org.apache.jackrabbit.core.id.PropertyId)25 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)25 NodeState (org.apache.jackrabbit.core.state.NodeState)25 RepositoryException (javax.jcr.RepositoryException)22 Name (org.apache.jackrabbit.spi.Name)22 InternalValue (org.apache.jackrabbit.core.value.InternalValue)19 NodeId (org.apache.jackrabbit.core.id.NodeId)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)14 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)13 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)5 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)5 ItemExistsException (javax.jcr.ItemExistsException)4 Value (javax.jcr.Value)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)4