|
| 1 | +package net.quiltservertools.ledger.databases.databases |
| 2 | + |
| 3 | +import com.github.quiltservertools.ledger.Ledger |
| 4 | +import com.zaxxer.hikari.HikariConfig |
| 5 | +import com.zaxxer.hikari.HikariDataSource |
| 6 | +import net.quiltservertools.ledger.databases.DatabaseExtensionSpec |
| 7 | +import net.quiltservertools.ledger.databases.LedgerDatabases |
| 8 | +import java.nio.file.Path |
| 9 | +import javax.sql.DataSource |
| 10 | + |
| 11 | +object MariaDB : LedgerDatabase { |
| 12 | + override fun getDataSource(savePath: Path): DataSource = HikariDataSource(HikariConfig().apply { |
| 13 | + jdbcUrl = "jdbc:mariadb://${Ledger.config[DatabaseExtensionSpec.url]}" |
| 14 | + username = Ledger.config[DatabaseExtensionSpec.userName] |
| 15 | + password = Ledger.config[DatabaseExtensionSpec.password] |
| 16 | + maximumPoolSize = Ledger.config[DatabaseExtensionSpec.maxPoolSize] |
| 17 | + connectionTimeout = Ledger.config[DatabaseExtensionSpec.connectionTimeout] |
| 18 | + addDataSourceProperty("rewriteBatchedStatements", "true") |
| 19 | + addDataSourceProperty("cachePrepStmts", true) |
| 20 | + addDataSourceProperty("prepStmtCacheSize", 250) |
| 21 | + addDataSourceProperty("prepStmtCacheSqlLimit", 2048) |
| 22 | + addDataSourceProperty("useServerPrepStmts", true) |
| 23 | + addDataSourceProperty("cacheCallableStmts", true) |
| 24 | + addDataSourceProperty("cacheResultSetMetadata", true) |
| 25 | + addDataSourceProperty("cacheServerConfiguration", true) |
| 26 | + addDataSourceProperty("useLocalSessionState", true) |
| 27 | + addDataSourceProperty("elideSetAutoCommits", true) |
| 28 | + addDataSourceProperty("alwaysSendSetIsolation", false) |
| 29 | + addDataSourceProperty("useJDBCCompliantTimezoneShift", true) |
| 30 | + addDataSourceProperty("useLegacyDatetimeCode", false) |
| 31 | + addDataSourceProperty("serverTimezone", "UTC") |
| 32 | + for ((key, value) in Ledger.config[DatabaseExtensionSpec.properties]) { |
| 33 | + addDataSourceProperty(key, value) |
| 34 | + } |
| 35 | + }) |
| 36 | + |
| 37 | + override fun getDatabaseIdentifier() = LedgerDatabases.identifier("mariadb") |
| 38 | +} |
0 commit comments