Package ru.vyarus.guicey.jdbi.tx
Class TransactionTemplate
- java.lang.Object
-
- ru.vyarus.guicey.jdbi.tx.TransactionTemplate
-
@Singleton public class TransactionTemplate extends java.lang.ObjectTransaction 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:
- 4.12.2016
-
-
Constructor Summary
Constructors Constructor Description TransactionTemplate(UnitManager manager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TinTransaction(TxAction<T> action)Wraps provided action with unit of work and transaction.
-
-
-
Constructor Detail
-
TransactionTemplate
@Inject public TransactionTemplate(UnitManager manager)
-
-
Method Detail
-
inTransaction
public <T> T inTransaction(TxAction<T> action)
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:
action- action to execute- Returns:
- action result
-
-