diff --git a/src/main/java/net/helenus/core/AbstractUnitOfWork.java b/src/main/java/net/helenus/core/AbstractUnitOfWork.java index 33a2155..bf283a2 100644 --- a/src/main/java/net/helenus/core/AbstractUnitOfWork.java +++ b/src/main/java/net/helenus/core/AbstractUnitOfWork.java @@ -312,7 +312,11 @@ public abstract class AbstractUnitOfWork * @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. */ - public PostCommitFunction commit() throws E, TimeoutException { + public synchronized PostCommitFunction 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. if (batch != null) { @@ -411,7 +415,7 @@ public abstract class AbstractUnitOfWork /* Explicitly discard the work and mark it as as such in the log. */ public synchronized void abort() { - if (!aborted) { + if (!isDone()) { aborted = true; // Spoil any pending futures created within the context of this unit of work. @@ -458,6 +462,10 @@ public abstract class AbstractUnitOfWork }); } + public boolean isDone() { + return aborted || committed; + } + public String describeConflicts() { return "it's complex..."; } diff --git a/src/main/java/net/helenus/core/UnitOfWork.java b/src/main/java/net/helenus/core/UnitOfWork.java index 5df73e2..3c41717 100644 --- a/src/main/java/net/helenus/core/UnitOfWork.java +++ b/src/main/java/net/helenus/core/UnitOfWork.java @@ -53,6 +53,8 @@ public interface UnitOfWork extends AutoCloseable { boolean hasCommitted(); + boolean isDone(); + long committedAt(); void batch(AbstractOperation operation);