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 Details

    • 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.
    • 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(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(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.