Search in sources :

Example 31 with ItemStateException

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

the class HierarchyManagerImpl method getDepth.

/**
     * {@inheritDoc}
     */
public int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException {
    // shortcut
    if (id.equals(rootNodeId)) {
        return 0;
    }
    try {
        ItemState state = getItemState(id);
        NodeId parentId = getParentId(state);
        int depth = 0;
        while (parentId != null) {
            depth++;
            state = getItemState(parentId);
            parentId = getParentId(state);
        }
        return depth;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine depth of " + id;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine depth of " + id;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 32 with ItemStateException

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

the class HierarchyManagerImpl method getRelativeDepth.

/**
     * {@inheritDoc}
     */
public int getRelativeDepth(NodeId ancestorId, ItemId descendantId) throws ItemNotFoundException, RepositoryException {
    if (ancestorId.equals(descendantId)) {
        return 0;
    }
    int depth = 1;
    try {
        ItemState state = getItemState(descendantId);
        NodeId parentId = getParentId(state);
        while (parentId != null) {
            if (parentId.equals(ancestorId)) {
                return depth;
            }
            depth++;
            state = getItemState(parentId);
            parentId = getParentId(state);
        }
        // not an ancestor
        return -1;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 33 with ItemStateException

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

the class HierarchyManagerImpl method isAncestor.

/**
     * {@inheritDoc}
     */
public boolean isAncestor(NodeId nodeId, ItemId itemId) throws ItemNotFoundException, RepositoryException {
    if (nodeId.equals(itemId)) {
        // can't be ancestor of self
        return false;
    }
    try {
        ItemState state = getItemState(itemId);
        NodeId parentId = getParentId(state);
        while (parentId != null) {
            if (parentId.equals(nodeId)) {
                return true;
            }
            state = getItemState(parentId);
            parentId = getParentId(state);
        }
        // not an ancestor
        return false;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine degree of relationship of " + nodeId + " and " + itemId;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine degree of relationship of " + nodeId + " and " + itemId;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 34 with ItemStateException

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

the class NodeImpl method getOrCreateProperty.

/**
     * @param name
     * @param type
     * @param multiValued
     * @param exactTypeMatch
     * @param status
     * @return
     * @throws ConstraintViolationException if no applicable property definition
     *                                      could be found
     * @throws RepositoryException          if another error occurs
     */
protected synchronized PropertyImpl getOrCreateProperty(Name name, int type, boolean multiValued, boolean exactTypeMatch, BitSet status) throws ConstraintViolationException, RepositoryException {
    status.clear();
    if (isNew() && !hasProperty(name)) {
        // this is a new node and the property does not exist yet
        // -> no need to check item manager
        PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
        PropertyImpl prop = createChildProperty(name, type, def);
        status.set(CREATED);
        return prop;
    }
    /*
         * Please note, that this implementation does not win a price for beauty
         * or speed. It's never a good idea to use exceptions for semantical
         * control flow.
         * However, compared to the previous version, this one is thread save
         * and makes the test/get block atomic in respect to transactional
         * commits. the test/set can still fail.
         *
         * Old Version:

            NodeState thisState = (NodeState) state;
            if (thisState.hasPropertyName(name)) {
                /**
                 * the following call will throw ItemNotFoundException if the
                 * current session doesn't have read access
                 /
                return getProperty(name);
            }
            [...create block...]

        */
    PropertyId propId = new PropertyId(getNodeId(), name);
    try {
        return (PropertyImpl) itemMgr.getItem(propId);
    } catch (AccessDeniedException ade) {
        throw new ItemNotFoundException(name.toString());
    } catch (ItemNotFoundException e) {
        // does not exist yet or has been removed transiently:
        // find definition for the specified property and (re-)create property
        PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
        PropertyImpl prop;
        if (stateMgr.hasTransientItemStateInAttic(propId)) {
            // remove from attic
            try {
                stateMgr.disposeTransientItemStateInAttic(stateMgr.getAttic().getItemState(propId));
            } catch (ItemStateException ise) {
                // shouldn't happen because we checked if it is in the attic
                throw new RepositoryException(ise);
            }
            prop = (PropertyImpl) itemMgr.getItem(propId);
            PropertyState state = (PropertyState) prop.getOrCreateTransientItemState();
            state.setMultiValued(multiValued);
            state.setType(type);
            getNodeState().addPropertyName(name);
        } else {
            prop = createChildProperty(name, type, def);
        }
        status.set(CREATED);
        return prop;
    }
}
Also used : AccessDeniedException(javax.jcr.AccessDeniedException) PropertyDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) ItemNotFoundException(javax.jcr.ItemNotFoundException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 35 with ItemStateException

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

the class NodeImpl method getOrCreateTransientItemState.

@Override
protected synchronized ItemState getOrCreateTransientItemState() throws RepositoryException {
    synchronized (data) {
        if (!isTransient()) {
            try {
                // make transient (copy-on-write)
                NodeState transientState = stateMgr.createTransientNodeState((NodeState) stateMgr.getItemState(getId()), ItemState.STATUS_EXISTING_MODIFIED);
                // replace persistent with transient state
                data.setState(transientState);
            } catch (ItemStateException ise) {
                String msg = "failed to create transient state";
                log.debug(msg);
                throw new RepositoryException(msg, ise);
            }
        }
        return getItemState();
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)141 RepositoryException (javax.jcr.RepositoryException)87 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)86 NodeId (org.apache.jackrabbit.core.id.NodeId)44 NodeState (org.apache.jackrabbit.core.state.NodeState)39 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)31 IOException (java.io.IOException)28 InvalidItemStateException (javax.jcr.InvalidItemStateException)27 PropertyState (org.apache.jackrabbit.core.state.PropertyState)24 SQLException (java.sql.SQLException)23 PropertyId (org.apache.jackrabbit.core.id.PropertyId)22 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)19 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)19 Name (org.apache.jackrabbit.spi.Name)17 ItemNotFoundException (javax.jcr.ItemNotFoundException)15 InternalValue (org.apache.jackrabbit.core.value.InternalValue)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)13 InputStream (java.io.InputStream)12