Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch/remove buffer of open dbfile #63

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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