Search in sources :

Example 1 with NoSuchItemStateException

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

the class XMLPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    Exception e = null;
    String nodeFilePath = buildNodeFilePath(id);
    try {
        if (!itemStateFS.isFile(nodeFilePath)) {
            throw new NoSuchItemStateException(id.toString());
        }
        InputStream in = itemStateFS.getInputStream(nodeFilePath);
        try {
            DOMWalker walker = new DOMWalker(in);
            String ntName = walker.getAttribute(NODETYPE_ATTRIBUTE);
            NodeState state = createNew(id);
            state.setNodeTypeName(factory.create(ntName));
            readState(walker, state);
            return state;
        } finally {
            in.close();
        }
    } catch (IOException ioe) {
        e = ioe;
    // fall through
    } catch (FileSystemException fse) {
        e = fse;
    // fall through
    }
    String msg = "failed to read node state: " + 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) NodeState(org.apache.jackrabbit.core.state.NodeState) InputStream(java.io.InputStream) 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 2 with NoSuchItemStateException

use of org.apache.jackrabbit.core.state.NoSuchItemStateException 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 3 with NoSuchItemStateException

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

the class DatabasePersistenceManager method load.

/**
     * {@inheritDoc}
     */
public PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    synchronized (propertyStateSelectSQL) {
        ResultSet rs = null;
        InputStream in = null;
        try {
            Statement stmt = executeStmt(propertyStateSelectSQL, new Object[] { id.toString() });
            rs = stmt.getResultSet();
            if (!rs.next()) {
                throw new NoSuchItemStateException(id.toString());
            }
            in = rs.getBinaryStream(1);
            if (!externalBLOBs) {
                // JCR-1532: pre-fetch/buffer stream data
                ByteArrayInputStream bain = new ByteArrayInputStream(IOUtils.toByteArray(in));
                IOUtils.closeQuietly(in);
                in = bain;
            }
            PropertyState state = createNew(id);
            Serializer.deserialize(state, in, blobStore);
            return state;
        } catch (Exception e) {
            if (e instanceof NoSuchItemStateException) {
                throw (NoSuchItemStateException) e;
            }
            String msg = "failed to read property state: " + id;
            log.error(msg, e);
            throw new ItemStateException(msg, e);
        } finally {
            IOUtils.closeQuietly(in);
            closeResultSet(rs);
        }
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ByteArrayInputStream(java.io.ByteArrayInputStream) FilterInputStream(java.io.FilterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) 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) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 4 with NoSuchItemStateException

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

the class ObjectPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String propFilePath = buildPropFilePath(id);
    try {
        if (!itemStateFS.isFile(propFilePath)) {
            throw new NoSuchItemStateException(propFilePath);
        }
    } catch (FileSystemException fse) {
        String msg = "failed to read property state: " + propFilePath;
        log.debug(msg);
        throw new ItemStateException(msg, fse);
    }
    try {
        BufferedInputStream in = new BufferedInputStream(itemStateFS.getInputStream(propFilePath));
        try {
            PropertyState state = createNew(id);
            Serializer.deserialize(state, in, blobStore);
            return state;
        } finally {
            in.close();
        }
    } catch (Exception e) {
        String msg = "failed to read property state: " + propFilePath;
        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) 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) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 5 with NoSuchItemStateException

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

the class HierarchyManagerImpl method isShareAncestor.

/**
     * {@inheritDoc}
     */
public boolean isShareAncestor(NodeId ancestor, NodeId descendant) throws ItemNotFoundException, RepositoryException {
    if (ancestor.equals(descendant)) {
        // can't be ancestor of self
        return false;
    }
    try {
        ItemState state = getItemState(descendant);
        Set<NodeId> parentIds = getParentIds(state, false);
        while (parentIds.size() > 0) {
            if (parentIds.contains(ancestor)) {
                return true;
            }
            Set<NodeId> grandparentIds = new LinkedHashSet<NodeId>();
            for (NodeId parentId : parentIds) {
                grandparentIds.addAll(getParentIds(getItemState(parentId), false));
            }
            parentIds = grandparentIds;
        }
        // not an ancestor
        return false;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)37 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)31 RepositoryException (javax.jcr.RepositoryException)17 NodeId (org.apache.jackrabbit.core.id.NodeId)14 NodeState (org.apache.jackrabbit.core.state.NodeState)13 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)11 PropertyState (org.apache.jackrabbit.core.state.PropertyState)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 InvalidItemStateException (javax.jcr.InvalidItemStateException)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)8 ItemState (org.apache.jackrabbit.core.state.ItemState)8 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)8 SQLException (java.sql.SQLException)7 PropertyId (org.apache.jackrabbit.core.id.PropertyId)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 Name (org.apache.jackrabbit.spi.Name)6 InternalValue (org.apache.jackrabbit.core.value.InternalValue)5 FilterInputStream (java.io.FilterInputStream)4