override fun doBegin()

in spring-transaction/src/main/kotlin/org/jetbrains/exposed/v1/spring/transaction/SpringTransactionManager.kt [103:152]


    override fun doBegin(transaction: Any, definition: TransactionDefinition) {
        val trxObject = transaction as ExposedTransactionObject

        // If the current transaction in the stack is null (because it was suspended),
        // or if it belongs to a different database, then we should not use it as outer transaction
        @OptIn(InternalApi::class)
        val currentTransaction = currentTransactionOrNull() as JdbcTransaction?
        val outerTransactionToUse = if (currentTransaction?.db == database) {
            currentTransaction
        } else {
            null
        }

        // exposed transaction
        val newTransaction = trxObject.database.transactionManager.newTransaction(
            isolation = definition.isolationLevel,
            readOnly = definition.isReadOnly,
            outerTransaction = outerTransactionToUse
        ).apply {
            if (definition.timeout != TransactionDefinition.TIMEOUT_DEFAULT) {
                queryTimeout = definition.timeout
            }

            if (showSql) {
                addLogger(StdOutSqlLogger)
            }
        }

        // Spring JDBC transaction
        @Suppress("TooGenericExceptionCaught")
        try {
            if (trxObject.connectionHolder == null) {
                trxObject.connectionHolder = ConnectionHolder(ExposedConnectionHandle(newTransaction))
                trxObject.isNewConnectionHolder = true
            }

            trxObject.connectionHolder?.isSynchronizedWithTransaction = true

            // Bind the connection holder to the thread.
            if (trxObject.isNewConnectionHolder) {
                TransactionSynchronizationManager.bindResource(dataSource, trxObject.connectionHolder!!)
            }
        } catch (ex: Throwable) {
            trxObject.connectionHolder = null
            throw CannotCreateTransactionException("Could not open JDBC Connection for transaction", ex)
        }

        @OptIn(InternalApi::class)
        ThreadLocalTransactionsStack.pushTransaction(newTransaction)
    }