Package org.jdbi.v3.core.transaction
Class SerializableTransactionRunner
- java.lang.Object
-
- org.jdbi.v3.core.transaction.DelegatingTransactionHandler
-
- org.jdbi.v3.core.transaction.SerializableTransactionRunner
-
- All Implemented Interfaces:
TransactionHandler
public class SerializableTransactionRunner extends DelegatingTransactionHandler implements TransactionHandler
A TransactionHandler that automatically retries transactions that fail due to serialization failures, which can generally be resolved by automatically retrying the transaction. Any HandleCallback used under this runner should be aware that it may be invoked multiple times and should be idempotent.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSerializableTransactionRunner.ConfigurationConfiguration for serializable transaction runner.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringSQLSTATE_TXN_SERIALIZATION_FAILED
-
Constructor Summary
Constructors Constructor Description SerializableTransactionRunner()SerializableTransactionRunner(TransactionHandler delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R,X extends java.lang.Exception>
RinTransaction(Handle handle, HandleCallback<R,X> callback)Run a transaction.<R,X extends java.lang.Exception>
RinTransaction(Handle handle, TransactionIsolationLevel level, HandleCallback<R,X> callback)Run a transaction.protected booleanisSqlState(java.lang.String expectedSqlState, java.lang.Throwable throwable)Checks whether a given exception is in a specific SQL state.TransactionHandlerspecialize(Handle handle)Bind a TransactionHandler to a Handle, to allow it to track handle-local state.-
Methods inherited from class org.jdbi.v3.core.transaction.DelegatingTransactionHandler
begin, commit, getDelegate, isInTransaction, releaseSavepoint, rollback, rollbackToSavepoint, savepoint
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jdbi.v3.core.transaction.TransactionHandler
begin, commit, isInTransaction, releaseSavepoint, rollback, rollbackToSavepoint, savepoint
-
-
-
-
Field Detail
-
SQLSTATE_TXN_SERIALIZATION_FAILED
private static final java.lang.String SQLSTATE_TXN_SERIALIZATION_FAILED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SerializableTransactionRunner
public SerializableTransactionRunner()
-
SerializableTransactionRunner
public SerializableTransactionRunner(TransactionHandler delegate)
-
-
Method Detail
-
inTransaction
public <R,X extends java.lang.Exception> R inTransaction(Handle handle, HandleCallback<R,X> callback) throws X extends java.lang.Exception
Description copied from interface:TransactionHandlerRun a transaction.- Specified by:
inTransactionin interfaceTransactionHandler- Overrides:
inTransactionin classDelegatingTransactionHandler- Type Parameters:
R- the callback return typeX- the exception type thrown by the callback, if any- Parameters:
handle- the handle to the databasecallback- a callback which will receive the open handle, in a transaction.- Returns:
- the value returned by the callback.
- Throws:
X- any exception thrown by the callback.X extends java.lang.Exception- See Also:
Handle.inTransaction(HandleCallback)
-
inTransaction
public <R,X extends java.lang.Exception> R inTransaction(Handle handle, TransactionIsolationLevel level, HandleCallback<R,X> callback) throws X extends java.lang.Exception
Description copied from interface:TransactionHandlerRun a transaction.- Specified by:
inTransactionin interfaceTransactionHandler- Overrides:
inTransactionin classDelegatingTransactionHandler- Type Parameters:
R- the callback return typeX- the exception type thrown by the callback, if any- Parameters:
handle- the handle to the databaselevel- the isolation level for the transactioncallback- a callback which will receive the open handle, in a transaction.- Returns:
- the value returned by the callback.
- Throws:
X- any exception thrown by the callback.X extends java.lang.Exception- See Also:
Handle.inTransaction(TransactionIsolationLevel, HandleCallback)
-
specialize
public TransactionHandler specialize(Handle handle) throws java.sql.SQLException
Description copied from interface:TransactionHandlerBind a TransactionHandler to a Handle, to allow it to track handle-local state.- Specified by:
specializein interfaceTransactionHandler- Parameters:
handle- the handle to bind to- Returns:
- the bound TransactionHandler
- Throws:
java.sql.SQLException- bad things happened
-
isSqlState
protected boolean isSqlState(java.lang.String expectedSqlState, java.lang.Throwable throwable)Checks whether a given exception is in a specific SQL state.- Parameters:
expectedSqlState- The expected SQL state.throwable- The Throwable to test.- Returns:
- True if Throwable or one of its causes is an SQLException whose SQLState begins with the given state.
-
-