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:
parent
7497cf5a18
commit
c42803b964
2 changed files with 12 additions and 5 deletions
|
@ -151,12 +151,16 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void commit() throws ConflictingUnitOfWorkException {
|
||||
public synchronized Function<Void, Void> commit() throws ConflictingUnitOfWorkException {
|
||||
final Function<Void, Void> f = Function.<Void>identity();
|
||||
synchronized(currentUnitOfWork) {
|
||||
if (currentUnitOfWork != null) {
|
||||
currentUnitOfWork.commit();
|
||||
currentUnitOfWork.commit().andThen((it) -> { return f; });
|
||||
currentUnitOfWork = null;
|
||||
}
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
public synchronized void abort() {
|
||||
if (currentUnitOfWork != null) {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue