DefaultJdbcTransactionProvider

Default implementation of JdbcTransactionProvider using ThreadLocal to manage transactions. This implementation does not depend on any external transaction managers (like Spring).

It supports:

  • Nested transactions via Savepoints.

  • Propagation (REQUIRED, REQUIRES_NEW).

  • Automatic restoration of connection state (isolation level, read-only) after transaction completion.

  • Transaction timeouts via PostgreSQL 'statement_timeout'.

Constructors

Link copied to clipboard
constructor(dataSource: DataSource)

Properties

Link copied to clipboard
open override val dataSource: DataSource

The underlying data source used for obtaining connections.

Functions

Link copied to clipboard
open override fun applyTimeout(statement: Statement)

Applies the current transaction timeout to the given statement.

Link copied to clipboard
open override fun <T> execute(propagation: TransactionPropagation, isolation: IsolationLevel, readOnly: Boolean, timeoutSeconds: Int?, block: (TransactionStatus) -> T): T

Executes a block of code within a transaction context.

Link copied to clipboard
open override fun getConnection(): Connection

Obtains a connection for the current execution context. If a transaction is active, returns the connection bound to that transaction. Otherwise, returns a new connection from the dataSource.

Link copied to clipboard
open override fun releaseConnection(connection: Connection)

Releases the given connection. If the connection is part of an active transaction, it is NOT closed. Otherwise, it is returned to the pool (closed).