Search in sources :

Example 21 with ItemStateException

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

the class ObjectPersistenceManager method destroy.

/**
     * {@inheritDoc}
     */
protected void destroy(NodeState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String nodeFilePath = buildNodeFilePath(state.getNodeId());
    FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
    try {
        if (nodeFile.exists()) {
            // delete resource and prune empty parent folders
            nodeFile.delete(true);
        }
    } catch (FileSystemException fse) {
        String msg = "failed to delete node state: " + state.getNodeId();
        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 22 with ItemStateException

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

the class BundleDbPersistenceManager method getAllNodeIds.

/**
     * {@inheritDoc}
     */
public synchronized List<NodeId> getAllNodeIds(NodeId bigger, int maxCount) throws ItemStateException, RepositoryException {
    ResultSet rs = null;
    try {
        String sql = bundleSelectAllIdsSQL;
        NodeId lowId = null;
        Object[] keys = new Object[0];
        if (bigger != null) {
            sql = bundleSelectAllIdsFromSQL;
            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);
        ArrayList<NodeId> result = new ArrayList<NodeId>();
        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 (lowId != null) {
                    // only required for SM_LONGLONG_KEYS
                    if (current.compareTo(lowId) <= 0) {
                        continue;
                    }
                }
            }
            result.add(current);
        }
        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) ResultSet(java.sql.ResultSet) NodeId(org.apache.jackrabbit.core.id.NodeId) ArrayList(java.util.ArrayList) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 23 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 24 with ItemStateException

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

the class DatabasePersistenceManager method destroy.

/**
     * {@inheritDoc}
     */
public synchronized void destroy(PropertyState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    // make sure binary values (BLOBs) are properly removed
    InternalValue[] values = state.getValues();
    if (values != null) {
        for (int i = 0; i < values.length; i++) {
            InternalValue val = values[i];
            if (val != null) {
                if (val.getType() == PropertyType.BINARY) {
                    val.deleteBinaryResource();
                    // also remove from BLOBStore
                    String blobId = blobStore.createId(state.getPropertyId(), i);
                    try {
                        blobStore.remove(blobId);
                    } catch (Exception e) {
                        log.warn("failed to remove from BLOBStore: " + blobId, e);
                    }
                }
            }
        }
    }
    try {
        // we are synchronized on this instance, therefore we do not
        // not have to additionally synchronize on the sql statement
        executeStmt(propertyStateDeleteSQL, new Object[] { state.getPropertyId().toString() });
    } catch (Exception e) {
        String msg = "failed to delete property state: " + state.getPropertyId();
        log.error(msg, e);
        throw new ItemStateException(msg, e);
    }
}
Also used : InternalValue(org.apache.jackrabbit.core.value.InternalValue) 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 25 with ItemStateException

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

the class InMemPersistenceManager method store.

/**
     * {@inheritDoc}
     */
protected void store(PropertyState state) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
        // serialize property state
        Serializer.serialize(state, out, blobStore);
        // store in serialized format in map for better memory efficiency
        stateStore.put(state.getPropertyId(), out.toByteArray());
    // there's no need to close a ByteArrayOutputStream
    //out.close();
    } catch (Exception e) {
        String msg = "failed to store property state: " + state.getPropertyId();
        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)

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