Search in sources :

Example 11 with ItemStateException

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

the class DatabasePersistenceManager method exists.

/**
     * {@inheritDoc}
     */
public boolean exists(PropertyId id) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    synchronized (propertyStateSelectExistSQL) {
        ResultSet rs = null;
        try {
            Statement stmt = executeStmt(propertyStateSelectExistSQL, new Object[] { id.toString() });
            rs = stmt.getResultSet();
            // a property state exists if the result has at least one entry
            return rs.next();
        } catch (Exception e) {
            String msg = "failed to check existence of property state: " + id;
            log.error(msg, e);
            throw new ItemStateException(msg, e);
        } finally {
            closeResultSet(rs);
        }
    }
}
Also used : 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) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 12 with ItemStateException

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

the class DatabasePersistenceManager method existsReferencesTo.

/**
     * {@inheritDoc}
     */
public boolean existsReferencesTo(NodeId targetId) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    synchronized (nodeReferenceSelectExistSQL) {
        ResultSet rs = null;
        try {
            Statement stmt = executeStmt(nodeReferenceSelectExistSQL, new Object[] { targetId.toString() });
            rs = stmt.getResultSet();
            // a reference exists if the result has at least one entry
            return rs.next();
        } catch (Exception e) {
            String msg = "failed to check existence of node references: " + targetId;
            log.error(msg, e);
            throw new ItemStateException(msg, e);
        } finally {
            closeResultSet(rs);
        }
    }
}
Also used : 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) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 13 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)

Example 14 with ItemStateException

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

the class BundleDbPersistenceManager method getAllNodeInfos.

/**
     * {@inheritDoc}
     */
@Override
public synchronized Map<NodeId, NodeInfo> getAllNodeInfos(NodeId bigger, int maxCount) throws ItemStateException {
    ResultSet rs = null;
    try {
        String sql = bundleSelectAllBundlesSQL;
        NodeId lowId = null;
        Object[] keys = new Object[0];
        if (bigger != null) {
            sql = bundleSelectAllBundlesFromSQL;
            lowId = bigger;
            keys = getKey(bigger);
        }
        if (getStorageModel() == SM_LONGLONG_KEYS && maxCount > 0) {
            // get some more rows, in case the first row is smaller
            // only required for SM_LONGLONG_KEYS
            // probability is very low to get get the wrong first key, < 1 : 2^64
            // see also bundleSelectAllIdsFrom SQL statement
            maxCount += 10;
        }
        rs = conHelper.exec(sql, keys, false, maxCount);
        Map<NodeId, NodeInfo> result = new LinkedHashMap<NodeId, NodeInfo>(maxCount);
        while ((maxCount == 0 || result.size() < maxCount) && rs.next()) {
            NodeId current;
            if (getStorageModel() == SM_BINARY_KEYS) {
                current = new NodeId(rs.getBytes(1));
            } else {
                long high = rs.getLong(1);
                long low = rs.getLong(2);
                current = new NodeId(high, low);
            }
            if (getStorageModel() == SM_LONGLONG_KEYS && lowId != null) {
                // skip the keys that are smaller or equal (see above, maxCount += 10)
                if (current.compareTo(lowId) <= 0) {
                    continue;
                }
            }
            NodePropBundle bundle = readBundle(current, rs, getStorageModel() == SM_LONGLONG_KEYS ? 3 : 2);
            NodeInfo nodeInfo = new NodeInfo(bundle);
            result.put(nodeInfo.getId(), nodeInfo);
        }
        return result;
    } catch (SQLException e) {
        String msg = "getAllNodeIds failed.";
        log.error(msg, e);
        throw new ItemStateException(msg, e);
    } finally {
        DbUtility.close(rs);
    }
}
Also used : SQLException(java.sql.SQLException) NodeInfo(org.apache.jackrabbit.core.persistence.util.NodeInfo) ResultSet(java.sql.ResultSet) NodeId(org.apache.jackrabbit.core.id.NodeId) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) LinkedHashMap(java.util.LinkedHashMap) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 15 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)

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