public abstract class CurrentUnitOfWork extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
clear(UnitOfWork<?> unitOfWork)
Clears the UnitOfWork currently bound to the current thread, if that UnitOfWork is the given
unitOfWork. |
static void |
commit()
Commits the current UnitOfWork.
|
static MetaData |
correlationData()
Returns the Correlation Data attached to the current Unit of Work, or an empty
MetaData instance
if no Unit of Work is started. |
static UnitOfWork<?> |
get()
Gets the UnitOfWork bound to the current thread.
|
static boolean |
ifStarted(Consumer<UnitOfWork<?>> consumer)
If a UnitOfWork is started, invokes the given
consumer with the active Unit of Work. |
static boolean |
isStarted()
Indicates whether a unit of work has already been started.
|
static <T> Optional<T> |
map(Function<UnitOfWork<?>,T> function)
If a Unit of Work is started, execute the given
function on it. |
static void |
set(UnitOfWork<?> unitOfWork)
Binds the given
unitOfWork to the current thread. |
public static boolean isStarted()
public static boolean ifStarted(Consumer<UnitOfWork<?>> consumer)
consumer with the active Unit of Work. Otherwise,
it does nothingconsumer - The consumer to invoke if a Unit of Work is activetrue if a unit of work is active, false otherwisepublic static <T> Optional<T> map(Function<UnitOfWork<?>,T> function)
function on it. Otherwise, returns an empty Optional.
Use this method when you wish to retrieve information from a Unit of Work, reverting to a default when no Unit
of Work is started.T - The type of return value expectedfunction - The function to apply to the unit of work, if presentNullPointerException - when a Unit of Work is present and the function returns nullpublic static UnitOfWork<?> get()
IllegalStateException is thrown.
To verify whether a UnitOfWork is already active, use isStarted().IllegalStateException - if no UnitOfWork is activepublic static void commit()
IllegalStateException is thrown.IllegalStateException - if no UnitOfWork is currently started.UnitOfWork.commit()public static void set(UnitOfWork<?> unitOfWork)
unitOfWork to the current thread. If other UnitOfWork instances were bound, they
will be marked as inactive until the given UnitOfWork is cleared.unitOfWork - The UnitOfWork to bind to the current thread.public static void clear(UnitOfWork<?> unitOfWork)
unitOfWork.unitOfWork - The UnitOfWork expected to be bound to the current thread.IllegalStateException - when the given UnitOfWork was not the current active UnitOfWork. This exception
indicates a potentially wrong nesting of Units Of Work.public static MetaData correlationData()
MetaData instance
if no Unit of Work is started.UnitOfWork.getCorrelationData()Copyright © 2010–2018. All rights reserved.