Search in sources :

Example 91 with ItemStateException

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

the class VersionManagerImplConfig method createConfiguration.

/**
     * Creates a new configuration node.
     * <p>
     * The nt:confguration is stored within the nt:configurations storage using
     * the nodeid of the configuration root (rootId) as path.
     *
     * @param state the node of the workspace configuration
     * @return the node id of the created configuration
     * @throws RepositoryException if an error occurs
     */
protected NodeId createConfiguration(NodeStateEx state) throws RepositoryException {
    WriteOperation ops = startWriteOperation();
    try {
        NodeId configId = internalCreateConfiguration(state.getNodeId(), null, null);
        // set configuration reference in state
        state.setPropertyValue(NameConstants.JCR_CONFIGURATION, InternalValue.create(configId));
        state.store();
        ops.save();
        return configId;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 92 with ItemStateException

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

the class VersionManagerImplConfig method restore.

/**
     * Restores the versions recorded in the given baseline below the specified
     * path.
     * @param parent the parent state
     * @param name the name of the new node (tree)
     * @param baseline the baseline that recorded the versions
     * @return the node id of the configuration
     * @throws RepositoryException if an error occurs
     */
protected NodeId restore(NodeStateEx parent, Name name, InternalBaseline baseline) throws RepositoryException {
    // check if nt:configuration exists
    NodeId configId = baseline.getConfigurationId();
    NodeId rootId = baseline.getConfigurationRootId();
    if (stateMgr.hasItemState(rootId)) {
        NodeStateEx existing = parent.getNode(rootId);
        String msg = "Configuration for the given baseline already exists at: " + safeGetJCRPath(existing);
        log.error(msg);
        throw new UnsupportedRepositoryOperationException(msg);
    }
    // find version for configuration root
    VersionSet versions = baseline.getBaseVersions();
    InternalVersion rootVersion = null;
    for (InternalVersion v : versions.versions().values()) {
        if (v.getVersionHistory().getVersionableId().equals(rootId)) {
            rootVersion = v;
            break;
        }
    }
    if (rootVersion == null) {
        String msg = "Internal error: supplied baseline has no version for its configuration root.";
        log.error(msg);
        throw new RepositoryException(msg);
    }
    // create new node below parent
    WriteOperation ops = startWriteOperation();
    try {
        if (!stateMgr.hasItemState(configId)) {
            // create if nt:configuration node is not exists
            internalCreateConfiguration(rootId, configId, baseline.getId());
        }
        NodeStateEx config = parent.getNode(configId);
        // create the root node so that the restore works
        InternalFrozenNode fn = rootVersion.getFrozenNode();
        NodeStateEx state = parent.addNode(name, fn.getFrozenPrimaryType(), fn.getFrozenId());
        state.setMixins(fn.getFrozenMixinTypes());
        parent.store();
        // and finally restore the config and root
        internalRestore(config, baseline, null, false);
        ops.save();
        return configId;
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 93 with ItemStateException

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

the class VersionManagerImplMerge method finishMerge.

/**
     * Perform {@link Node#cancelMerge(Version)} or {@link Node#doneMerge(Version)}
     * depending on the value of <code>cancel</code>.
     * @param state state to finish
     * @param version version
     * @param cancel flag inidicates if this is a cancel operation
     * @throws RepositoryException if an error occurs
     */
protected void finishMerge(NodeStateEx state, Version version, boolean cancel) throws RepositoryException {
    // check versionable
    if (!checkVersionable(state)) {
        throw new UnsupportedRepositoryOperationException("Node not full versionable: " + safeGetJCRPath(state));
    }
    // check if version is in mergeFailed list
    Set<NodeId> failed = getMergeFailed(state);
    NodeId versionId = ((VersionImpl) version).getNodeId();
    if (!failed.remove(versionId)) {
        String msg = "Unable to finish merge. Specified version is not in" + " jcr:mergeFailed property: " + safeGetJCRPath(state);
        log.error(msg);
        throw new VersionException(msg);
    }
    WriteOperation ops = startWriteOperation();
    try {
        // remove version from mergeFailed list
        setMergeFailed(state, failed);
        if (!cancel) {
            // add version to jcr:predecessors list
            InternalValue[] vals = state.getPropertyValues(NameConstants.JCR_PREDECESSORS);
            InternalValue[] v = new InternalValue[vals.length + 1];
            for (int i = 0; i < vals.length; i++) {
                v[i] = InternalValue.create(vals[i].getNodeId());
            }
            v[vals.length] = InternalValue.create(versionId);
            state.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, v, true);
        }
        state.store();
        ops.save();
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) VersionException(javax.jcr.version.VersionException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 94 with ItemStateException

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

the class NodeStateEx method removeNode.

/**
     * removes the child node with the given child node entry
     *
     * @param entry entry to remove
     * @return <code>true</code> if the child was removed.
     * @throws RepositoryException if an error occurs
     */
public boolean removeNode(ChildNodeEntry entry) throws RepositoryException {
    try {
        if (entry == null) {
            return false;
        } else {
            removeNode(entry.getId());
            nodeState.removeChildNodeEntry(entry.getId());
            nodeState.setStatus(ItemState.STATUS_EXISTING_MODIFIED);
            return true;
        }
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 95 with ItemStateException

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

the class NodeStateEx method reload.

/**
     * reloads the persistent state recursively
     *
     * @throws RepositoryException if an error occurs
     */
public void reload() throws RepositoryException {
    try {
        reload(nodeState);
        // refetch node state if discarded
        nodeState = (NodeState) stateMgr.getItemState(nodeState.getNodeId());
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) 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