package com.correx.infrastructure.persistence.util

import java.sql.Connection

object JDBCHelper {
    inline fun <T> Connection.transaction(block: () -> T): T {
        val oldAutoCommit = autoCommit
        try {
            autoCommit = false

            val result = block()

            commit()
            return result
        } catch (e: Throwable) {
            rollback()
            throw e
        } finally {
            autoCommit = oldAutoCommit
        }
    }
}
