English | 简体中文

api-docs / org.ktorm.global / useTransaction

useTransaction

inline fun <T> useTransaction(
    isolation: TransactionIsolation? = null,
    func: (Transaction) -> T
): T
(source code)

Deprecated: ktorm-global will be removed in the future, please migrate to the standard API.

Execute the specific callback function in a transaction of Database.Companion.global and returns its result if the
execution succeeds, otherwise, if the execution fails, the transaction will be rollback.

Note:

  • Any exceptions thrown in the callback function can trigger a rollback.
  • This function is reentrant, so it can be called nested. However, the inner calls don’t open new transactions
    but share the same ones with outers.
  • Since version 3.3.0, the default isolation has changed to null (stands for the default isolation level of the
    underlying datastore), not TransactionIsolation.REPEATABLE_READ anymore.

Parameters

isolation - transaction isolation, null for the default isolation level of the underlying datastore.

func - the executed callback function.

Return
the result of the callback function.

See Also

Database.useTransaction