app.cash.sqldelight.dialects.sqlite_3_18.SqliteConnectionManager.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sqlite-3-18-dialect Show documentation
Show all versions of sqlite-3-18-dialect Show documentation
The SQLite v3.18 Dialect for SQLDelight
The newest version!
package app.cash.sqldelight.dialects.sqlite_3_18
import app.cash.sqldelight.dialect.api.ConnectionManager
import app.cash.sqldelight.dialect.api.ConnectionManager.ConnectionProperties
import com.intellij.openapi.project.Project
import java.sql.Connection
import java.sql.DriverManager
import java.sql.SQLException
class SqliteConnectionManager : ConnectionManager {
override fun createNewConnectionProperties(
project: Project,
prefilledProperties: ConnectionProperties?,
): ConnectionProperties? {
val dialog = SelectConnectionTypeDialog(project)
if (!dialog.showAndGet()) return null
return dialog.connectionProperties()
}
override fun getConnection(connectionProperties: ConnectionProperties): Connection {
val path = connectionProperties.serializedProperties
val previousContextLoader = Thread.currentThread().contextClassLoader
return try {
// When it iterates the ServiceLoader we want to make sure its on the plugins classpath.
Thread.currentThread().contextClassLoader = this::class.java.classLoader
DriverManager.getConnection("jdbc:sqlite:$path")
} catch (e: SQLException) {
DriverManager.getConnection("jdbc:sqlite:$path")
} finally {
Thread.currentThread().contextClassLoader = previousContextLoader
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy