Class TransactionHelper

java.lang.Object
me.confuser.banmanager.common.util.TransactionHelper

public class TransactionHelper extends Object
Utility class for handling database transactions. Wraps ORMLite's TransactionManager for consistent transaction handling across storage classes. Includes automatic retry logic for InnoDB deadlocks.
  • Constructor Details

    • TransactionHelper

      public TransactionHelper()
  • Method Details

    • callInTransaction

      public static <T> T callInTransaction(me.confuser.banmanager.common.ormlite.support.ConnectionSource connectionSource, Callable<T> callable) throws SQLException
      Executes the given callable within a database transaction with deadlock retry logic. If a deadlock or lock wait timeout occurs, the operation will be retried up to MAX_RETRIES times. If the callable throws a non-deadlock exception, the transaction will be rolled back immediately. If the callable completes successfully, the transaction will be committed.
      Type Parameters:
      T - the return type of the callable
      Parameters:
      connectionSource - the connection source to use for the transaction
      callable - the callable to execute within the transaction
      Returns:
      the result of the callable
      Throws:
      SQLException - if a database error occurs after all retries are exhausted
    • runInTransaction

      public static void runInTransaction(me.confuser.banmanager.common.ormlite.support.ConnectionSource connectionSource, TransactionHelper.TransactionRunnable runnable) throws SQLException
      Executes the given runnable within a database transaction with deadlock retry logic. If a deadlock or lock wait timeout occurs, the operation will be retried up to MAX_RETRIES times. If the runnable throws a non-deadlock exception, the transaction will be rolled back immediately. If the runnable completes successfully, the transaction will be committed.
      Parameters:
      connectionSource - the connection source to use for the transaction
      runnable - the runnable to execute within the transaction
      Throws:
      SQLException - if a database error occurs after all retries are exhausted