# Transaction

abstract class Transaction : UserDataHolder, TransactionInterface

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

## Constructors

Transaction
Link copied to clipboard
constructor()

## Properties

db
Link copied to clipboard
abstract val db: DatabaseApi

The database on which the transaction tasks are performed.

debug
Link copied to clipboard
var debug: Boolean

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

duration
Link copied to clipboard
var duration: Long

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

id
Link copied to clipboard
val id: String

The unique ID for this transaction.

outerTransaction
Link copied to clipboard
abstract val outerTransaction: Transaction?

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

queryTimeout
Link copied to clipboard
var queryTimeout: Int?

The number of seconds the driver should wait for a statement to execute in a transaction before timing out. Note that not all drivers implement this limit. For more information, refer to the relevant driver documentation.

readOnly
Link copied to clipboard
abstract val readOnly: Boolean

Whether the transaction is in read-only mode.

statementCount
Link copied to clipboard
var statementCount: Int

The current number of statements executed in this transaction.

statements
Link copied to clipboard
val statements: StringBuilder

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

statementStats
Link copied to clipboard
val statementStats: HashMap<String, Pair<Int, Long>>

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.

transactionId
Link copied to clipboard
val transactionId: String

The unique ID for this transaction.

transactionManager
Link copied to clipboard
abstract val transactionManager: TransactionManagerApi

The transaction manager that manages this transaction instance.

warnLongQueriesDuration
Link copied to clipboard
var warnLongQueriesDuration: Long?

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

## Functions

addLogger
Link copied to clipboard
open fun addLogger(vararg logger: SqlLogger): CompositeSqlLogger

Adds one or more SqlLoggers to this Transaction.

fullIdentity
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.

getOrCreate
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.

getUserData
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.

identity
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.

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

Maps the specified key to the specified value.

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

Removes the specified key and its corresponding value.