File tree Expand file tree Collapse file tree 2 files changed +24
-10
lines changed
pramen/core/src/main/scala/za/co/absa/pramen/core/rdb Expand file tree Collapse file tree 2 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import za.co.absa.pramen.core.reader.JdbcUrlSelector
2727import za .co .absa .pramen .core .reader .model .JdbcConfig
2828
2929import java .sql .Connection
30+ import scala .util .Try
3031import scala .util .control .NonFatal
3132
3233class PramenDb (val jdbcConfig : JdbcConfig ,
@@ -43,6 +44,11 @@ class PramenDb(val jdbcConfig: JdbcConfig,
4344 def db : Database = slickDb
4445
4546 def setupDatabase (): Unit = {
47+ // Explicitly set auto-commit to true, overriding any user JDBC settings or PostgreSQL defaults
48+ Try (jdbcConnection.setAutoCommit(true )).recover {
49+ case NonFatal (e) => log.warn(s " Unable to set autoCommit=true fdr the bookkeeping database tha uses the driver: ${jdbcConfig.driver}. " )
50+ }
51+
4652 val dbVersion = rdb.getVersion()
4753 if (dbVersion < MODEL_VERSION ) {
4854 initDatabase(dbVersion)
Original file line number Diff line number Diff line change 1616
1717package za .co .absa .pramen .core .rdb
1818
19- import java .sql .Connection
20-
19+ import org .slf4j .LoggerFactory
2120import za .co .absa .pramen .core .rdb .RdbJdbc .dbVersionTableName
2221
22+ import java .sql .{Connection , SQLException }
2323import scala .util .control .NonFatal
2424
2525object RdbJdbc {
2626 val dbVersionTableName = " db_version"
2727}
2828
2929class RdbJdbc (connection : Connection ) extends Rdb {
30+ private val log = LoggerFactory .getLogger(this .getClass)
31+
3032 override def getVersion (): Int = {
3133 getDbVersion()
3234 }
@@ -37,18 +39,24 @@ class RdbJdbc(connection: Connection) extends Rdb{
3739 executeDDL(s " INSERT INTO $dbVersionTableName (version) VALUES (0) " )
3840 }
3941
40- executeDDL(s " UPDATE db_version SET version = $version" )
42+ executeDDL(s " UPDATE $dbVersionTableName SET version = $version" )
4143 }
4244
4345 override def doesTableExists (tableName : String ): Boolean = {
4446 val meta = connection.getMetaData
45- val res = meta.getTables(null , null , tableName, Array [String ](" TABLE" ))
46- if (res.next) {
47- res.close()
48- true
49- } else {
50- res.close()
51- false
47+ try {
48+ val res = meta.getTables(null , null , tableName, Array [String ](" TABLE" ))
49+ if (res.next) {
50+ res.close()
51+ true
52+ } else {
53+ res.close()
54+ false
55+ }
56+ } catch {
57+ case ex : SQLException =>
58+ log.warn(s " Error while checking existence of $tableName. " , ex)
59+ false
5260 }
5361 }
5462
You can’t perform that action at this time.
0 commit comments