this is enough.

This commit is contained in:
DNx5 2015-11-03 07:37:00 +07:00
parent 3ede8f0dae
commit 56aca7f473
2 changed files with 37 additions and 63 deletions

View File

@ -1,26 +1,18 @@
package fr.xephi.authme.datasource; package fr.xephi.authme.datasource;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.pool.PoolInitializationException; import com.zaxxer.hikari.pool.PoolInitializationException;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class MySQL implements DataSource { public class MySQL implements DataSource {
private String host; private String host;
@ -108,19 +100,18 @@ public class MySQL implements DataSource {
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
config.setUsername(this.username); config.setUsername(this.username);
config.setPassword(this.password); config.setPassword(this.password);
if (Settings.isMySQLWebsite) if (Settings.isMySQLWebsite) {
{
config.addDataSourceProperty("cachePrepStmts", "false"); config.addDataSourceProperty("cachePrepStmts", "false");
} } else {
else {
config.addDataSourceProperty("cachePrepStmts", "true"); config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
} }
config.addDataSourceProperty("autoReconnect", false); config.addDataSourceProperty("autoReconnect", false);
config.setInitializationFailFast(true); // Don't start the plugin if the database is unavariable config.setInitializationFailFast(true); // Don't start the plugin if the database is unavailable
config.setMaxLifetime(180000); // 3 Min config.setMaxLifetime(180000); // 3 Min
config.setIdleTimeout(60000); // 1 Min config.setIdleTimeout(60000); // 1 Min
config.setMinimumIdle(2);
config.setMaximumPoolSize(maxConnections); config.setMaximumPoolSize(maxConnections);
ds = new HikariDataSource(config); ds = new HikariDataSource(config);
ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!"); ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!");
@ -136,24 +127,7 @@ public class MySQL implements DataSource {
} }
private synchronized Connection getConnection() throws SQLException { private synchronized Connection getConnection() throws SQLException {
if (!ds.isClosed()) return ds.getConnection();
{
Connection con;
con = ds.getConnection();
return con;
}
ConsoleLogger.showError("Can't open a database connection!");
if (Settings.isStopEnabled)
{
ConsoleLogger.showError("Server will ShuttingDown for Security reason");
Bukkit.getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable(){
@Override
public void run() {
AuthMe.getInstance().getServer().shutdown();
}
});
}
return null;
} }
private synchronized void setupConnection() throws SQLException { private synchronized void setupConnection() throws SQLException {

View File

@ -10,7 +10,7 @@ DataSource:
# Database Port # Database Port
mySQLPort: '3306' mySQLPort: '3306'
# MySql Max Connections # MySql Max Connections
mySQLMaxConections: 25 mySQLMaxConections: 8
# Username about Database Connection Infos # Username about Database Connection Infos
mySQLUsername: authme mySQLUsername: authme
# Password about Database Connection Infos # Password about Database Connection Infos