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