Class TransactionHelper
java.lang.Object
me.confuser.banmanager.common.util.TransactionHelper
Utility class for handling database transactions.
Wraps ORMLite's TransactionManager for consistent transaction handling across storage classes.
Includes automatic retry logic for InnoDB deadlocks.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for runnables that may throw SQLException. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TcallInTransaction(me.confuser.banmanager.common.ormlite.support.ConnectionSource connectionSource, Callable<T> callable) Executes the given callable within a database transaction with deadlock retry logic.static voidrunInTransaction(me.confuser.banmanager.common.ormlite.support.ConnectionSource connectionSource, TransactionHelper.TransactionRunnable runnable) Executes the given runnable within a database transaction with deadlock retry logic.
-
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 transactioncallable- 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 transactionrunnable- the runnable to execute within the transaction- Throws:
SQLException- if a database error occurs after all retries are exhausted
-