use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class ObjectPersistenceManager method exists.
/**
* {@inheritDoc}
*/
public synchronized boolean exists(NodeId id) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
try {
String nodeFilePath = buildNodeFilePath(id);
FileSystemResource nodeFile = new FileSystemResource(itemStateFS, nodeFilePath);
return nodeFile.exists();
} catch (FileSystemException fse) {
String msg = "failed to check existence of item state: " + id;
log.error(msg, fse);
throw new ItemStateException(msg, fse);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class ObjectPersistenceManager method load.
/**
* {@inheritDoc}
*/
public synchronized NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
String nodeFilePath = buildNodeFilePath(id);
try {
if (!itemStateFS.isFile(nodeFilePath)) {
throw new NoSuchItemStateException(nodeFilePath);
}
} catch (FileSystemException fse) {
String msg = "failed to read node state: " + nodeFilePath;
log.debug(msg);
throw new ItemStateException(msg, fse);
}
try {
BufferedInputStream in = new BufferedInputStream(itemStateFS.getInputStream(nodeFilePath));
try {
NodeState state = createNew(id);
Serializer.deserialize(state, in);
return state;
} catch (Exception e) {
String msg = "failed to read node state: " + id;
log.debug(msg);
throw new ItemStateException(msg, e);
} finally {
in.close();
}
} catch (Exception e) {
String msg = "failed to read node state: " + nodeFilePath;
log.debug(msg);
throw new ItemStateException(msg, e);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class BundleDbPersistenceManager method store.
/**
* {@inheritDoc}
*
* This method uses shared <code>PreparedStatements</code>, which must
* be used 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
* statement must be synchronized.
*/
public synchronized void store(NodeReferences refs) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
// check if insert or update
boolean update = existsReferencesTo(refs.getTargetId());
String sql = (update) ? nodeReferenceUpdateSQL : nodeReferenceInsertSQL;
try {
ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
// serialize references
Serializer.serialize(refs, out);
Object[] params = createParams(refs.getTargetId(), out.toByteArray(), true);
conHelper.exec(sql, params);
// there's no need to close a ByteArrayOutputStream
//out.close();
} catch (Exception e) {
String msg = "failed to write " + refs;
log.error(msg, e);
throw new ItemStateException(msg, e);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class BundleDbPersistenceManager method loadReferencesTo.
/**
* {@inheritDoc}
*/
public synchronized NodeReferences loadReferencesTo(NodeId targetId) throws NoSuchItemStateException, ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
ResultSet rs = null;
InputStream in = null;
try {
rs = conHelper.exec(nodeReferenceSelectSQL, getKey(targetId), false, 0);
if (!rs.next()) {
throw new NoSuchItemStateException(targetId.toString());
}
in = rs.getBinaryStream(1);
NodeReferences refs = new NodeReferences(targetId);
Serializer.deserialize(refs, in);
return refs;
} catch (Exception e) {
if (e instanceof NoSuchItemStateException) {
throw (NoSuchItemStateException) e;
}
String msg = "failed to read references: " + targetId;
log.error(msg, e);
throw new ItemStateException(msg, e);
} finally {
IOUtils.closeQuietly(in);
DbUtility.close(rs);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class InMemPersistenceManager method load.
/**
* {@inheritDoc}
*/
public synchronized PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
byte[] data = stateStore.get(id);
if (data == null) {
throw new NoSuchItemStateException(id.toString());
}
ByteArrayInputStream in = new ByteArrayInputStream(data);
try {
PropertyState state = createNew(id);
Serializer.deserialize(state, in, blobStore);
return state;
} catch (Exception e) {
String msg = "failed to read property state: " + id;
log.debug(msg);
throw new ItemStateException(msg, e);
}
}
Aggregations