Class TransactionHelper

java.lang.Object
com.peterphi.std.guice.hibernate.module.TransactionHelper

public class TransactionHelper extends Object
Provides transaction helper methods
  • Constructor Details

    • TransactionHelper

      public TransactionHelper()
  • Method Details

    • get

      public final org.hibernate.Transaction get()
      get the current hibernate transaction
      Returns:
    • start

      public HibernateTransaction start()
      Starts a new Hibernate transaction. Note that the caller accepts responsibility for closing the transaction
      Returns:
    • execute

      public <T> T execute(Callable<T> statements) throws Exception
      Execute the provided Callable 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

      public void execute(Runnable statements)
      Execute the provided Runnable within a transaction, committing if no exceptions are thrown
      Parameters:
      statements -
    • addCommitAction

      public void addCommitAction(Runnable action) throws org.hibernate.HibernateException
      Register an action to run on the successful commit of the transaction
      Parameters:
      action -
      Throws:
      org.hibernate.HibernateException
    • addRollbackAction

      public void addRollbackAction(Runnable action) throws org.hibernate.HibernateException
      Register an action to run on the rollback of the transaction
      Parameters:
      action -
      Throws:
      org.hibernate.HibernateException
    • deleteOnRollback

      public void deleteOnRollback(Collection<File> files)
      Adds an action to the transaction to delete a set of files once rollback completes
      Parameters:
      files -