use of com.b2international.index.IndexException in project snow-owl by b2ihealthcare.
the class RepositoryTransactionContext method commit.
@Override
public Optional<Commit> commit(String author, String commitComment, String parentLockContext) {
if (!isDirty()) {
return Optional.empty();
}
// fall back to the current lock context or ROOT if none is present
if (Strings.isNullOrEmpty(parentLockContext)) {
parentLockContext = optionalService(Locks.class).map(Locks::lockContext).orElse(DatastoreLockContextDescriptions.ROOT);
}
final DatastoreLockContext lockContext = createLockContext(service(User.class).getUsername(), parentLockContext);
final DatastoreLockTarget lockTarget = createLockTarget(info().id(), path());
IOperationLockManager locks = service(IOperationLockManager.class);
Commit commit = null;
try {
locks.lock(lockContext, 1000L, lockTarget);
final long timestamp = service(TimestampProvider.class).getTimestamp();
log().info("Persisting changes to {}@{}", path(), timestamp);
commit = staging.commit(null, timestamp, author, commitComment);
log().info("Changes have been successfully persisted to {}@{}.", path(), timestamp);
return Optional.ofNullable(commit);
} catch (final IndexException e) {
Throwable rootCause = Throwables.getRootCause(e);
if (rootCause instanceof CycleDetectedException) {
throw (CycleDetectedException) rootCause;
}
throw new SnowowlRuntimeException(e.getMessage(), e);
} finally {
locks.unlock(lockContext, lockTarget);
if (commit != null && isNotificationEnabled()) {
service(RepositoryCommitNotificationSender.class).publish(this, commit);
}
clear();
}
}
Aggregations