Class TransactionHelper
java.lang.Object
com.peterphi.std.guice.hibernate.module.TransactionHelper
Provides transaction helper methods
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCommitAction(Runnable action) Register an action to run on the successful commit of the transactionvoidaddRollbackAction(Runnable action) Register an action to run on the rollback of the transactionvoiddeleteOnRollback(Collection<File> files) Adds an action to the transaction to delete a set of files once rollback completesvoidExecute the provided Runnable within a transaction, committing if no exceptions are thrown<T> TExecute the providedCallablewithin a transaction, committing if no exceptions are thrown and returning the result of the Callablefinal org.hibernate.Transactionget()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 providedCallablewithin 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-
-