Skip to content

Commit

Permalink
Merge pull request #63 from smeup/patch/remove_buffer_of_open_dbfile
Browse files Browse the repository at this point in the history
Patch/remove buffer of open dbfile
  • Loading branch information
foresti-smeup committed Dec 18, 2023
2 parents 413e10a + 7e2f2f4 commit 0ca8750
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 463 deletions.
33 changes: 15 additions & 18 deletions sql/src/main/kotlin/com/smeup/dbnative/sql/SQLDBMManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ import java.sql.DriverManager
import java.util.*
import kotlin.system.measureTimeMillis

open class SQLDBMManager(override val connectionConfig: ConnectionConfig) : DBManagerBaseImpl() {
open class SQLDBMManager(override val connectionConfig: ConnectionConfig) : DBManagerBaseImpl() {

private var sqlLog: Boolean = false

private var openedFile = mutableMapOf<String, SQLDBFile>()
//private var openedFile = mutableMapOf<String, SQLDBFile>()

val connection : Connection by lazy {
val connection: Connection by lazy {
logger?.logEvent(LoggingKey.connection, "Opening SQL connection on url ${connectionConfig.url}")
val conn: Connection
measureTimeMillis {
connectionConfig.driver?.let {
Class.forName(connectionConfig.driver)
}

val connectionProps = Properties();
connectionProps.put("user", connectionConfig.user);
connectionProps.put("password", connectionConfig.password);
val connectionProps = Properties()
connectionProps["user"] = connectionConfig.user
connectionProps["password"] = connectionConfig.password

connectionConfig.properties.forEach() {
if (!it.key.equals("user") && !it.key.equals("password")) {
connectionProps.put(it.key, it.value);
connectionConfig.properties.forEach {
if (it.key != "user" && it.key != "password") {
connectionProps[it.key] = it.value
}
}
conn = DriverManager.getConnection(connectionConfig.url, connectionProps)
Expand All @@ -59,21 +59,18 @@ open class SQLDBMManager(override val connectionConfig: ConnectionConfig) : DBMa
}

override fun close() {
openedFile.values.forEach { it.close()}
openedFile.clear()
//openedFile.values.forEach { it.close()}
//openedFile.clear()
connection.close()
}

override fun openFile(name: String) = openedFile.getOrPut(name) {
require(existFile(name)) {
"Cannot open a unregistered file $name"
}
SQLDBFile(name = name, fileMetadata = metadataOf(name), connection = connection, logger)
override fun openFile(name: String): SQLDBFile {
require(this.existFile(name))
return SQLDBFile(name = name, fileMetadata = metadataOf(name), connection = connection, logger)
}


override fun closeFile(name: String) {
openedFile.remove(name)?.close()
//openedFile.remove(name)?.close()
}

fun execute(sqlStatements: List<String>) {
Expand Down
Loading

0 comments on commit 0ca8750

Please sign in to comment.