useTransaction

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

Execute the specific callback function in a transaction 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.

Return

the result of the callback function.

Parameters

isolation

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

func

the executed callback function.