@Singleton
public class TransactionTemplate
extends java.lang.Object
Usage:
@Inject TransactionTemplate template;
...
template.inTransaction(() -> doSoemStaff())
| Constructor and Description |
|---|
TransactionTemplate(UnitManager manager) |
| Modifier and Type | Method and Description |
|---|---|
<T> T |
inTransaction(TxAction<T> action)
Shortcut for
inTransaction(TxConfig, TxAction) for calling action with default transaction config. |
<T> T |
inTransaction(TxConfig config,
TxAction<T> action)
Wraps provided action with unit of work and transaction.
|
@Inject public TransactionTemplate(UnitManager manager)
public <T> T inTransaction(TxAction<T> action)
inTransaction(TxConfig, TxAction) for calling action with default transaction config.T - return typeaction - action to executepublic <T> T inTransaction(TxConfig config, TxAction<T> action)
NOTE: If unit of work was started manually (using UnitManager, but without transaction started,
then action will be simply executed without starting transaction. This was done for rare situations
when logic must be performed without transaction and transaction annotation will simply indicate unit of work.
T - return typeconfig - transaction configaction - action to execute