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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations