Class TransactionHelper
java.lang.Object
com.peterphi.std.guice.hibernate.module.TransactionHelper
Provides transaction helper methods
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCommitAction
(Runnable action) Register an action to run on the successful commit of the transactionvoid
addRollbackAction
(Runnable action) Register an action to run on the rollback of the transactionvoid
deleteOnRollback
(Collection<File> files) Adds an action to the transaction to delete a set of files once rollback completesvoid
Execute the provided Runnable within a transaction, committing if no exceptions are thrown<T> T
Execute the providedCallable
within a transaction, committing if no exceptions are thrown and returning the result of the Callablefinal org.hibernate.Transaction
get()
get the current hibernate transactionstart()
Starts a new Hibernate transaction.
-
Constructor Details
-
TransactionHelper
public TransactionHelper()
-
-
Method Details
-
get
public final org.hibernate.Transaction get()get the current hibernate transaction- Returns:
-
start
Starts a new Hibernate transaction. Note that the caller accepts responsibility for closing the transaction- Returns:
-
execute
Execute the providedCallable
within a transaction, committing if no exceptions are thrown and returning the result of the Callable- Type Parameters:
T
-- Parameters:
statements
-- Returns:
- Throws:
Exception
-
execute
Execute the provided Runnable within a transaction, committing if no exceptions are thrown- Parameters:
statements
-
-
addCommitAction
Register an action to run on the successful commit of the transaction- Parameters:
action
-- Throws:
org.hibernate.HibernateException
-
addRollbackAction
Register an action to run on the rollback of the transaction- Parameters:
action
-- Throws:
org.hibernate.HibernateException
-
deleteOnRollback
Adds an action to the transaction to delete a set of files once rollback completes- Parameters:
files
-
-