Add isDone() method on UnitOfWork.

This commit is contained in:
Greg Burd 2018-01-14 12:51:49 -05:00
parent 7b4e46431f
commit 3554b7ecb5
2 changed files with 12 additions and 2 deletions

View file

@ -312,7 +312,11 @@ public abstract class AbstractUnitOfWork<E extends Exception>
* @return a function from which to chain work that only happens when commit is successful * @return a function from which to chain work that only happens when commit is successful
* @throws E when the work overlaps with other concurrent writers. * @throws E when the work overlaps with other concurrent writers.
*/ */
public PostCommitFunction<Void, Void> commit() throws E, TimeoutException { public synchronized PostCommitFunction<Void, Void> commit() throws E, TimeoutException {
if (isDone()) {
return new PostCommitFunction(this, null, null, false);
}
// Only the outer-most UOW batches statements for commit time, execute them. // Only the outer-most UOW batches statements for commit time, execute them.
if (batch != null) { if (batch != null) {
@ -411,7 +415,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
/* Explicitly discard the work and mark it as as such in the log. */ /* Explicitly discard the work and mark it as as such in the log. */
public synchronized void abort() { public synchronized void abort() {
if (!aborted) { if (!isDone()) {
aborted = true; aborted = true;
// Spoil any pending futures created within the context of this unit of work. // Spoil any pending futures created within the context of this unit of work.
@ -458,6 +462,10 @@ public abstract class AbstractUnitOfWork<E extends Exception>
}); });
} }
public boolean isDone() {
return aborted || committed;
}
public String describeConflicts() { public String describeConflicts() {
return "it's complex..."; return "it's complex...";
} }

View file

@ -53,6 +53,8 @@ public interface UnitOfWork<X extends Exception> extends AutoCloseable {
boolean hasCommitted(); boolean hasCommitted();
boolean isDone();
long committedAt(); long committedAt();
void batch(AbstractOperation operation); void batch(AbstractOperation operation);