All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dbobjekts.util.StatementLogger.kt Maven / Gradle / Ivy

There is a newer version: 0.6.0-RC2
Show newest version
package com.dbobjekts.util

import com.dbobjekts.api.AnySqlParameter
import com.dbobjekts.api.ExecutedStatementInfo

open class StatementLogger {

    private val cache = mutableListOf()

    private var lastSQLStatement: String? = null
    private var lastParameters: List = listOf()

    //returns immutable list
    fun transactionExecutionLog(): List = cache.toList()

    fun lastStatement(): String? = lastSQLStatement

    internal fun logStatement(
        sql: String,
        parameters: List
    ) {
        lastSQLStatement = sql
        lastParameters = parameters
    }

    internal fun logResult(result: Any?) {
        //should in fact never be null when we log a result
        if (lastSQLStatement != null) {
            cache += ExecutedStatementInfo(lastSQLStatement ?: "NIL", lastParameters, result)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy