Search in sources :

Example 6 with ItemStateException

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

the class GarbageCollector method scanPersistenceManagersByNodeIds.

private void scanPersistenceManagersByNodeIds() throws RepositoryException, ItemStateException {
    int pmCount = 0;
    for (IterablePersistenceManager pm : pmList) {
        pmCount++;
        List<NodeId> allNodeIds = pm.getAllNodeIds(null, 0);
        int overAllCount = allNodeIds.size();
        if (overAllCount > minSplitSize) {
            final int splits = getConcurrentThreadSize();
            ExecutorService executorService = Executors.newFixedThreadPool(splits);
            try {
                Set<Future<Void>> futures = new HashSet<Future<Void>>();
                List<List<NodeId>> lists = splitIntoParts(allNodeIds, splits);
                LOG.debug(splits + " concurrent Threads will be started. Split Size: " + lists.get(0).size() + " Total Size: " + overAllCount);
                for (int i = 0; i < splits; i++) {
                    List<NodeId> subList = lists.get(i);
                    futures.add(executorService.submit(new ScanNodeIdListTask(i + 1, subList, pm, pmCount)));
                }
                for (Future<Void> future : futures) {
                    future.get();
                }
            } catch (Exception e) {
                throw new RepositoryException(e);
            } finally {
                executorService.shutdown();
            }
        } else {
            scanNodeIdList(0, allNodeIds, pm, pmCount);
        }
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) NodeId(org.apache.jackrabbit.core.id.NodeId) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 7 with ItemStateException

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

the class GarbageCollector method mark.

public void mark() throws RepositoryException {
    if (store == null) {
        throw new RepositoryException("No DataStore configured.");
    }
    long now = System.currentTimeMillis();
    if (startScanTimestamp == 0) {
        startScanTimestamp = now;
        store.updateModifiedDateOnAccess(startScanTimestamp);
    }
    if (pmList == null || !persistenceManagerScan) {
        for (SessionImpl s : sessionList) {
            scanNodes(s);
        }
    } else {
        try {
            if (!NODE_ID_SCAN) {
                scanPersistenceManagersByNodeInfos();
            } else {
                scanPersistenceManagersByNodeIds();
            }
        } catch (ItemStateException e) {
            throw new RepositoryException(e);
        }
    }
}
Also used : RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 8 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(PropertyState 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) ? propertyStateUpdateSQL : propertyStateInsertSQL;
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
        // serialize property state
        Serializer.serialize(state, out, blobStore);
        // 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.getPropertyId().toString() });
    // there's no need to close a ByteArrayOutputStream
    //out.close();
    } catch (Exception e) {
        String msg = "failed to write property state: " + state.getPropertyId();
        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 9 with ItemStateException

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

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

the class DatabasePersistenceManager method exists.

/**
     * {@inheritDoc}
     */
public boolean exists(NodeId id) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    synchronized (nodeStateSelectExistSQL) {
        ResultSet rs = null;
        try {
            Statement stmt = executeStmt(nodeStateSelectExistSQL, new Object[] { id.toString() });
            rs = stmt.getResultSet();
            // a node state exists if the result has at least one entry
            return rs.next();
        } catch (Exception e) {
            String msg = "failed to check existence of node 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)

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