Interface Transactional<This extends Transactional<This>>
-
- Type Parameters:
This- must match the interface that is extending this one.
- All Superinterfaces:
SqlObject
public interface Transactional<This extends Transactional<This>> extends SqlObject
A mixin interface to expose transaction methods on the sql object.Use caution with
on-demandTransactionalinstances.HandlethrowsTransactionExceptionif closed while a transaction is open. Since on-demand extensions open and close a handle around each method invocation, callingbegin()on an on-demandTransactionalwill always leave a transaction open, and thus always throw this exception.Users of on-demand
Transactionalinstances should use theinTransactionanduseTransactionmethods to execute transactions. It is safe to call otherTransactionalmethods from inside these callbacks.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default voidbegin()Begins a transaction.default voidcommit()Commits the open transaction.default <R,X extends Exception>
RinTransaction(TransactionIsolationLevel isolation, TransactionalCallback<R,This,X> callback)Executes the given callback within a transaction, returning the value returned by the callback.default <R,X extends Exception>
RinTransaction(TransactionalCallback<R,This,X> callback)Executes the given callback within a transaction, returning the value returned by the callback.default voidreleaseSavepoint(String savepointName)Releases the given savepoint.default voidrollback()Rolls back the open transaction.default voidrollbackToSavepoint(String savepointName)Rolls back to the given savepoint.default voidsavepoint(String savepointName)Creates a savepoint with the given name on the transaction.default <X extends Exception>
voiduseTransaction(TransactionIsolationLevel isolation, TransactionalConsumer<This,X> callback)Executes the given callback within a transaction.default <X extends Exception>
voiduseTransaction(TransactionalConsumer<This,X> callback)Executes the given callback within a transaction.-
Methods inherited from interface org.jdbi.v3.sqlobject.SqlObject
getHandle, useHandle, withHandle
-
-
-
-
Method Detail
-
begin
default void begin()
Begins a transaction.- Throws:
TransactionException- if called on an on-demand Transactional instance.
-
commit
default void commit()
Commits the open transaction.
-
rollback
default void rollback()
Rolls back the open transaction.
-
savepoint
default void savepoint(String savepointName)
Creates a savepoint with the given name on the transaction.- Parameters:
savepointName- the savepoint name.
-
rollbackToSavepoint
default void rollbackToSavepoint(String savepointName)
Rolls back to the given savepoint.- Parameters:
savepointName- the savepoint name.
-
releaseSavepoint
default void releaseSavepoint(String savepointName)
Releases the given savepoint.- Parameters:
savepointName- the savepoint name.
-
inTransaction
default <R,X extends Exception> R inTransaction(TransactionalCallback<R,This,X> callback) throws X extends Exception
Executes the given callback within a transaction, returning the value returned by the callback.- Type Parameters:
R- method return typeX- exception optionally thrown by the callback.- Parameters:
callback- the callback to execute- Returns:
- the value returned by the callback.
- Throws:
X- any exception thrown by the callback.X extends Exception
-
inTransaction
default <R,X extends Exception> R inTransaction(TransactionIsolationLevel isolation, TransactionalCallback<R,This,X> callback) throws X extends Exception
Executes the given callback within a transaction, returning the value returned by the callback.- Type Parameters:
R- method return typeX- exception optionally thrown by the callback.- Parameters:
isolation- the transaction isolation level.callback- the callback to execute- Returns:
- the value returned by the callback.
- Throws:
X- any exception thrown by the callback.X extends Exception
-
useTransaction
default <X extends Exception> void useTransaction(TransactionalConsumer<This,X> callback) throws X extends Exception
Executes the given callback within a transaction.- Type Parameters:
X- exception optionally thrown by the callback.- Parameters:
callback- the callback to execute- Throws:
X- any exception thrown by the callback.X extends Exception
-
useTransaction
default <X extends Exception> void useTransaction(TransactionIsolationLevel isolation, TransactionalConsumer<This,X> callback) throws X extends Exception
Executes the given callback within a transaction.- Type Parameters:
X- exception optionally thrown by the callback.- Parameters:
isolation- the transaction isolation level.callback- the callback to execute- Throws:
X- any exception thrown by the callback.X extends Exception
-
-