mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 10:47:33 +02:00
Remove and fix storage driver check
This commit is contained in:
@ -66,8 +66,6 @@ import net.md_5.bungee.config.Configuration;
|
|||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import net.md_5.bungee.config.ConfigurationProvider;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import net.md_5.bungee.config.YamlConfiguration;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import static java.util.function.Function.identity;
|
import static java.util.function.Function.identity;
|
||||||
import static java.util.stream.Collectors.toMap;
|
import static java.util.stream.Collectors.toMap;
|
||||||
import static java.util.stream.Collectors.toSet;
|
import static java.util.stream.Collectors.toSet;
|
||||||
@ -224,10 +222,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean setupDatabase() {
|
public boolean setupDatabase() {
|
||||||
String driver = config.getString("driver");
|
String type = config.getString("driver");
|
||||||
if (!checkDriver(driver)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
HikariConfig databaseConfig = new HikariConfig();
|
HikariConfig databaseConfig = new HikariConfig();
|
||||||
String database = config.getString("database");
|
String database = config.getString("database");
|
||||||
@ -235,7 +230,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
databaseConfig.setConnectionTimeout(config.getInt("timeout", 30) * 1_000L);
|
databaseConfig.setConnectionTimeout(config.getInt("timeout", 30) * 1_000L);
|
||||||
databaseConfig.setMaxLifetime(config.getInt("lifetime", 30) * 1_000L);
|
databaseConfig.setMaxLifetime(config.getInt("lifetime", 30) * 1_000L);
|
||||||
|
|
||||||
if (driver.contains("sqlite")) {
|
if (type.contains("sqlite")) {
|
||||||
storage = new SQLiteStorage(this, database, databaseConfig);
|
storage = new SQLiteStorage(this, database, databaseConfig);
|
||||||
} else {
|
} else {
|
||||||
String host = config.get("host", "");
|
String host = config.get("host", "");
|
||||||
@ -254,7 +249,7 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
|
|
||||||
databaseConfig.setUsername(config.get("username", ""));
|
databaseConfig.setUsername(config.get("username", ""));
|
||||||
databaseConfig.setPassword(config.getString("password"));
|
databaseConfig.setPassword(config.getString("password"));
|
||||||
storage = new MySQLStorage(this, driver, host, port, database, databaseConfig, useSSL);
|
storage = new MySQLStorage(this, type, host, port, database, databaseConfig, useSSL);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -266,20 +261,6 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkDriver(String className) {
|
|
||||||
try {
|
|
||||||
Class.forName(className);
|
|
||||||
return true;
|
|
||||||
} catch (ClassNotFoundException notFoundEx) {
|
|
||||||
Logger log = plugin.getLog();
|
|
||||||
log.warn("This driver {} is not supported on this platform", className);
|
|
||||||
log.warn("Please choose either MySQL (Spigot, BungeeCord), SQLite (Spigot, Sponge) or "
|
|
||||||
+ "MariaDB (Sponge, Velocity)", notFoundEx);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Configuration getConfig() {
|
public Configuration getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ import java.util.UUID;
|
|||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
import org.sqlite.JDBC;
|
||||||
import org.sqlite.SQLiteConfig;
|
import org.sqlite.SQLiteConfig;
|
||||||
|
|
||||||
public class SQLiteStorage extends SQLStorage {
|
public class SQLiteStorage extends SQLStorage {
|
||||||
@ -54,17 +55,16 @@ public class SQLiteStorage extends SQLStorage {
|
|||||||
config.setConnectionTestQuery("SELECT 1");
|
config.setConnectionTestQuery("SELECT 1");
|
||||||
config.setMaximumPoolSize(1);
|
config.setMaximumPoolSize(1);
|
||||||
|
|
||||||
config.addDataSourceProperty("url", path);
|
config.addDataSourceProperty("url", JDBC.PREFIX + path);
|
||||||
|
|
||||||
// a try to fix https://www.spigotmc.org/threads/fastlogin.101192/page-26#post-1874647
|
// 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
|
// format strings retrieved by the timestamp column to match them from MySQL
|
||||||
// vs the default: yyyy-MM-dd HH:mm:ss.SSS
|
// vs the default: yyyy-MM-dd HH:mm:ss.SSS
|
||||||
SQLiteConfig sqLiteConfig = new SQLiteConfig();
|
SQLiteConfig sqLiteConfig = new SQLiteConfig();
|
||||||
sqLiteConfig.setDateStringFormat("yyyy-MM-dd HH:mm:ss");
|
sqLiteConfig.setDateStringFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
config.addDataSourceProperty("config", config);
|
// sqLiteConfig.setDatePrecision("seconds");
|
||||||
|
|
||||||
// TODO: test first for compatibility
|
config.addDataSourceProperty("config", sqLiteConfig);
|
||||||
// config.addDataSourceProperty("date_precision", "seconds");
|
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user