Interface Transactional<This extends Transactional<This>>

Type Parameters:
This - must match the interface that is extending the Transactional interface.
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-demand Transactional instances. Handle throws TransactionException if closed while a transaction is open. Since on-demand extensions open and close a handle around each method invocation, calling begin() on an on-demand Transactional will always leave a transaction open, and thus always throw this exception.

Users of on-demand Transactional instances should use the inTransaction and useTransaction methods to execute transactions. It is safe to call other Transactional methods from inside these callbacks.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Begins a transaction.
    default void
    Commits the open transaction.
    default <R, X extends Exception>
    R
    inTransaction(org.jdbi.v3.core.transaction.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>
    R
    Executes the given callback within a transaction, returning the value returned by the callback.
    default boolean
    Returns True if this object is currently in a transaction.
    default void
    releaseSavepoint(String savepointName)
    Releases the given savepoint.
    default void
    Rolls back the open transaction.
    default void
    rollbackToSavepoint(String savepointName)
    Rolls back to the given savepoint.
    default void
    savepoint(String savepointName)
    Creates a savepoint with the given name on the transaction.
    default <X extends Exception>
    void
    useTransaction(org.jdbi.v3.core.transaction.TransactionIsolationLevel isolation, TransactionalConsumer<This,X> callback)
    Executes the given callback within a transaction.
    default <X extends Exception>
    void
    Executes the given callback within a transaction.

    Methods inherited from interface SqlObject

    getHandle, useHandle, withHandle
    Modifier and Type
    Method
    Description
    org.jdbi.v3.core.Handle
    Returns the handle used in the current sql object context.
    default <X extends Exception>
    void
    useHandle(org.jdbi.v3.core.HandleConsumer<X> consumer)
    A convenience function which manages the lifecycle of the handle associated to this sql object, and yields it to a consumer for use by clients.
    <R, X extends Exception>
    R
    withHandle(org.jdbi.v3.core.HandleCallback<R,X> callback)
    A convenience function which manages the lifecycle of the handle associated to this sql object, and yields it to a callback for use by clients.
  • Method Details

    • begin

      default void begin()
      Begins a transaction.
      Throws:
      org.jdbi.v3.core.transaction.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.
    • isInTransaction

      default boolean isInTransaction()
      Returns True if this object is currently in a transaction.
      Returns:
      True if the object is in a 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
      Executes the given callback within a transaction, returning the value returned by the callback.
      Type Parameters:
      R - method return type
      X - 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.
    • inTransaction

      default <R, X extends Exception> R inTransaction(org.jdbi.v3.core.transaction.TransactionIsolationLevel isolation, TransactionalCallback<R,This,X> callback) throws X
      Executes the given callback within a transaction, returning the value returned by the callback.
      Type Parameters:
      R - method return type
      X - 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.
    • useTransaction

      default <X extends Exception> void useTransaction(TransactionalConsumer<This,X> callback) throws X
      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.
    • useTransaction

      default <X extends Exception> void useTransaction(org.jdbi.v3.core.transaction.TransactionIsolationLevel isolation, TransactionalConsumer<This,X> callback) throws X
      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.