Package org.jdbi.v3.core.transaction
Interface TransactionHandler
- All Known Implementing Classes:
CMTTransactionHandler
,DelegatingTransactionHandler
,LocalTransactionHandler
,RollbackOnlyTransactionHandler
,SerializableTransactionRunner
public interface TransactionHandler
Interface which defines callbacks to be used when transaction methods are called on a handle.
Used by specifying on a
Jdbi
instance. All Handle
instances
opened from that Jdbi
will use the handler specified.
The default implementation, LocalTransactionHandler
, explicitly manages
the transactions on the underlying JDBC Connection
.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Begin a transaction.void
Commit the transaction.<R,
X extends Exception>
RinTransaction
(Handle handle, HandleCallback<R, X> callback) Run a transaction.<R,
X extends Exception>
RinTransaction
(Handle handle, TransactionIsolationLevel level, HandleCallback<R, X> callback) Run a transaction.boolean
isInTransaction
(Handle handle) Returns whether a given Handle is in the transaction.void
releaseSavepoint
(Handle handle, String savepointName) Release a previously created savepoint.void
Roll back the transaction.void
rollbackToSavepoint
(Handle handle, String savepointName) Roll back to a named savepoint.void
Create a new savepoint.default TransactionHandler
specialize
(Handle handle) Bind a TransactionHandler to a Handle, to allow it to track handle-local state.
-
Method Details
-
begin
Begin a transaction.- Parameters:
handle
- the handle the transaction is being started on
-
commit
Commit the transaction.- Parameters:
handle
- the handle the commit is being performed on
-
rollback
Roll back the transaction.- Parameters:
handle
- the handle the rollback is being performed on
-
isInTransaction
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
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
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
Release a previously created savepoint.- Parameters:
handle
- the handle on which the savepoint is being releasedsavepointName
- the savepoint to release
-
inTransaction
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.- See Also:
-
inTransaction
<R,X extends Exception> R inTransaction(Handle handle, TransactionIsolationLevel level, HandleCallback<R, X> callback) throws XRun 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.- See Also:
-
specialize
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:
SQLException
- bad things happened
-