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 aUnitOfWork
-
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.LoggerunitOfWorkLog
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Optional<UOW>getCurrentUnitOfWork()Get the currently activeUnitOfWorkUOWgetOrCreateNewUnitOfWork()Get the currently activeUnitOfWorkor create a newUnitOfWorkif one is missingUOWgetRequiredUnitOfWork()Get 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()
-
-
-
Method Detail
-
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
-
usingUnitOfWork
default void usingUnitOfWork(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()- Parameters:
action- the action that's performed in aUnitOfWork
-
withUnitOfWork
default <R> R withUnitOfWork(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()- Type Parameters:
R- the return type from the action- Parameters:
action- the action that's performed in aUnitOfWork- Returns:
- the result of running the action in a
UnitOfWork
-
usingUnitOfWork
default void usingUnitOfWork(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.- Parameters:
unitOfWorkConsumer- the consumer that's called with aUnitOfWork
-
withUnitOfWork
default <R> R withUnitOfWork(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.- Parameters:
unitOfWorkFunction- the consumer that's called with aUnitOfWork
-
getCurrentUnitOfWork
Optional<UOW> getCurrentUnitOfWork()
Get the currently activeUnitOfWork- Returns:
- the currently active
UnitOfWorkwrapped in anOptionalorOptional.empty()in case there isn't a currently activeUnitOfWork
-
-