diff options
author | Dico200 <dico.karssiens@gmail.com> | 2018-07-22 07:12:53 +0200 |
---|---|---|
committer | Dico200 <dico.karssiens@gmail.com> | 2018-07-22 07:12:53 +0200 |
commit | 9f81a74bd9e89541448bf79d73d0b9bc297e72ee (patch) | |
tree | d32eb5e641bf8f81c172d866fdf05d22018c08ba /src/main/kotlin/io/dico/parcels2/storage/Hikari.kt | |
parent | dbcc90ac8a938e9098dc93206f061cc2a4765ad6 (diff) |
port RedstonerPlots a bit
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/storage/Hikari.kt')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/storage/Hikari.kt | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/storage/Hikari.kt b/src/main/kotlin/io/dico/parcels2/storage/Hikari.kt new file mode 100644 index 0000000..7e4fb7f --- /dev/null +++ b/src/main/kotlin/io/dico/parcels2/storage/Hikari.kt @@ -0,0 +1,51 @@ +package io.dico.parcels2.storage + +import com.zaxxer.hikari.HikariConfig +import com.zaxxer.hikari.HikariDataSource +import io.dico.parcels2.DataConnectionOptions +import javax.sql.DataSource + +fun getHikariDataSource(dialectName: String, + driver: String, + dco: DataConnectionOptions): DataSource = with(HikariConfig()) { + + val (address, port) = dco.splitAddressAndPort() ?: throw IllegalArgumentException("Invalid address: ${dco.address}") + + poolName = "redstonerplots" + maximumPoolSize = dco.poolSize + dataSourceClassName = driver + username = dco.username + password = dco.password + connectionTimeout = 15000 + leakDetectionThreshold = 10000 + connectionTestQuery = "SELECT 1" + + addDataSourceProperty("serverName", address) + addDataSourceProperty("port", port.toString()) + addDataSourceProperty("databaseName", dco.database) + + // copied from github.com/lucko/LuckPerms + if (dialectName.toLowerCase() == "mariadb") { + addDataSourceProperty("properties", "useUnicode=true;characterEncoding=utf8") + } else { + // doesn't exist on the MariaDB driver + addDataSourceProperty("cachePrepStmts", "true") + addDataSourceProperty("alwaysSendSetIsolation", "false") + addDataSourceProperty("cacheServerConfiguration", "true") + addDataSourceProperty("elideSetAutoCommits", "true") + addDataSourceProperty("useLocalSessionState", "true") + + // already set as default on mariadb + addDataSourceProperty("useServerPrepStmts", "true") + addDataSourceProperty("prepStmtCacheSize", "250") + addDataSourceProperty("prepStmtCacheSqlLimit", "2048") + addDataSourceProperty("cacheCallableStmts", "true") + + // make sure unicode characters can be used. + addDataSourceProperty("characterEncoding", "utf8") + addDataSourceProperty("useUnicode", "true") + } + + HikariDataSource(this) + +} |