Search in sources :

Example 41 with ItemStateException

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

the class XMLPersistenceManager method exists.

/**
     * {@inheritDoc}
     */
public synchronized boolean exists(PropertyId id) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    try {
        String propFilePath = buildPropFilePath(id);
        FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
        return propFile.exists();
    } catch (FileSystemException fse) {
        String msg = "failed to check existence of item state: " + id;
        log.error(msg, fse);
        throw new ItemStateException(msg, fse);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 42 with ItemStateException

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

the class XMLPersistenceManager method loadReferencesTo.

/**
     * {@inheritDoc}
     */
public synchronized NodeReferences loadReferencesTo(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    Exception e = null;
    String refsFilePath = buildNodeReferencesFilePath(id);
    try {
        if (!itemStateFS.isFile(refsFilePath)) {
            throw new NoSuchItemStateException(id.toString());
        }
        InputStream in = itemStateFS.getInputStream(refsFilePath);
        try {
            DOMWalker walker = new DOMWalker(in);
            NodeReferences refs = new NodeReferences(id);
            readState(walker, refs);
            return refs;
        } finally {
            in.close();
        }
    } catch (IOException ioe) {
        e = ioe;
    // fall through
    } catch (FileSystemException fse) {
        e = fse;
    // fall through
    }
    String msg = "failed to load references: " + id;
    log.debug(msg);
    throw new ItemStateException(msg, e);
}
Also used : DOMWalker(org.apache.jackrabbit.core.util.DOMWalker) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InputStream(java.io.InputStream) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) IOException(java.io.IOException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 43 with ItemStateException

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

the class VersionManagerImplRestore method restoreByLabel.

/**
     * @param state the state to restore
     * @param versionLabel the name of the version to restore
     * @param removeExisting remove existing flag
     * @throws RepositoryException if an error occurs
     *
     * @see VersionManager#restoreByLabel(String, String, boolean)
     */
protected void restoreByLabel(NodeStateEx state, Name versionLabel, boolean removeExisting) throws RepositoryException {
    checkVersionable(state);
    InternalVersion v = getVersionHistory(state).getVersionByLabel(versionLabel);
    if (v == null) {
        String msg = "No version for label " + versionLabel + " found.";
        log.error(msg);
        throw new VersionException(msg);
    }
    WriteOperation ops = startWriteOperation();
    try {
        internalRestore(state, v, new LabelVersionSelector(versionLabel), removeExisting);
        ops.save();
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) VersionException(javax.jcr.version.VersionException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 44 with ItemStateException

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

the class VersionManagerImplRestore method restore.

/**
     * Restores the <code>version</code> below the <code>parent</code> node
     * using the indicated <code>name</code>
     *
     * @param parent parent node
     * @param name desired name
     * @param v version to restore
     * @param removeExisting remove exiting flag
     * @throws RepositoryException if an error occurs
     */
protected void restore(NodeStateEx parent, Name name, InternalVersion v, boolean removeExisting) throws RepositoryException {
    // check if versionable node exists
    InternalFrozenNode fn = v.getFrozenNode();
    if (stateMgr.hasItemState(fn.getFrozenId())) {
        if (removeExisting) {
            NodeStateEx existing = parent.getNode(fn.getFrozenId());
            checkVersionable(existing);
            // move versionable node below this one using the given "name"
            WriteOperation ops = startWriteOperation();
            try {
                NodeStateEx exParent = existing.getParent();
                NodeStateEx state = parent.moveFrom(existing, name, false);
                exParent.store();
                parent.store();
                // and restore it
                internalRestore(state, v, new DateVersionSelector(v.getCreated()), removeExisting);
                ops.save();
            } catch (ItemStateException e) {
                throw new RepositoryException(e);
            } finally {
                ops.close();
            }
        } else {
            String msg = "Unable to restore version. Versionable node already exists.";
            log.error(msg);
            throw new ItemExistsException(msg);
        }
    } else {
        WriteOperation ops = startWriteOperation();
        try {
            // create new node below parent
            NodeStateEx state = parent.addNode(name, fn.getFrozenPrimaryType(), fn.getFrozenId());
            state.setMixins(fn.getFrozenMixinTypes());
            internalRestore(state, v, new DateVersionSelector(v.getCreated()), removeExisting);
            parent.store();
            ops.save();
        } catch (ItemStateException e) {
            throw new RepositoryException(e);
        } finally {
            ops.close();
        }
    }
}
Also used : ItemExistsException(javax.jcr.ItemExistsException) RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 45 with ItemStateException

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

the class VersionManagerImplRestore method restore.

/**
     * @param state the state to restore
     * @param v the version to restore
     * @param removeExisting remove existing flag
     * @throws RepositoryException if an error occurs
     *
     * @see javax.jcr.version.VersionManager#restore(String, Version, boolean)
     */
protected void restore(NodeStateEx state, InternalVersion v, boolean removeExisting) throws RepositoryException {
    checkVersionable(state);
    // check if 'own' version
    if (!v.getVersionHistory().equals(getVersionHistory(state))) {
        String msg = "Unable to restore version. Not same version history.";
        log.error(msg);
        throw new VersionException(msg);
    }
    WriteOperation ops = startWriteOperation();
    try {
        internalRestore(state, v, new DateVersionSelector(v.getCreated()), removeExisting);
        ops.save();
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) VersionException(javax.jcr.version.VersionException) 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