mirror of
https://github.com/BlockWorldGroup/Ledger-Databases.git
synced 2025-08-17 11:39:43 +08:00
Redo things
This commit is contained in:
parent
8b925fabf9
commit
7bbc2ab8ab
11
build.gradle
11
build.gradle
@ -19,9 +19,6 @@ repositories {
|
||||
maven {
|
||||
url = "https://oss.sonatype.org/content/repositories/snapshots"
|
||||
}
|
||||
maven {
|
||||
url = "https://maven.bymartrixx.me/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@ -34,20 +31,20 @@ dependencies {
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
// Yes this has to be capitalised
|
||||
modImplementation "com.github.quiltservertools:Ledger:1.3.0"
|
||||
modImplementation "com.github.quiltservertools:Ledger:1.3.0+local"
|
||||
|
||||
modImplementation "net.fabricmc:fabric-language-kotlin:1.9.4+kotlin.1.8.21"
|
||||
|
||||
implementation("com.zaxxer:HikariCP:5.0.1")
|
||||
|
||||
// H2
|
||||
implementation(include("com.h2database:h2:1.4.200"))
|
||||
implementation(include("com.h2database:h2:2.2.224"))
|
||||
|
||||
// MySQL
|
||||
implementation(include('mysql:mysql-connector-java:8.0.19'))
|
||||
implementation(include('mysql:mysql-connector-java:8.3.0'))
|
||||
|
||||
// PostgreSQL
|
||||
implementation(include("org.postgresql:postgresql:42.3.0"))
|
||||
implementation(include("org.postgresql:postgresql:42.7.3"))
|
||||
}
|
||||
|
||||
processResources {
|
||||
|
@ -1,50 +0,0 @@
|
||||
package net.quiltservertools.ledger.databases
|
||||
|
||||
import com.github.quiltservertools.ledger.Ledger
|
||||
import com.github.quiltservertools.ledger.api.DatabaseExtension
|
||||
import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import net.minecraft.util.Identifier
|
||||
import org.h2.jdbcx.JdbcDataSource
|
||||
import org.sqlite.SQLiteDataSource
|
||||
import java.nio.file.Path
|
||||
import javax.sql.DataSource
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
class LedgerDatabaseExtension : DatabaseExtension {
|
||||
override fun getConfigSpecs(): List<ConfigSpec> = listOf(DatabaseExtensionSpec)
|
||||
|
||||
override fun getDataSource(fileLocation: Path): DataSource {
|
||||
return when (Ledger.config[DatabaseExtensionSpec.database]) {
|
||||
Databases.SQLITE -> SQLiteDataSource().apply {
|
||||
url = "jdbc:sqlite:${fileLocation.resolve("ledger.sqlite").pathString}"
|
||||
}
|
||||
|
||||
Databases.H2 -> JdbcDataSource().apply {
|
||||
setURL("jdbc:h2:${fileLocation.resolve("ledger.h2").pathString};MODE=MySQL")
|
||||
}
|
||||
|
||||
Databases.MYSQL -> HikariDataSource(HikariConfig().apply {
|
||||
jdbcUrl = "jdbc:mysql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true"
|
||||
username = Ledger.config[DatabaseExtensionSpec.userName]
|
||||
password = Ledger.config[DatabaseExtensionSpec.password]
|
||||
maximumPoolSize = Ledger.config[DatabaseExtensionSpec.maxPoolSize]
|
||||
})
|
||||
|
||||
Databases.POSTGRESQL -> HikariDataSource(HikariConfig().apply {
|
||||
jdbcUrl = "jdbc:postgresql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true"
|
||||
username = Ledger.config[DatabaseExtensionSpec.userName]
|
||||
password = Ledger.config[DatabaseExtensionSpec.password]
|
||||
maximumPoolSize = Ledger.config[DatabaseExtensionSpec.maxPoolSize]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override fun getIdentifier(): Identifier = when (Ledger.config[DatabaseExtensionSpec.database]) {
|
||||
Databases.MYSQL -> Ledger.identifier("mysql_extension")
|
||||
Databases.H2 -> Ledger.identifier("h2_extension")
|
||||
Databases.POSTGRESQL -> Ledger.identifier("postgresql_extension")
|
||||
else -> Ledger.identifier(Ledger.DEFAULT_DATABASE)
|
||||
}
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
package net.quiltservertools.ledger.databases
|
||||
|
||||
import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
|
||||
import com.uchuhimo.konf.ConfigSpec
|
||||
|
||||
object DatabaseExtensionSpec : ConfigSpec("database_extensions") {
|
||||
val database by optional(Databases.SQLITE, "database")
|
||||
val database by required<Databases>("database")
|
||||
val userName by optional("root", "username")
|
||||
val password by optional("", "password")
|
||||
val url by optional("localhost", "url")
|
||||
val properties by optional(mapOf<String, String>(), "properties")
|
||||
val maxPoolSize by optional(10, "maxPoolSize")
|
||||
val connectionTimeout by optional(60000L, "connectionTimeout")
|
||||
}
|
@ -1,10 +1,15 @@
|
||||
package net.quiltservertools.ledger.databases
|
||||
|
||||
import net.quiltservertools.ledger.databases.databases.*
|
||||
import net.quiltservertools.ledger.databases.databases.H2Database
|
||||
import net.quiltservertools.ledger.databases.databases.LedgerDatabase
|
||||
import net.quiltservertools.ledger.databases.databases.MySQL
|
||||
import net.quiltservertools.ledger.databases.databases.PostgreSQL
|
||||
import net.quiltservertools.ledger.databases.databases.SQLite
|
||||
|
||||
|
||||
enum class Databases(val database: LedgerDatabase) {
|
||||
SQLITE(SQLite),
|
||||
MYSQL(MySQL),
|
||||
H2(H2Database),
|
||||
POSTGRESQL(PostgreSQL)
|
||||
POSTGRESQL(PostgreSQL),
|
||||
SQLITE(SQLite)
|
||||
}
|
@ -2,17 +2,18 @@ package net.quiltservertools.ledger.databases
|
||||
|
||||
import com.github.quiltservertools.ledger.Ledger
|
||||
import com.github.quiltservertools.ledger.api.DatabaseExtension
|
||||
import com.github.quiltservertools.libs.com.uchuhimo.konf.ConfigSpec
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import com.uchuhimo.konf.ConfigSpec
|
||||
import net.minecraft.util.Identifier
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import java.nio.file.Path
|
||||
import javax.sql.DataSource
|
||||
|
||||
class LedgerDatabaseExtension : DatabaseExtension {
|
||||
override fun getConfigSpecs(): List<ConfigSpec> = listOf(DatabaseExtensionSpec)
|
||||
|
||||
override fun getDatabase(server: MinecraftServer): Database {
|
||||
return Ledger.config[DatabaseExtensionSpec.database].database.getDatabase(server)
|
||||
override fun getDataSource(savePath: Path): DataSource {
|
||||
return Ledger.config[DatabaseExtensionSpec.database].database.getDataSource(savePath)
|
||||
}
|
||||
|
||||
override fun getIdentifier(): Identifier = Ledger.config[DatabaseExtensionSpec.database].database.getDatabaseIdentifier()
|
||||
override fun getIdentifier(): Identifier =
|
||||
Ledger.config[DatabaseExtensionSpec.database].database.getDatabaseIdentifier()
|
||||
}
|
||||
|
@ -2,9 +2,15 @@ package net.quiltservertools.ledger.databases
|
||||
|
||||
import com.github.quiltservertools.ledger.api.ExtensionManager
|
||||
import net.fabricmc.api.DedicatedServerModInitializer
|
||||
import net.minecraft.util.Identifier
|
||||
|
||||
const val MOD_ID = "ledger-databases"
|
||||
|
||||
object LedgerDatabases : DedicatedServerModInitializer {
|
||||
|
||||
class LedgerDatabases : DedicatedServerModInitializer {
|
||||
override fun onInitializeServer() {
|
||||
ExtensionManager.registerExtension(LedgerDatabaseExtension())
|
||||
}
|
||||
|
||||
fun identifier(path: String) = Identifier(MOD_ID, path)
|
||||
}
|
@ -1,14 +1,15 @@
|
||||
package net.quiltservertools.ledger.databases.databases
|
||||
|
||||
import com.github.quiltservertools.ledger.Ledger
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.util.WorldSavePath
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import net.quiltservertools.ledger.databases.LedgerDatabases
|
||||
import org.h2.jdbcx.JdbcDataSource
|
||||
import java.nio.file.Path
|
||||
import javax.sql.DataSource
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
object H2Database : LedgerDatabase {
|
||||
override fun getDatabase(server: MinecraftServer) = Database.connect(
|
||||
url = "jdbc:h2:${server.getSavePath(WorldSavePath.ROOT).resolve("ledger.h2").toFile()};MODE=MySQL"
|
||||
)
|
||||
|
||||
override fun getDatabaseIdentifier() = Ledger.identifier("h2")
|
||||
override fun getDataSource(savePath: Path): DataSource = JdbcDataSource().apply {
|
||||
setURL("jdbc:h2:${savePath.pathString};MODE=MySQL")
|
||||
}
|
||||
|
||||
override fun getDatabaseIdentifier() = LedgerDatabases.identifier("h2")
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.quiltservertools.ledger.databases.databases
|
||||
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.util.Identifier
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import java.nio.file.Path
|
||||
import javax.sql.DataSource
|
||||
|
||||
interface LedgerDatabase {
|
||||
fun getDatabase(server: MinecraftServer): Database
|
||||
fun getDataSource(savePath: Path): DataSource
|
||||
fun getDatabaseIdentifier(): Identifier
|
||||
}
|
@ -1,22 +1,35 @@
|
||||
package net.quiltservertools.ledger.databases.databases
|
||||
|
||||
import com.github.quiltservertools.ledger.Ledger
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import net.quiltservertools.ledger.databases.DatabaseExtensionSpec
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import net.quiltservertools.ledger.databases.LedgerDatabases
|
||||
import java.nio.file.Path
|
||||
import javax.sql.DataSource
|
||||
|
||||
object MySQL : LedgerDatabase {
|
||||
override fun getDatabase(server: MinecraftServer): Database {
|
||||
var url = "jdbc:mysql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true"
|
||||
for (arg in Ledger.config[DatabaseExtensionSpec.properties]) {
|
||||
url = url.plus("&$arg")
|
||||
}
|
||||
return Database.connect(
|
||||
url = url,
|
||||
user = Ledger.config[DatabaseExtensionSpec.userName],
|
||||
override fun getDataSource(savePath: Path): DataSource = HikariDataSource(HikariConfig().apply {
|
||||
jdbcUrl = "jdbc:mysql://${Ledger.config[DatabaseExtensionSpec.url]}"
|
||||
username = Ledger.config[DatabaseExtensionSpec.userName]
|
||||
password = Ledger.config[DatabaseExtensionSpec.password]
|
||||
)
|
||||
maximumPoolSize = Ledger.config[DatabaseExtensionSpec.maxPoolSize]
|
||||
connectionTimeout = Ledger.config[DatabaseExtensionSpec.connectionTimeout]
|
||||
addDataSourceProperty("rewriteBatchedStatements", "true")
|
||||
addDataSourceProperty("cachePrepStmts", true)
|
||||
addDataSourceProperty("prepStmtCacheSize", 250)
|
||||
addDataSourceProperty("prepStmtCacheSqlLimit", 2048)
|
||||
addDataSourceProperty("useServerPrepStmts", true)
|
||||
addDataSourceProperty("cacheCallableStmts", true)
|
||||
addDataSourceProperty("cacheResultSetMetadata", true)
|
||||
addDataSourceProperty("cacheServerConfiguration", true)
|
||||
addDataSourceProperty("useLocalSessionState", true)
|
||||
addDataSourceProperty("elideSetAutoCommits", true)
|
||||
addDataSourceProperty("alwaysSendSetIsolation", false)
|
||||
for ((key, value) in Ledger.config[DatabaseExtensionSpec.properties]) {
|
||||
addDataSourceProperty(key, value)
|
||||
}
|
||||
})
|
||||
|
||||
override fun getDatabaseIdentifier() = Ledger.identifier("mysql")
|
||||
override fun getDatabaseIdentifier() = LedgerDatabases.identifier("mysql")
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
package net.quiltservertools.ledger.databases.databases
|
||||
|
||||
import com.github.quiltservertools.ledger.Ledger
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import net.quiltservertools.ledger.databases.DatabaseExtensionSpec
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import net.quiltservertools.ledger.databases.LedgerDatabases
|
||||
import java.nio.file.Path
|
||||
import javax.sql.DataSource
|
||||
|
||||
object PostgreSQL : LedgerDatabase {
|
||||
override fun getDatabase(server: MinecraftServer): Database {
|
||||
var url = "jdbc:postgresql://${Ledger.config[DatabaseExtensionSpec.url]}?rewriteBatchedStatements=true"
|
||||
for (arg in Ledger.config[DatabaseExtensionSpec.properties]) {
|
||||
url = url.plus("&$arg")
|
||||
}
|
||||
return Database.connect(
|
||||
url = url,
|
||||
user = Ledger.config[DatabaseExtensionSpec.userName],
|
||||
override fun getDataSource(savePath: Path): DataSource = HikariDataSource(HikariConfig().apply {
|
||||
jdbcUrl = "jdbc:postgresql://${Ledger.config[DatabaseExtensionSpec.url]}"
|
||||
username = Ledger.config[DatabaseExtensionSpec.userName]
|
||||
password = Ledger.config[DatabaseExtensionSpec.password]
|
||||
)
|
||||
maximumPoolSize = Ledger.config[DatabaseExtensionSpec.maxPoolSize]
|
||||
for ((key, value) in Ledger.config[DatabaseExtensionSpec.properties]) {
|
||||
addDataSourceProperty(key, value)
|
||||
}
|
||||
})
|
||||
|
||||
override fun getDatabaseIdentifier() = Ledger.identifier("postgresql")
|
||||
override fun getDatabaseIdentifier() = LedgerDatabases.identifier("postgresql")
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
package net.quiltservertools.ledger.databases.databases
|
||||
|
||||
import com.github.quiltservertools.ledger.Ledger
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.util.WorldSavePath
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
import kotlin.io.path.pathString
|
||||
import org.sqlite.SQLiteDataSource
|
||||
import java.nio.file.Path
|
||||
|
||||
object SQLite : LedgerDatabase {
|
||||
override fun getDatabase(server: MinecraftServer) = Database.connect(
|
||||
url = "jdbc:sqlite:${server.getSavePath(WorldSavePath.ROOT).resolve("ledger.sqlite").pathString}"
|
||||
)
|
||||
override fun getDataSource(savePath: Path) = SQLiteDataSource().apply {
|
||||
url = "jdbc:sqlite:$savePath"
|
||||
}
|
||||
|
||||
override fun getDatabaseIdentifier() = Ledger.identifier(Ledger.DEFAULT_DATABASE)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user