Support mariadb
This commit is contained in:
@@ -5,6 +5,7 @@ import org.jetbrains.kotlin.gradle.dsl.Coroutines.ENABLE
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
import java.io.PrintWriter
|
import java.io.PrintWriter
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
val stdout = PrintWriter("gradle-output.txt")
|
val stdout = PrintWriter("gradle-output.txt")
|
||||||
|
|
||||||
@@ -124,6 +125,17 @@ tasks {
|
|||||||
manifest.attributes["Class-Path"] = "../lib/kotlin-stdlib.jar"
|
manifest.attributes["Class-Path"] = "../lib/kotlin-stdlib.jar"
|
||||||
dependsOn(kotlinStdlibJar)
|
dependsOn(kotlinStdlibJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val createDebugServer by creating {
|
||||||
|
|
||||||
|
val jarUrl = URL("https://yivesmirror.com/files/spigot/spigot-latest.jar")
|
||||||
|
val serverJarFile = file("$serverDir/lib/spigot.jar")
|
||||||
|
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import kotlinx.coroutines.experimental.channels.ProducerScope
|
|||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.SchemaUtils.create
|
import org.jetbrains.exposed.sql.SchemaUtils.create
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import org.jetbrains.exposed.sql.vendors.DatabaseDialect
|
||||||
import org.joda.time.DateTime
|
import org.joda.time.DateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.sql.DataSource
|
import javax.sql.DataSource
|
||||||
@@ -62,6 +63,14 @@ class ExposedBacking(private val dataSourceFactory: () -> DataSource) : Backing
|
|||||||
|
|
||||||
override val isConnected get() = database != null
|
override val isConnected get() = database != null
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
init {
|
||||||
|
Database.registerDialect("mariadb") {
|
||||||
|
Class.forName("org.jetbrains.exposed.sql.vendors.MysqlDialect").newInstance() as DatabaseDialect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun init() {
|
override suspend fun init() {
|
||||||
if (isShutdown) throw IllegalStateException()
|
if (isShutdown) throw IllegalStateException()
|
||||||
dataSource = dataSourceFactory()
|
dataSource = dataSourceFactory()
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package io.dico.parcels2.storage
|
package io.dico.parcels2.storage
|
||||||
|
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.Column
|
||||||
|
import org.jetbrains.exposed.sql.Index
|
||||||
|
import org.jetbrains.exposed.sql.Table
|
||||||
|
import org.jetbrains.exposed.sql.Transaction
|
||||||
import org.jetbrains.exposed.sql.statements.InsertStatement
|
import org.jetbrains.exposed.sql.statements.InsertStatement
|
||||||
import org.jetbrains.exposed.sql.statements.UpdateStatement
|
|
||||||
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
import org.jetbrains.exposed.sql.transactions.TransactionManager
|
||||||
|
|
||||||
class UpsertStatement<Key : Any>(table: Table, conflictColumn: Column<*>? = null, conflictIndex: Index? = null)
|
class UpsertStatement<Key : Any>(table: Table, conflictColumn: Column<*>? = null, conflictIndex: Index? = null)
|
||||||
@@ -26,12 +28,23 @@ class UpsertStatement<Key : Any>(table: Table, conflictColumn: Column<*>? = null
|
|||||||
|
|
||||||
override fun prepareSQL(transaction: Transaction) = buildString {
|
override fun prepareSQL(transaction: Transaction) = buildString {
|
||||||
append(super.prepareSQL(transaction))
|
append(super.prepareSQL(transaction))
|
||||||
append(" ON CONFLICT(")
|
|
||||||
append(indexName)
|
|
||||||
append(") DO UPDATE SET ")
|
|
||||||
|
|
||||||
values.keys.filter { it !in indexColumns}.joinTo(this) { "${transaction.identity(it)}=EXCLUDED.${transaction.identity(it)}" }
|
val dialect = transaction.db.vendor
|
||||||
}.also { println(it) }
|
if (dialect == "postgresql") {
|
||||||
|
|
||||||
|
append(" ON CONFLICT(")
|
||||||
|
append(indexName)
|
||||||
|
append(") DO UPDATE SET ")
|
||||||
|
|
||||||
|
values.keys.filter { it !in indexColumns }.joinTo(this) { "${transaction.identity(it)}=EXCLUDED.${transaction.identity(it)}" }
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
append (" ON DUPLICATE KEY UPDATE ")
|
||||||
|
values.keys.filter { it !in indexColumns }.joinTo(this) { "${transaction.identity(it)}=VALUES(${transaction.identity(it)})" }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,15 @@ fun getHikariConfig(dialectName: String,
|
|||||||
dataSourceProperties["portNumber"] = port.toString()
|
dataSourceProperties["portNumber"] = port.toString()
|
||||||
dataSourceProperties["databaseName"] = dco.database
|
dataSourceProperties["databaseName"] = dco.database
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"mariadb" -> run {
|
||||||
|
dataSourceClassName = "org.mariadb.jdbc.MariaDbDataSource"
|
||||||
|
dataSourceProperties["serverName"] = address
|
||||||
|
dataSourceProperties["port"] = port.toString()
|
||||||
|
dataSourceProperties["databaseName"] = dco.database
|
||||||
|
dataSourceProperties["properties"] = "useUnicode=true;characterEncoding=utf8"
|
||||||
|
}
|
||||||
|
|
||||||
else -> throw IllegalArgumentException("Unsupported dialect: $dialectName")
|
else -> throw IllegalArgumentException("Unsupported dialect: $dialectName")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ interface StorageFactory {
|
|||||||
|
|
||||||
class ConnectionStorageFactory : StorageFactory {
|
class ConnectionStorageFactory : StorageFactory {
|
||||||
override val optionsClass = DataConnectionOptions::class
|
override val optionsClass = DataConnectionOptions::class
|
||||||
private val types: List<String> = listOf("postgresql")
|
private val types: List<String> = listOf("postgresql", "mariadb")
|
||||||
|
|
||||||
fun register(companion: StorageFactory.StorageFactories) {
|
fun register(companion: StorageFactory.StorageFactories) {
|
||||||
types.forEach { companion.registerFactory(it, this) }
|
types.forEach { companion.registerFactory(it, this) }
|
||||||
|
|||||||
Reference in New Issue
Block a user