1+ @file:Suppress(" ImportOrdering" )
2+
13package io.github.ustudiocompany.uframework.jdbc.transaction
24
35import io.github.airflux.commons.types.maybe.Maybe
@@ -12,28 +14,41 @@ import io.github.ustudiocompany.uframework.jdbc.statement.JDBCNamedPreparedState
1214import io.github.ustudiocompany.uframework.jdbc.statement.JDBCPreparedStatement
1315import io.github.ustudiocompany.uframework.jdbc.statement.JDBCPreparedStatementInstance
1416import io.github.ustudiocompany.uframework.jdbc.statement.JDBCStatement
17+ import io.github.ustudiocompany.uframework.telemetry.logging.logger.slf4jextension.debug
18+ import io.github.ustudiocompany.uframework.telemetry.logging.logger.slf4jextension.error
19+ import io.github.ustudiocompany.uframework.telemetry.logging.logger.slf4jextension.warn
1520import java.sql.Connection
1621import java.sql.PreparedStatement
22+ import org.slf4j.LoggerFactory
1723
1824internal class TransactionInstance (
1925 private val unwrappedConnection : Connection ,
2026) : Transaction, JDBCConnection {
2127
28+ private val logger = LoggerFactory .getLogger(TransactionInstance ::class .java)
29+
2230 override val connection: JDBCConnection
2331 get() = this
2432
2533 override fun commit (): Maybe <JDBCError > = Maybe .catch (
2634 catch = { exception ->
27- JDBCError (description = " Error while committing transaction" , exception = exception)
35+ val errorDescription = " Error while committing transaction."
36+ logger.error { errorDescription }
37+ JDBCError (description = errorDescription, exception = exception)
2838 },
2939 block = { unwrappedConnection.commit() }
3040 )
3141
3242 override fun rollback (): Maybe <JDBCError > = Maybe .catch (
3343 catch = { exception ->
34- JDBCError (description = " Error while rolling back transaction" , exception = exception)
44+ val errorDescription = " Error while rolling back transaction."
45+ logger.error { errorDescription }
46+ JDBCError (description = errorDescription, exception = exception)
3547 },
36- block = { unwrappedConnection.rollback() }
48+ block = {
49+ logger.warn { " Transaction would be rolled back." }
50+ unwrappedConnection.rollback()
51+ }
3752 )
3853
3954 override fun close () {
@@ -48,18 +63,22 @@ internal class TransactionInstance(
4863 override fun preparedStatement (
4964 sql : String ,
5065 timeout : JDBCStatement .Timeout
51- ): JDBCResult <JDBCPreparedStatement > =
52- prepareStatement(sql, timeout)
66+ ): JDBCResult <JDBCPreparedStatement > {
67+ logger.debug { " Executing Query: \n $sql " }
68+ return prepareStatement(sql, timeout)
5369 .map { statement -> JDBCPreparedStatementInstance (statement = statement) }
70+ }
5471
5572 override fun namedPreparedStatement (
5673 sql : ParametrizedSql ,
5774 timeout : JDBCStatement .Timeout
58- ): JDBCResult <JDBCNamedPreparedStatement > =
59- prepareStatement(sql.value, timeout)
75+ ): JDBCResult <JDBCNamedPreparedStatement > {
76+ logger.debug { " Executing ParametrizedSql: \n $sql " }
77+ return prepareStatement(sql.value, timeout)
6078 .map { statement ->
6179 JDBCNamedPreparedStatementInstance (parameters = sql.parameters, statement = statement)
6280 }
81+ }
6382
6483 private fun prepareStatement (
6584 sql : String ,
0 commit comments