Search in sources :

Example 36 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class ObjectPersistenceManager method exists.

/**
     * {@inheritDoc}
     */
public synchronized boolean exists(NodeId id) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    try {
        String nodeFilePath = buildNodeFilePath(id);
        FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
        return nodeFile.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 37 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException in project jackrabbit by apache.

the class ObjectPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String nodeFilePath = buildNodeFilePath(id);
    try {
        if (!itemStateFS.isFile(nodeFilePath)) {
            throw new NoSuchItemStateException(nodeFilePath);
        }
    } catch (FileSystemException fse) {
        String msg = "failed to read node state: " + nodeFilePath;
        log.debug(msg);
        throw new ItemStateException(msg, fse);
    }
    try {
        BufferedInputStream in = new BufferedInputStream(itemStateFS.getInputStream(nodeFilePath));
        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);
        } finally {
            in.close();
        }
    } catch (Exception e) {
        String msg = "failed to read node state: " + nodeFilePath;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeState(org.apache.jackrabbit.core.state.NodeState) BufferedInputStream(java.io.BufferedInputStream) 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 38 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException 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)

Example 39 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException 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 40 with FileSystemException

use of org.apache.jackrabbit.core.fs.FileSystemException 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)

Aggregations

FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)54 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)19 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)18 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)16 IOException (java.io.IOException)15 SQLException (java.sql.SQLException)15 File (java.io.File)11 ResultSet (java.sql.ResultSet)10 InputStream (java.io.InputStream)7 RepositoryException (javax.jcr.RepositoryException)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 OutputStreamWriter (java.io.OutputStreamWriter)4 ArrayList (java.util.ArrayList)4 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)4 BufferedInputStream (java.io.BufferedInputStream)3 BufferedWriter (java.io.BufferedWriter)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Properties (java.util.Properties)3 FileFilter (java.io.FileFilter)2 FileInputStream (java.io.FileInputStream)2