Interface UnitOfWorkFactory<UOW extends UnitOfWork>
- Type Parameters:
UOW- theUnitOfWorksub-type returned by theUnitOfWorkFactory
- All Known Subinterfaces:
HandleAwareUnitOfWorkFactory<UOW>
- All Known Implementing Classes:
GenericHandleAwareUnitOfWorkFactory,JdbiUnitOfWorkFactory,SpringMongoTransactionAwareUnitOfWorkFactory,SpringTransactionAwareJdbiUnitOfWorkFactory,SpringTransactionAwareUnitOfWorkFactory
public interface UnitOfWorkFactory<UOW extends UnitOfWork>
This interface creates a
UnitOfWork-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionGet the currently activeUnitOfWorkGet the currently activeUnitOfWorkor create a newUnitOfWorkif one is missingGet a required activeUnitOfWorkdefault voidusingUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedConsumer<UOW> unitOfWorkConsumer) Run theunitOfWorkConsumerin aUnitOfWork
It works in two different ways:
1.
If no existingUnitOfWorkthen a newUnitOfWorkis created and started, theunitOfWorkConsumeris called with thisUnitOfWork
When theunitOfWorkConsumerhas completed, without throwing an exception, then the createdUnitOfWorkis committed.
In case an exception was thrown then the createdUnitOfWorkis rolledback.
2.
If there's already an existingUnitOfWorkthen theunitOfWorkConsumerjoins in with existingUnitOfWorkand theunitOfWorkConsumeris called with the existingUnitOfWork
When theunitOfWorkConsumerhas completed, without throwing an exception, then the existingUnitOfWorkis NOT committed, this is instead left to the original creator of theUnitOfWorkto do
In case an exception was thrown then the existingUnitOfWorkis marked as rollback only.default voidusingUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedRunnable action) Works just likeusingUnitOfWork(CheckedConsumer)except the action isn't provided an instance of theUnitOfWork
The code in the action can always access theUnitOfWorkby callinggetRequiredUnitOfWork()default <R> RwithUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedFunction<UOW, R> unitOfWorkFunction) Run theunitOfWorkFunctionin aUnitOfWork
It works in two different ways:
1.
If no existingUnitOfWorkthen a newUnitOfWorkis created and started, theunitOfWorkFunctionis called with thisUnitOfWork
When theunitOfWorkFunctionhas completed, without throwing an exception, then the createdUnitOfWorkis committed.
In case an exception was thrown then the createdUnitOfWorkis rolledback.
2.
If there's already an existingUnitOfWorkthen theunitOfWorkFunctionjoins in with existingUnitOfWorkand theunitOfWorkFunctionis called with the existingUnitOfWork
When theunitOfWorkFunctionhas completed, without throwing an exception, then the existingUnitOfWorkis NOT committed, this is instead left to the original creator of theUnitOfWorkto do
In case an exception was thrown then the existingUnitOfWorkis marked as rollback only.default <R> RwithUnitOfWork(dk.cloudcreate.essentials.shared.functional.CheckedSupplier<R> action) Works just likewithUnitOfWork(CheckedFunction)except the action isn't provided an instance of theUnitOfWork
The code in the action can always access theUnitOfWorkby callinggetRequiredUnitOfWork()
-
Field Details
-
unitOfWorkLog
static final org.slf4j.Logger unitOfWorkLog
-
-
Method Details
-
getRequiredUnitOfWork
UOW getRequiredUnitOfWork()Get a required activeUnitOfWork- Returns:
- the active
UnitOfWork - Throws:
NoActiveUnitOfWorkException- if the is no activeUnitOfWork
-
getOrCreateNewUnitOfWork
UOW getOrCreateNewUnitOfWork()Get the currently activeUnitOfWorkor create a newUnitOfWorkif one is missing- Returns:
- a
UnitOfWork
-
getCurrentUnitOfWork
Get the currently activeUnitOfWork- Returns:
- the currently active
UnitOfWorkwrapped in anOptionalorOptional.empty()in case there isn't a currently activeUnitOfWork
-