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 Details

    • 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, String savepointName)
      Create a new savepoint.
      Parameters:
      handle - the handle on which the transaction is being savepointed
      savepointName - The name of the savepoint, used to rollback to or release later
    • rollbackToSavepoint

      void rollbackToSavepoint(Handle handle, String savepointName)
      Roll back to a named savepoint.
      Parameters:
      handle - the handle the rollback is being performed on
      savepointName - the name of the savepoint to rollback to
    • releaseSavepoint

      void releaseSavepoint(Handle handle, String savepointName)
      Release a previously created savepoint.
      Parameters:
      handle - the handle on which the savepoint is being released
      savepointName - the savepoint to release
    • inTransaction

      <R, X extends Exception> R inTransaction(Handle handle, HandleCallback<R,X> callback) throws X
      Run a transaction.
      Type Parameters:
      R - the callback return type
      X - the exception type thrown by the callback, if any
      Parameters:
      handle - the handle to the database
      callback - 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 X
      Run a transaction.
      Type Parameters:
      R - the callback return type
      X - the exception type thrown by the callback, if any
      Parameters:
      handle - the handle to the database
      level - the isolation level for the transaction
      callback - 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

      default TransactionHandler specialize(Handle handle) throws 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:
      SQLException - bad things happened