Transaction

Class representing a unit block of work that is performed on a database.

Constructors

Link copied to clipboard
constructor(transactionImpl: TransactionInterface)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val connection: ExposedConnection<*>

The database connection used by the transaction.

Link copied to clipboard

The currently executing statement.

Link copied to clipboard
override val db: Database

The database on which the transaction tasks are performed.

Link copied to clipboard

Whether tracked values like statementCount and duration should be stored in statementStats for debugging.

Link copied to clipboard

The current total amount of time, in milliseconds, spent executing statements in this transaction.

Link copied to clipboard
val id: String

The unique ID for this transaction.

Link copied to clipboard

The maximum amount of attempts that will be made to perform this transaction block.

Link copied to clipboard
Link copied to clipboard

The maximum number of milliseconds to wait before retrying this transaction if an SQLException happens.

Link copied to clipboard
Link copied to clipboard

The minimum number of milliseconds to wait before retrying this transaction if an SQLException happens.

Link copied to clipboard
open override val outerTransaction: Transaction?

The parent transaction of a nested transaction; otherwise, null if the transaction is a top-level instance.

Link copied to clipboard

The number of seconds the JDBC driver should wait for a statement to execute in Transaction transaction before timing out. Note Not all JDBC drivers implement this limit. Please check the driver documentation.

Link copied to clipboard
open override val readOnly: Boolean

Whether the transaction is in read-only mode.

Link copied to clipboard
Link copied to clipboard

The current number of statements executed in this transaction.

Link copied to clipboard

A StringBuilder containing string representations of previously executed statements prefixed by their execution time in milliseconds.

Link copied to clipboard

A mapping of previously executed statements in this transaction, with a string representation of the prepared statement as the key and the statement count to execution time as the value.

Link copied to clipboard
open override val transactionIsolation: Int

The transaction isolation level of the transaction, which may differ from the set database level.

Link copied to clipboard

The threshold in milliseconds for query execution to exceed before logging a warning.

Functions

Link copied to clipboard

Adds one or more SqlLoggers to this transaction.

Link copied to clipboard
open override fun close()

Closes the transaction and releases any savepoints.

Link copied to clipboard

Closes all previously executed statements and resets or releases any used database and/or driver resources.

Link copied to clipboard
open override fun commit()

Saves all changes since the last commit or rollback operation.

Link copied to clipboard
fun <T> exec(stmt: Statement<T>): T?

Executes the provided Statement object and returns the generated value.

fun <T, R> exec(stmt: Statement<T>, body: Statement<T>.(T) -> R): R?

Executes the provided Statement object, retrieves the generated value, then calls the specified function body with this generated value as its argument and returns its result.

fun exec(stmt: String, args: Iterable<Pair<IColumnType<*>, Any?>> = emptyList(), explicitStatementType: StatementType? = null): Unit?
fun <T : Any> exec(stmt: String, args: Iterable<Pair<IColumnType<*>, Any?>> = emptyList(), explicitStatementType: StatementType? = null, transform: (ResultSet) -> T?): T?

Executes the provided statement exactly, using the supplied args to set values to question mark placeholders (if applicable).

Link copied to clipboard
fun execInBatch(stmts: List<String>)

Provided statements will be executed in a batch. Select statements are not supported as it's impossible to return multiple results.

Link copied to clipboard
fun Transaction.explain(analyze: Boolean = false, options: String? = null, body: Transaction.() -> Any?): ExplainQuery

Creates an ExplainQuery using the EXPLAIN keyword, which obtains information about a statement execution plan.

Link copied to clipboard
fun fullIdentity(column: Column<*>): String

Returns the complete string identifier of a column, based on its Table.tableName and Column.name.

Link copied to clipboard
fun <T : Any> getOrCreate(key: Key<T>, init: () -> T): T

Returns the value for the specified key. If the key is not found, the init function is called, then its result is mapped to the key and returned.

Link copied to clipboard
fun <T : Any> getUserData(key: Key<T>): T?

Returns the value to which the specified key is mapped, as a value of type T.

Link copied to clipboard
fun identity(column: Column<*>): String

Returns the string identifier of a column, based on its Column.name.

fun identity(table: Table): String

Returns the string identifier of a table, based on its Table.tableName and Table.alias, if applicable.

Link copied to clipboard
fun <T : Any> putUserData(key: Key<T>, value: T)

Maps the specified key to the specified value.

Link copied to clipboard

Adds the specified StatementInterceptor to act on this transaction.

Link copied to clipboard
fun <T : Any> removeUserData(key: Key<T>): Any?

Removes the specified key and its corresponding value.

Link copied to clipboard
open override fun rollback()

Reverts all changes since the last commit or rollback operation, or to the last set savepoint, if applicable.

Link copied to clipboard

Removes the specified StatementInterceptor from acting on this transaction.

Link copied to clipboard
fun <T> Transaction.withDataBaseLock(body: () -> T)

Creates table with name "busy" (if not present) and single column to be used as "synchronization" point. Table wont be dropped after execution.

Link copied to clipboard
suspend fun <T> Transaction.withSuspendTransaction(context: CoroutineContext? = null, statement: suspend Transaction.() -> T): T

Calls the specified suspending statement, suspends until it completes, and returns the result.