use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class ObjectPersistenceManager method loadReferencesTo.
/**
* {@inheritDoc}
*/
public synchronized NodeReferences loadReferencesTo(NodeId id) throws NoSuchItemStateException, ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
String refsFilePath = buildNodeReferencesFilePath(id);
try {
if (!itemStateFS.isFile(refsFilePath)) {
throw new NoSuchItemStateException(id.toString());
}
} catch (FileSystemException fse) {
String msg = "failed to load references: " + id;
log.debug(msg);
throw new ItemStateException(msg, fse);
}
try {
BufferedInputStream in = new BufferedInputStream(itemStateFS.getInputStream(refsFilePath));
try {
NodeReferences refs = new NodeReferences(id);
Serializer.deserialize(refs, in);
return refs;
} finally {
in.close();
}
} catch (Exception e) {
String msg = "failed to load references: " + id;
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 storeBundle.
/**
* {@inheritDoc}
*/
protected synchronized void storeBundle(NodePropBundle bundle) throws ItemStateException {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);
binding.writeBundle(out, bundle);
String sql = bundle.isNew() ? bundleInsertSQL : bundleUpdateSQL;
Object[] params = createParams(bundle.getId(), out.toByteArray(), true);
conHelper.update(sql, params);
} catch (Exception e) {
String msg;
if (isIntegrityConstraintViolation(e)) {
// we should never get an integrity constraint violation here
// other PMs may not be able to detect this and end up with
// corrupted data
msg = "FATAL error while writing the bundle: " + bundle.getId();
} else {
msg = "failed to write bundle: " + bundle.getId();
}
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 store.
/**
* {@inheritDoc}
*
* Basically wraps a JDBC transaction around super.store().
*
* FIXME: the retry logic is almost a duplicate of {@code ConnectionHelper.RetryManager}.
*/
public synchronized void store(final ChangeLog changeLog) throws ItemStateException {
int failures = 0;
ItemStateException lastException = null;
boolean sleepInterrupted = false;
while (!sleepInterrupted && (blockOnConnectionLoss || failures <= 1)) {
try {
conHelper.startBatch();
super.store(changeLog);
conHelper.endBatch(true);
return;
} catch (SQLException e) {
// Either startBatch or stopBatch threw it: either way the
// transaction was not persisted and no action needs to be taken.
lastException = new ItemStateException(e.getMessage(), e);
} catch (ItemStateException e) {
// store call threw it: we need to cancel the transaction
lastException = e;
try {
conHelper.endBatch(false);
} catch (SQLException e2) {
DbUtility.logException("rollback failed", e2);
}
// are running in test mode, we really want to stop
assert !isIntegrityConstraintViolation(e.getCause());
}
failures++;
log.error("Failed to persist ChangeLog (stacktrace on DEBUG log level), blockOnConnectionLoss = " + blockOnConnectionLoss + ": " + lastException);
log.debug("Failed to persist ChangeLog", lastException);
if (blockOnConnectionLoss || failures <= 1) {
// if we're going to try again
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
sleepInterrupted = true;
log.error("Interrupted: canceling retry of ChangeLog storage");
}
}
}
throw lastException;
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class ObjectPersistenceManager method destroy.
/**
* {@inheritDoc}
*/
protected void destroy(NodeReferences refs) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId());
FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
try {
if (refsFile.exists()) {
// delete resource and prune empty parent folders
refsFile.delete(true);
}
} catch (FileSystemException fse) {
String msg = "failed to delete " + refs;
log.debug(msg);
throw new ItemStateException(msg, fse);
}
}
use of org.apache.jackrabbit.core.state.ItemStateException in project jackrabbit by apache.
the class VersionManagerImplRestore method restore.
/**
* @param state the state to restore
* @param versionName the name of the version to restore
* @param removeExisting remove existing flag
* @throws RepositoryException if an error occurs
*
* @see VersionManager#restore(String, String, boolean)
*/
protected void restore(NodeStateEx state, Name versionName, boolean removeExisting) throws RepositoryException {
checkVersionable(state);
InternalVersion v = getVersionHistory(state).getVersion(versionName);
DateVersionSelector gvs = new DateVersionSelector(v.getCreated());
WriteOperation ops = startWriteOperation();
try {
internalRestore(state, v, gvs, removeExisting);
ops.save();
} catch (ItemStateException e) {
throw new RepositoryException(e);
} finally {
ops.close();
}
}
Aggregations