Search in sources :

Example 1 with ItemStateException

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

the class BundleLoader method loadBundle.

NodePropBundle loadBundle(NodeId id) throws ItemStateException {
    if (loadBundle != null) {
        try {
            return checkNotNull((NodePropBundle) loadBundle.invoke(pm, id), "Could not load NodePropBundle for id [%s]", id);
        } catch (InvocationTargetException e) {
            if (e.getCause() instanceof ItemStateException) {
                throw (ItemStateException) e.getCause();
            }
        // fall through
        } catch (IllegalArgumentException e) {
        // fall through
        } catch (IllegalAccessException e) {
        // fall through
        }
    }
    NodeState state = pm.load(id);
    checkNotNull(state, "Could not load NodeState for id [%s]", id);
    NodePropBundle bundle = new NodePropBundle(state);
    for (Name name : state.getPropertyNames()) {
        if (NameConstants.JCR_UUID.equals(name)) {
            bundle.setReferenceable(true);
        } else if (!NameConstants.JCR_PRIMARYTYPE.equals(name) && !NameConstants.JCR_MIXINTYPES.equals(name)) {
            bundle.addProperty(new PropertyEntry(pm.load(new PropertyId(id, name))));
        }
    }
    return bundle;
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) InvocationTargetException(java.lang.reflect.InvocationTargetException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 2 with ItemStateException

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

the class DatabasePersistenceManager method store.

/**
 * {@inheritDoc}
 * <p>
 * This method uses shared <code>PreparedStatement</code>s which must
 * be executed strictly sequentially. Because this method synchronizes on
 * the persistence manager instance there is no need to synchronize on the
 * shared statement. If the method would not be synchronized the shared
 * statements would have to be synchronized.
 */
@Override
public synchronized void store(NodeState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    // check if insert or update
    boolean update = state.getStatus() != ItemState.STATUS_NEW;
    // boolean update = exists(state.getId());
    String sql = (update) ? nodeStateUpdateSQL : nodeStateInsertSQL;
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
        // serialize node state
        Serializer.serialize(state, out);
        // we are synchronized on this instance, therefore we do not
        // not have to additionally synchronize on the sql statement
        executeStmt(sql, new Object[] { out.toByteArray(), state.getNodeId().toString() });
    // there's no need to close a ByteArrayOutputStream
    // out.close();
    } catch (Exception e) {
        String msg = "failed to write node state: " + state.getNodeId();
        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 3 with ItemStateException

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

the class OraclePersistenceManager method store.

/**
 * {@inheritDoc}
 */
public synchronized void store(NodeState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    // check if insert or update
    boolean update = state.getStatus() != ItemState.STATUS_NEW;
    // boolean update = exists((NodeId) state.getId());
    String sql = (update) ? nodeStateUpdateSQL : nodeStateInsertSQL;
    Blob blob = null;
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
        // serialize node state
        Serializer.serialize(state, out);
        // we are synchronized on this instance, therefore we do not
        // not have to additionally synchronize on the sql statement
        blob = createTemporaryBlob(new ByteArrayInputStream(out.toByteArray()));
        executeStmt(sql, new Object[] { blob, state.getNodeId().toString() });
    // there's no need to close a ByteArrayOutputStream
    // out.close();
    } catch (Exception e) {
        String msg = "failed to write node state: " + state.getId();
        log.error(msg, e);
        throw new ItemStateException(msg, e);
    } finally {
        if (blob != null) {
            try {
                freeTemporaryBlob(blob);
            } catch (Exception ignore) {
            }
        }
    }
}
Also used : Blob(java.sql.Blob) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 4 with ItemStateException

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

the class InMemBundlePersistenceManager method storeBundle.

/**
 * {@inheritDoc}
 */
@Override
protected void storeBundle(NodePropBundle bundle) throws ItemStateException {
    ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
    try {
        binding.writeBundle(out, bundle);
        bundleStore.put(bundle.getId(), out.toByteArray());
    } catch (IOException e) {
        String msg = "failed to write bundle: " + bundle.getId();
        log.error(msg, e);
        throw new ItemStateException(msg, e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 5 with ItemStateException

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

the class ObjectPersistenceManager 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.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)

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