diff --git a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java index 5e968199..fbe7fa8e 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/shared/FastLoginCore.java @@ -230,8 +230,6 @@ public class FastLoginCore
> { } HikariConfig databaseConfig = new HikariConfig(); - databaseConfig.setDriverClassName(driver); - String database = config.getString("database"); databaseConfig.setConnectionTimeout(config.getInt("timeout", 30) * 1_000L); diff --git a/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java index 2bbae0b4..868f7fbe 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/storage/MySQLStorage.java @@ -30,23 +30,18 @@ import com.zaxxer.hikari.HikariConfig; public class MySQLStorage extends SQLStorage { + private static final String JDBC_PROTOCOL = "jdbc:"; + public MySQLStorage(FastLoginCore, ?, ?> core, String driver, String host, int port, String database, HikariConfig config, boolean useSSL) { - super(core, - buildJDBCUrl(driver, host, port, database), - setParams(config, useSSL)); + super(core, setParams(config, driver, host, port, database, useSSL)); } - private static String buildJDBCUrl(String driver, String host, int port, String database) { - String protocol = "mysql"; - if (driver.contains("mariadb")) { - protocol = "mariadb"; - } + private static HikariConfig setParams(HikariConfig config, + String driver, String host, int port, String database, + boolean useSSL) { + config.setDriverClassName(driver); - return protocol + "://" + host + ':' + port + '/' + database; - } - - private static HikariConfig setParams(HikariConfig config, boolean useSSL) { // Require SSL on the server if requested in config - this will also verify certificate // Those values are deprecated in favor of sslMode config.addDataSourceProperty("useSSL", useSSL); @@ -56,11 +51,22 @@ public class MySQLStorage extends SQLStorage { // could be useful for hiding server details config.addDataSourceProperty("paranoid", true); + config.setJdbcUrl(JDBC_PROTOCOL + buildJDBCUrl(driver, host, port, database)); + // enable MySQL specific optimizations addPerformanceProperties(config); return config; } + private static String buildJDBCUrl(String driver, String host, int port, String database) { + String protocol = "mysql"; + if (driver.contains("mariadb")) { + protocol = "mariadb"; + } + + return protocol + "://" + host + ':' + port + '/' + database; + } + private static void addPerformanceProperties(HikariConfig config) { // disabled by default - will return the same prepared statement instance config.addDataSourceProperty("cachePrepStmts", true); diff --git a/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLStorage.java index 7b1fa631..dff841bf 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLStorage.java @@ -45,8 +45,6 @@ import static java.sql.Statement.RETURN_GENERATED_KEYS; public abstract class SQLStorage implements AuthStorage { - private static final String JDBC_PROTOCOL = "jdbc:"; - protected static final String PREMIUM_TABLE = "premium"; protected static final String CREATE_TABLE_STMT = "CREATE TABLE IF NOT EXISTS `" + PREMIUM_TABLE + "` (" + "`UserID` INTEGER PRIMARY KEY AUTO_INCREMENT, " @@ -70,7 +68,7 @@ public abstract class SQLStorage implements AuthStorage { protected final FastLoginCore, ?, ?> core; protected final HikariDataSource dataSource; - public SQLStorage(FastLoginCore, ?, ?> core, String jdbcURL, HikariConfig config) { + public SQLStorage(FastLoginCore, ?, ?> core, HikariConfig config) { this.core = core; config.setPoolName(core.getPlugin().getName()); @@ -79,7 +77,6 @@ public abstract class SQLStorage implements AuthStorage { config.setThreadFactory(platformThreadFactory); } - config.setJdbcUrl(JDBC_PROTOCOL + jdbcURL); this.dataSource = new HikariDataSource(config); } diff --git a/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLiteStorage.java b/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLiteStorage.java index 41beb594..c57dec32 100644 --- a/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLiteStorage.java +++ b/core/src/main/java/com/github/games647/fastlogin/core/storage/SQLiteStorage.java @@ -39,19 +39,22 @@ import java.util.concurrent.locks.ReentrantLock; public class SQLiteStorage extends SQLStorage { + private static final String SQLITE_DRIVER = "org.sqlite.SQLiteDataSource"; private final Lock lock = new ReentrantLock(); public SQLiteStorage(FastLoginCore, ?, ?> core, String databasePath, HikariConfig config) { - super(core, - "sqlite://" + replacePathVariables(core.getPlugin(), databasePath), - setParams(config)); + super(core, setParams(config, replacePathVariables(core.getPlugin(), databasePath))); } - private static HikariConfig setParams(HikariConfig config) { + private static HikariConfig setParams(HikariConfig config, String path) { + config.setDataSourceClassName(SQLITE_DRIVER); + config.setConnectionTestQuery("SELECT 1"); config.setMaximumPoolSize(1); - //a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647 + config.addDataSourceProperty("databaseName", path); + + // a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647 // format strings retrieved by the timestamp column to match them from MySQL config.addDataSourceProperty("date_string_format", "yyyy-MM-dd HH:mm:ss");