withTransaction

open fun <R, E : Exception?> withTransaction(@NotNull transactionFunction: @NotNull TransactionFunction<R, E>): R(source)

Acquires a database connection, runs the function, commits the changes and closes the connection.

If all connections are used, this function blocks until a connection is available.

If getDumpLongTransactions is enabled, a coroutine dump (if available) and a thread dump will be done if the transaction is longer than the threshold.

Supports nesting, but it is not recommended doing so, avoid nesting by returning the data as soon as possible.

Parameters

transactionFunction

The function to run with the connection

See also


open fun <R, E : Exception?> withTransaction(readOnly: Boolean, @NotNull transactionFunction: @NotNull TransactionFunction<R, E>): R(source)

Acquires a database connection, runs the function, commits the changes and closes the connection.

If all connections are used, this function blocks until a connection is available.

If getDumpLongTransactions is enabled, a coroutine dump (if available) and a thread dump will be done if the transaction is longer than the threshold.

Supports nesting, but it is not recommended doing so, avoid nesting by returning the data as soon as possible.

Parameters

readOnly

true if the database only is read from, can allow some optimizations but does not prevent writing

transactionFunction

The function to run with the connection

See also