Package org.jdbi.v3.core.transaction
Interface TransactionHandler
-
- All Known Implementing Classes:
CMTTransactionHandler,DelegatingTransactionHandler,LocalTransactionHandler,LocalTransactionHandler.BindingLocalTransactionHandler,LocalTransactionHandler.BoundLocalTransactionHandler,RollbackOnlyTransactionHandler,SerializableTransactionRunner
public interface TransactionHandlerInterface which defines callbacks to be used when transaction methods are called on a handle. Used by specifying on aJdbiinstance. AllHandleinstances opened from thatJdbiwill use the handler specified.The default implementation,
LocalTransactionHandler, explicitly manages the transactions on the underlying JDBCConnection.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidbegin(Handle handle)Begin a transaction.voidcommit(Handle handle)Commit the transaction.<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.booleanisInTransaction(Handle handle)Returns whether a given Handle is in the transaction.voidreleaseSavepoint(Handle handle, java.lang.String savepointName)Release a previously created savepoint.voidrollback(Handle handle)Roll back the transaction.voidrollbackToSavepoint(Handle handle, java.lang.String savepointName)Roll back to a named savepoint.voidsavepoint(Handle handle, java.lang.String savepointName)Create a new savepoint.default TransactionHandlerspecialize(Handle handle)Bind a TransactionHandler to a Handle, to allow it to track handle-local state.
-
-
-
Method Detail
-
begin
void begin(Handle handle)
Begin a transaction.- Parameters:
handle- the handle the transaction is being started on
-
commit
void commit(Handle handle)
Commit the transaction.- Parameters:
handle- the handle the commit is being performed on
-
rollback
void rollback(Handle handle)
Roll back the transaction.- Parameters:
handle- the handle the rollback is being performed on
-
isInTransaction
boolean isInTransaction(Handle handle)
Returns whether a given Handle is in the transaction.- Parameters:
handle- the handle to test- Returns:
- whether the given handle is in a transaction
-
savepoint
void savepoint(Handle handle, java.lang.String savepointName)
Create a new savepoint.- Parameters:
handle- the handle on which the transaction is being savepointedsavepointName- The name of the savepoint, used to rollback to or release later
-
rollbackToSavepoint
void rollbackToSavepoint(Handle handle, java.lang.String savepointName)
Roll back to a named savepoint.- Parameters:
handle- the handle the rollback is being performed onsavepointName- the name of the savepoint to rollback to
-
releaseSavepoint
void releaseSavepoint(Handle handle, java.lang.String savepointName)
Release a previously created savepoint.- Parameters:
handle- the handle on which the savepoint is being releasedsavepointName- the savepoint to release
-
inTransaction
<R,X extends java.lang.Exception> R inTransaction(Handle handle, HandleCallback<R,X> callback) throws X extends java.lang.Exception
Run a transaction.- 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
<R,X extends java.lang.Exception> R inTransaction(Handle handle, TransactionIsolationLevel level, HandleCallback<R,X> callback) throws X extends java.lang.Exception
Run a transaction.- 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
default TransactionHandler specialize(Handle handle) throws java.sql.SQLException
Bind a TransactionHandler to a Handle, to allow it to track handle-local state.- Parameters:
handle- the handle to bind to- Returns:
- the bound TransactionHandler
- Throws:
java.sql.SQLException- bad things happened
-
-