Package ru.vyarus.guicey.jdbi3.tx
Class TransactionTemplate
java.lang.Object
ru.vyarus.guicey.jdbi3.tx.TransactionTemplate
Transaction template used to both declare unit of work and start transaction.
If called inside of transaction then provided action will be simply executed as transaction is already managed
somewhere outside. In case of exception, it's propagated and transaction rolled back.
Usage:
@Inject TransactionTemplate template;
...
template.inTransaction(() -> doSoemStaff())
- Since:
- 31.08.2018
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TinTransaction(TxAction<T> action) Shortcut forinTransaction(TxConfig, TxAction)for calling action with default transaction config.<T> TinTransaction(TxConfig config, TxAction<T> action) Wraps provided action with unit of work and transaction.
-
Constructor Details
-
TransactionTemplate
-
-
Method Details
-
inTransaction
Shortcut forinTransaction(TxConfig, TxAction)for calling action with default transaction config.- Type Parameters:
T- return type- Parameters:
action- action to execute- Returns:
- action result
-
inTransaction
Wraps provided action with unit of work and transaction. If called under already started transaction then action will be called directly.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.- Type Parameters:
T- return type- Parameters:
config- transaction configaction- action to execute- Returns:
- action result
-