Search in sources :

Example 81 with ItemStateException

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

the class InMemPersistenceManager method loadReferencesTo.

/**
     * {@inheritDoc}
     */
public synchronized NodeReferences loadReferencesTo(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    byte[] data = refsStore.get(id);
    if (data == null) {
        throw new NoSuchItemStateException(id.toString());
    }
    ByteArrayInputStream in = new ByteArrayInputStream(data);
    try {
        NodeReferences refs = new NodeReferences(id);
        Serializer.deserialize(refs, in);
        return refs;
    } catch (Exception e) {
        String msg = "failed to load references: " + id;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 82 with ItemStateException

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

the class InMemPersistenceManager method store.

/**
     * {@inheritDoc}
     */
protected void store(NodeReferences refs) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
        // serialize references
        Serializer.serialize(refs, out);
        // store in serialized format in map for better memory efficiency
        refsStore.put(refs.getTargetId(), out.toByteArray());
    // there's no need to close a ByteArrayOutputStream
    //out.close();
    } catch (Exception e) {
        String msg = "failed to store " + refs;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 83 with ItemStateException

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

the class InMemPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    byte[] data = stateStore.get(id);
    if (data == null) {
        throw new NoSuchItemStateException(id.toString());
    }
    ByteArrayInputStream in = new ByteArrayInputStream(data);
    try {
        NodeState state = createNew(id);
        Serializer.deserialize(state, in);
        return state;
    } catch (Exception e) {
        String msg = "failed to read node state: " + id;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeState(org.apache.jackrabbit.core.state.NodeState) ByteArrayInputStream(java.io.ByteArrayInputStream) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 84 with ItemStateException

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

the class ObjectPersistenceManager method store.

/**
     * {@inheritDoc}
     */
protected void store(NodeReferences refs) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId());
    FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
    try {
        refsFile.makeParentDirs();
        OutputStream out = new BufferedOutputStream(refsFile.getOutputStream());
        try {
            Serializer.serialize(refs, out);
        } finally {
            out.close();
        }
    } catch (Exception e) {
        String msg = "failed to store " + refs;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) BufferedOutputStream(java.io.BufferedOutputStream) 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 85 with ItemStateException

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

the class ObjectPersistenceManager method destroy.

/**
     * {@inheritDoc}
     */
protected void destroy(PropertyState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    // delete binary values (stored as files)
    InternalValue[] values = state.getValues();
    if (values != null) {
        for (int i = 0; i < values.length; i++) {
            InternalValue val = values[i];
            if (val != null) {
                val.deleteBinaryResource();
            }
        }
    }
    // delete property file
    String propFilePath = buildPropFilePath(state.getPropertyId());
    FileSystemResource propFile = new FileSystemResource(itemStateFS, propFilePath);
    try {
        if (propFile.exists()) {
            // delete resource and prune empty parent folders
            propFile.delete(true);
        }
    } catch (FileSystemException fse) {
        String msg = "failed to delete property state: " + state.getParentId() + "/" + state.getName();
        log.debug(msg);
        throw new ItemStateException(msg, fse);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) InternalValue(org.apache.jackrabbit.core.value.InternalValue) 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