https://kotlinlang.org logo
#exposed
Title
# exposed
r

rikusen0335

11/27/2019, 2:20 PM
Is there an way to set and use member(class?) variavles for db in class method like:
Copy code
var db: Database

    override fun onEnable() {
        // Enabled message
        server.consoleSender.sendMessage("%sSamplePlugin is now enabled!".format(ChatColor.GREEN))
        server.pluginManager.registerEvents(this, this)

        val basePath: Path = Paths.get(System.getProperty("user.dir")).toRealPath()
        val sqliteFile: Path = Paths.get(basePath.toString(), "sample.db")
        print(sqliteFile) // Show the paths
        db = Database.connect("jdbc:sqlite:file:$sqliteFile", "org.sqlite.JDBC")

        TransactionManager.manager.defaultIsolationLevel = Connection.TRANSACTION_SERIALIZABLE
    }

    override fun onDisable() {
        TransactionManager.closeAndUnregister(db) // Disconnect処理?
    }
e

Evan R.

11/27/2019, 2:26 PM
Yeah, Database.connect() returns a database connection object which you can then pass as a parameter to
newTransaction()
. It’s all detailed here: https://github.com/JetBrains/Exposed/wiki/DataBase-and-DataSource and here: https://github.com/JetBrains/Exposed/wiki/Transactions#working-with-a-multiple-databases
👍 1
2 Views