mirror of
https://github.com/TuxCoding/FastLogin.git
synced 2025-07-30 02:37:34 +02:00
Add advanced options for the connection pool (Fixes #210)
This commit is contained in:
@ -32,17 +32,11 @@ public class AuthStorage {
|
|||||||
private final FastLoginCore<?, ?, ?> core;
|
private final FastLoginCore<?, ?, ?> core;
|
||||||
private final HikariDataSource dataSource;
|
private final HikariDataSource dataSource;
|
||||||
|
|
||||||
public AuthStorage(FastLoginCore<?, ?, ?> core, String driver, String host, int port, String databasePath
|
public AuthStorage(FastLoginCore<?, ?, ?> core, String host, int port, String databasePath,
|
||||||
, String user, String pass, boolean useSSL) {
|
HikariConfig config, boolean useSSL) {
|
||||||
this.core = core;
|
this.core = core;
|
||||||
|
|
||||||
HikariConfig config = new HikariConfig();
|
|
||||||
config.setPoolName(core.getPlugin().getName());
|
config.setPoolName(core.getPlugin().getName());
|
||||||
|
|
||||||
config.setUsername(user);
|
|
||||||
config.setPassword(pass);
|
|
||||||
config.setDriverClassName(driver);
|
|
||||||
|
|
||||||
//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
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty("date_string_format", "yyyy-MM-dd HH:mm:ss");
|
properties.setProperty("date_string_format", "yyyy-MM-dd HH:mm:ss");
|
||||||
@ -55,7 +49,7 @@ public class AuthStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String jdbcUrl = "jdbc:";
|
String jdbcUrl = "jdbc:";
|
||||||
if (driver.contains("sqlite")) {
|
if (config.getDriverClassName().contains("sqlite")) {
|
||||||
String pluginFolder = core.getPlugin().getPluginFolder().toAbsolutePath().toString();
|
String pluginFolder = core.getPlugin().getPluginFolder().toAbsolutePath().toString();
|
||||||
databasePath = databasePath.replace("{pluginDir}", pluginFolder);
|
databasePath = databasePath.replace("{pluginDir}", pluginFolder);
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import com.github.games647.fastlogin.core.hooks.AuthPlugin;
|
|||||||
import com.github.games647.fastlogin.core.hooks.DefaultPasswordGenerator;
|
import com.github.games647.fastlogin.core.hooks.DefaultPasswordGenerator;
|
||||||
import com.github.games647.fastlogin.core.hooks.PasswordGenerator;
|
import com.github.games647.fastlogin.core.hooks.PasswordGenerator;
|
||||||
import com.google.common.net.HostAndPort;
|
import com.google.common.net.HostAndPort;
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -150,8 +151,9 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean setupDatabase() {
|
public boolean setupDatabase() {
|
||||||
String driver = config.getString("driver");
|
HikariConfig databaseConfig = new HikariConfig();
|
||||||
if (!checkDriver(driver)) {
|
databaseConfig.setDriverClassName(config.getString("driver"));
|
||||||
|
if (!checkDriver(databaseConfig.getDriverClassName())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,12 +161,15 @@ public class FastLoginCore<P extends C, C, T extends PlatformPlugin<C>> {
|
|||||||
int port = config.get("port", 3306);
|
int port = config.get("port", 3306);
|
||||||
String database = config.getString("database");
|
String database = config.getString("database");
|
||||||
|
|
||||||
String user = config.get("username", "");
|
|
||||||
String password = config.get("password", "");
|
|
||||||
|
|
||||||
boolean useSSL = config.get("useSSL", false);
|
boolean useSSL = config.get("useSSL", false);
|
||||||
|
|
||||||
storage = new AuthStorage(this, driver, host, port, database, user, password, useSSL);
|
databaseConfig.setUsername(config.get("username", ""));
|
||||||
|
databaseConfig.setPassword(config.get("password", ""));
|
||||||
|
|
||||||
|
databaseConfig.setConnectionTimeout(config.getInt("timeout", 30) * 1000);
|
||||||
|
databaseConfig.setMaxLifetime(config.getInt("lifetime", 30) * 1000);
|
||||||
|
|
||||||
|
storage = new AuthStorage(this, host, port, database, databaseConfig, useSSL);
|
||||||
try {
|
try {
|
||||||
storage.createTables();
|
storage.createTables();
|
||||||
return true;
|
return true;
|
||||||
|
@ -174,6 +174,10 @@ database: '{pluginDir}/FastLogin.db'
|
|||||||
#username: myUser
|
#username: myUser
|
||||||
#password: myPassword
|
#password: myPassword
|
||||||
|
|
||||||
|
# Advanced Connection Pool settings in seconds
|
||||||
|
#timeout: 30
|
||||||
|
#lifetime: 30
|
||||||
|
|
||||||
# It's strongly recommended to enable SSL and setup a SSL certificate if the MySQL server isn't running on the same
|
# It's strongly recommended to enable SSL and setup a SSL certificate if the MySQL server isn't running on the same
|
||||||
# machine
|
# machine
|
||||||
#useSSL: false
|
#useSSL: false
|
||||||
|
Reference in New Issue
Block a user