diff --git a/src/main/java/net/helenus/core/HelenusSession.java b/src/main/java/net/helenus/core/HelenusSession.java index df5c6fe..cdc968b 100644 --- a/src/main/java/net/helenus/core/HelenusSession.java +++ b/src/main/java/net/helenus/core/HelenusSession.java @@ -151,11 +151,15 @@ public final class HelenusSession extends AbstractSessionOperations implements C } } - public synchronized void commit() throws ConflictingUnitOfWorkException { - if (currentUnitOfWork != null) { - currentUnitOfWork.commit(); - currentUnitOfWork = null; + public synchronized Function commit() throws ConflictingUnitOfWorkException { + final Function f = Function.identity(); + synchronized(currentUnitOfWork) { + if (currentUnitOfWork != null) { + currentUnitOfWork.commit().andThen((it) -> { return f; }); + currentUnitOfWork = null; + } } + return f; } public synchronized void abort() { diff --git a/src/main/java/net/helenus/core/UnitOfWork.java b/src/main/java/net/helenus/core/UnitOfWork.java index b0665cd..79902f6 100644 --- a/src/main/java/net/helenus/core/UnitOfWork.java +++ b/src/main/java/net/helenus/core/UnitOfWork.java @@ -1,6 +1,7 @@ package net.helenus.core; import java.util.ArrayList; +import java.util.function.Function; /** * Encapsulates the concept of a "transaction" as a unit-of-work. @@ -34,15 +35,17 @@ public class UnitOfWork { * Checks to see if the work performed between calling begin and now can be * committed or not. * + * @return a function from which to chain work that only happens when commit is successful * @throws ConflictingUnitOfWorkException * when the work overlaps with other concurrent writers. */ - public void commit() throws ConflictingUnitOfWorkException { + public Function commit() throws ConflictingUnitOfWorkException { // nested.foreach.commit() // log.record(txn::provisionalCommit) // examine log for conflicts in read-set and write-set between begin and // provisional commit // if (conflict) { throw new ConflictingUnitOfWorkException(this) } + return Function.identity(); } /**