Return a Function on successful UnitOfWork.commit() so as to allow users to execute code post-commit iff that commit was successful.

This commit is contained in:
Greg Burd 2017-08-04 09:26:58 -04:00
parent 7497cf5a18
commit c42803b964
2 changed files with 12 additions and 5 deletions

View file

@ -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<Void, Void> commit() throws ConflictingUnitOfWorkException {
final Function<Void, Void> f = Function.<Void>identity();
synchronized(currentUnitOfWork) {
if (currentUnitOfWork != null) {
currentUnitOfWork.commit().andThen((it) -> { return f; });
currentUnitOfWork = null;
}
}
return f;
}
public synchronized void abort() {

View file

@ -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<Void, Void> 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.<Void>identity();
}
/**