Search in sources :

Example 86 with ItemStateException

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

the class ObjectPersistenceManager method loadReferencesTo.

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

Example 87 with ItemStateException

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

the class BundleDbPersistenceManager method storeBundle.

/**
     * {@inheritDoc}
     */
protected synchronized void storeBundle(NodePropBundle bundle) throws ItemStateException {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
        binding.writeBundle(out, bundle);
        String sql = bundle.isNew() ? bundleInsertSQL : bundleUpdateSQL;
        Object[] params = createParams(bundle.getId(), out.toByteArray(), true);
        conHelper.update(sql, params);
    } catch (Exception e) {
        String msg;
        if (isIntegrityConstraintViolation(e)) {
            // we should never get an integrity constraint violation here
            // other PMs may not be able to detect this and end up with
            // corrupted data
            msg = "FATAL error while writing the bundle: " + bundle.getId();
        } else {
            msg = "failed to write bundle: " + bundle.getId();
        }
        log.error(msg, e);
        throw new ItemStateException(msg, e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) SQLException(java.sql.SQLException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 88 with ItemStateException

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

the class BundleDbPersistenceManager method store.

/**
     * {@inheritDoc}
     *
     * Basically wraps a JDBC transaction around super.store().
     * 
     * FIXME: the retry logic is almost a duplicate of {@code ConnectionHelper.RetryManager}.
     */
public synchronized void store(final ChangeLog changeLog) throws ItemStateException {
    int failures = 0;
    ItemStateException lastException = null;
    boolean sleepInterrupted = false;
    while (!sleepInterrupted && (blockOnConnectionLoss || failures <= 1)) {
        try {
            conHelper.startBatch();
            super.store(changeLog);
            conHelper.endBatch(true);
            return;
        } catch (SQLException e) {
            // Either startBatch or stopBatch threw it: either way the
            // transaction was not persisted and no action needs to be taken.
            lastException = new ItemStateException(e.getMessage(), e);
        } catch (ItemStateException e) {
            // store call threw it: we need to cancel the transaction
            lastException = e;
            try {
                conHelper.endBatch(false);
            } catch (SQLException e2) {
                DbUtility.logException("rollback failed", e2);
            }
            // are running in test mode, we really want to stop
            assert !isIntegrityConstraintViolation(e.getCause());
        }
        failures++;
        log.error("Failed to persist ChangeLog (stacktrace on DEBUG log level), blockOnConnectionLoss = " + blockOnConnectionLoss + ": " + lastException);
        log.debug("Failed to persist ChangeLog", lastException);
        if (blockOnConnectionLoss || failures <= 1) {
            // if we're going to try again
            try {
                Thread.sleep(100);
            } catch (InterruptedException e1) {
                Thread.currentThread().interrupt();
                sleepInterrupted = true;
                log.error("Interrupted: canceling retry of ChangeLog storage");
            }
        }
    }
    throw lastException;
}
Also used : SQLException(java.sql.SQLException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 89 with ItemStateException

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

the class ObjectPersistenceManager method destroy.

/**
     * {@inheritDoc}
     */
protected void destroy(NodeReferences refs) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId());
    FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
    try {
        if (refsFile.exists()) {
            // delete resource and prune empty parent folders
            refsFile.delete(true);
        }
    } catch (FileSystemException fse) {
        String msg = "failed to delete " + refs;
        log.debug(msg);
        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 90 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 versionName the name of the version to restore
     * @param removeExisting remove existing flag
     * @throws RepositoryException if an error occurs
     *
     * @see VersionManager#restore(String, String, boolean)
     */
protected void restore(NodeStateEx state, Name versionName, boolean removeExisting) throws RepositoryException {
    checkVersionable(state);
    InternalVersion v = getVersionHistory(state).getVersion(versionName);
    DateVersionSelector gvs = new DateVersionSelector(v.getCreated());
    WriteOperation ops = startWriteOperation();
    try {
        internalRestore(state, v, gvs, removeExisting);
        ops.save();
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
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