mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 14:46:46 +01:00
Rewiring the SQL code to the new configs
This commit is contained in:
parent
e94005df34
commit
be69f0d6a7
@ -12,11 +12,7 @@ public class ConfigCategoryDatabase {
|
|||||||
@Setting(value = "Table_Prefix", comment = "The Prefix that will be used for tables in your DB")
|
@Setting(value = "Table_Prefix", comment = "The Prefix that will be used for tables in your DB")
|
||||||
private String tablePrefix = "mcmmo_";
|
private String tablePrefix = "mcmmo_";
|
||||||
|
|
||||||
@Setting(value = "Max_Connections", comment = "This setting is the max simultaneous MySQL/MariaDB connections allowed at a time, this needs to be high enough to support multiple player logins in quick succession")
|
|
||||||
private ConfigCategoryMaxConnections configCategoryMaxConnections;
|
|
||||||
|
|
||||||
@Setting(value = "Max_Pool_Size", comment = "This setting is the max size of the pool of cached connections that we hold at any given time.")
|
|
||||||
private ConfigCategoryMaxPoolSize configCategoryMaxPoolSize;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GETTER BOILERPLATE
|
* GETTER BOILERPLATE
|
||||||
@ -30,11 +26,5 @@ public class ConfigCategoryDatabase {
|
|||||||
return tablePrefix;
|
return tablePrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigCategoryMaxConnections getConfigCategoryMaxConnections() {
|
|
||||||
return configCategoryMaxConnections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ConfigCategoryMaxPoolSize getConfigCategoryMaxPoolSize() {
|
|
||||||
return configCategoryMaxPoolSize;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.gmail.nossr50.config.hocon.database;
|
package com.gmail.nossr50.config.hocon.database;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.database.SQLDatabaseManager;
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import ninja.leaping.configurate.objectmapping.Setting;
|
import ninja.leaping.configurate.objectmapping.Setting;
|
||||||
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
|
||||||
|
|
||||||
@ -26,6 +28,10 @@ public class ConfigCategoryMySQL {
|
|||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigCategoryUser getConfigCategoryUser() {
|
||||||
|
return configCategoryUser;
|
||||||
|
}
|
||||||
|
|
||||||
public ConfigCategoryDatabase getConfigCategoryDatabase() {
|
public ConfigCategoryDatabase getConfigCategoryDatabase() {
|
||||||
return configCategoryDatabase;
|
return configCategoryDatabase;
|
||||||
}
|
}
|
||||||
@ -33,4 +39,34 @@ public class ConfigCategoryMySQL {
|
|||||||
public ConfigCategoryServer getConfigCategoryServer() {
|
public ConfigCategoryServer getConfigCategoryServer() {
|
||||||
return configCategoryServer;
|
return configCategoryServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxPoolSize(SQLDatabaseManager.PoolIdentifier poolIdentifier)
|
||||||
|
{
|
||||||
|
switch (poolIdentifier)
|
||||||
|
{
|
||||||
|
case LOAD:
|
||||||
|
return configCategoryServer.getConfigCategoryMaxPoolSize().getLoad();
|
||||||
|
case SAVE:
|
||||||
|
return configCategoryServer.getConfigCategoryMaxPoolSize().getSave();
|
||||||
|
case MISC:
|
||||||
|
return configCategoryServer.getConfigCategoryMaxPoolSize().getMisc();
|
||||||
|
default:
|
||||||
|
return 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxConnections(SQLDatabaseManager.PoolIdentifier poolIdentifier)
|
||||||
|
{
|
||||||
|
switch (poolIdentifier)
|
||||||
|
{
|
||||||
|
case LOAD:
|
||||||
|
return configCategoryServer.getConfigCategoryMaxPoolSize().getLoad();
|
||||||
|
case SAVE:
|
||||||
|
return configCategoryServer.getConfigCategoryMaxPoolSize().getSave();
|
||||||
|
case MISC:
|
||||||
|
return configCategoryServer.getConfigCategoryMaxPoolSize().getMisc();
|
||||||
|
default:
|
||||||
|
return 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,12 @@ public class ConfigCategoryServer {
|
|||||||
@Setting(value = "Server_Address", comment = "The address for your MySQL/MariaDB server")
|
@Setting(value = "Server_Address", comment = "The address for your MySQL/MariaDB server")
|
||||||
private String serverAddress = "localhost";
|
private String serverAddress = "localhost";
|
||||||
|
|
||||||
|
@Setting(value = "Max_Connections", comment = "This setting is the max simultaneous MySQL/MariaDB connections allowed at a time, this needs to be high enough to support multiple player logins in quick succession")
|
||||||
|
private ConfigCategoryMaxConnections configCategoryMaxConnections;
|
||||||
|
|
||||||
|
@Setting(value = "Max_Pool_Size", comment = "This setting is the max size of the pool of cached connections that we hold at any given time.")
|
||||||
|
private ConfigCategoryMaxPoolSize configCategoryMaxPoolSize;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GETTER BOILERPLATE
|
* GETTER BOILERPLATE
|
||||||
*/
|
*/
|
||||||
@ -32,4 +38,14 @@ public class ConfigCategoryServer {
|
|||||||
public String getServerAddress() {
|
public String getServerAddress() {
|
||||||
return serverAddress;
|
return serverAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigCategoryMaxConnections getConfigCategoryMaxConnections() {
|
||||||
|
return configCategoryMaxConnections;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigCategoryMaxPoolSize getConfigCategoryMaxPoolSize() {
|
||||||
|
return configCategoryMaxPoolSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@ import java.util.concurrent.locks.ReentrantLock;
|
|||||||
|
|
||||||
public final class SQLDatabaseManager implements DatabaseManager {
|
public final class SQLDatabaseManager implements DatabaseManager {
|
||||||
private static final String ALL_QUERY_VERSION = "total";
|
private static final String ALL_QUERY_VERSION = "total";
|
||||||
private String tablePrefix = MainConfig.getInstance().getMySQLTablePrefix();
|
public static final String COM_MYSQL_JDBC_DRIVER = "com.mysql.jdbc.Driver";
|
||||||
|
private String tablePrefix = mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getTablePrefix();
|
||||||
|
|
||||||
private final Map<UUID, Integer> cachedUserIDs = new HashMap<UUID, Integer>();
|
private final Map<UUID, Integer> cachedUserIDs = new HashMap<UUID, Integer>();
|
||||||
|
|
||||||
@ -32,10 +33,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
private ReentrantLock massUpdateLock = new ReentrantLock();
|
private ReentrantLock massUpdateLock = new ReentrantLock();
|
||||||
|
|
||||||
protected SQLDatabaseManager() {
|
protected SQLDatabaseManager() {
|
||||||
String connectionString = "jdbc:mysql://" + MainConfig.getInstance().getMySQLServerName()
|
String connectionString = "jdbc:mysql://" + mcMMO.getMySQLConfigSettings().getConfigCategoryServer().getServerAddress()
|
||||||
+ ":" + MainConfig.getInstance().getMySQLServerPort() + "/" + MainConfig.getInstance().getMySQLDatabaseName();
|
+ ":" + mcMMO.getMySQLConfigSettings().getConfigCategoryServer().getServerPort() + "/" + mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName();
|
||||||
|
|
||||||
if(MainConfig.getInstance().getMySQLSSL())
|
if(mcMMO.getMySQLConfigSettings().getConfigCategoryServer().isUseSSL())
|
||||||
connectionString +=
|
connectionString +=
|
||||||
"?verifyServerCertificate=false"+
|
"?verifyServerCertificate=false"+
|
||||||
"&useSSL=true"+
|
"&useSSL=true"+
|
||||||
@ -46,7 +47,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Force driver to load if not yet loaded
|
// Force driver to load if not yet loaded
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName(COM_MYSQL_JDBC_DRIVER);
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException e) {
|
catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -54,56 +55,58 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
//throw e; // aborts onEnable() Riking if you want to do this, fully implement it.
|
//throw e; // aborts onEnable() Riking if you want to do this, fully implement it.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Setup Save, Load, and Misc pools
|
||||||
PoolProperties poolProperties = new PoolProperties();
|
setupPools(connectionString);
|
||||||
poolProperties.setDriverClassName("com.mysql.jdbc.Driver");
|
|
||||||
poolProperties.setUrl(connectionString);
|
|
||||||
poolProperties.setUsername(MainConfig.getInstance().getMySQLUserName());
|
|
||||||
poolProperties.setPassword(MainConfig.getInstance().getMySQLUserPassword());
|
|
||||||
poolProperties.setMaxIdle(MainConfig.getInstance().getMySQLMaxPoolSize(PoolIdentifier.MISC));
|
|
||||||
poolProperties.setMaxActive(MainConfig.getInstance().getMySQLMaxConnections(PoolIdentifier.MISC));
|
|
||||||
poolProperties.setInitialSize(0);
|
|
||||||
poolProperties.setMaxWait(-1);
|
|
||||||
poolProperties.setRemoveAbandoned(true);
|
|
||||||
poolProperties.setRemoveAbandonedTimeout(60);
|
|
||||||
poolProperties.setTestOnBorrow(true);
|
|
||||||
poolProperties.setValidationQuery("SELECT 1");
|
|
||||||
poolProperties.setValidationInterval(30000);
|
|
||||||
miscPool = new DataSource(poolProperties);
|
|
||||||
poolProperties = new PoolProperties();
|
|
||||||
poolProperties.setDriverClassName("com.mysql.jdbc.Driver");
|
|
||||||
poolProperties.setUrl(connectionString);
|
|
||||||
poolProperties.setUsername(MainConfig.getInstance().getMySQLUserName());
|
|
||||||
poolProperties.setPassword(MainConfig.getInstance().getMySQLUserPassword());
|
|
||||||
poolProperties.setInitialSize(0);
|
|
||||||
poolProperties.setMaxIdle(MainConfig.getInstance().getMySQLMaxPoolSize(PoolIdentifier.SAVE));
|
|
||||||
poolProperties.setMaxActive(MainConfig.getInstance().getMySQLMaxConnections(PoolIdentifier.SAVE));
|
|
||||||
poolProperties.setMaxWait(-1);
|
|
||||||
poolProperties.setRemoveAbandoned(true);
|
|
||||||
poolProperties.setRemoveAbandonedTimeout(60);
|
|
||||||
poolProperties.setTestOnBorrow(true);
|
|
||||||
poolProperties.setValidationQuery("SELECT 1");
|
|
||||||
poolProperties.setValidationInterval(30000);
|
|
||||||
savePool = new DataSource(poolProperties);
|
|
||||||
poolProperties = new PoolProperties();
|
|
||||||
poolProperties.setDriverClassName("com.mysql.jdbc.Driver");
|
|
||||||
poolProperties.setUrl(connectionString);
|
|
||||||
poolProperties.setUsername(MainConfig.getInstance().getMySQLUserName());
|
|
||||||
poolProperties.setPassword(MainConfig.getInstance().getMySQLUserPassword());
|
|
||||||
poolProperties.setInitialSize(0);
|
|
||||||
poolProperties.setMaxIdle(MainConfig.getInstance().getMySQLMaxPoolSize(PoolIdentifier.LOAD));
|
|
||||||
poolProperties.setMaxActive(MainConfig.getInstance().getMySQLMaxConnections(PoolIdentifier.LOAD));
|
|
||||||
poolProperties.setMaxWait(-1);
|
|
||||||
poolProperties.setRemoveAbandoned(true);
|
|
||||||
poolProperties.setRemoveAbandonedTimeout(60);
|
|
||||||
poolProperties.setTestOnBorrow(true);
|
|
||||||
poolProperties.setValidationQuery("SELECT 1");
|
|
||||||
poolProperties.setValidationInterval(30000);
|
|
||||||
loadPool = new DataSource(poolProperties);
|
|
||||||
|
|
||||||
checkStructure();
|
checkStructure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up our pools
|
||||||
|
* @param connectionString the MySQL connection string
|
||||||
|
*/
|
||||||
|
private void setupPools(String connectionString)
|
||||||
|
{
|
||||||
|
miscPool = new DataSource(setupPool(PoolIdentifier.MISC, connectionString));
|
||||||
|
loadPool = new DataSource(setupPool(PoolIdentifier.LOAD, connectionString));
|
||||||
|
savePool = new DataSource(setupPool(PoolIdentifier.SAVE, connectionString));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up our pool using settings from the users config
|
||||||
|
* @param poolIdentifier the target pool
|
||||||
|
* @param connectionString the MySQL connection string
|
||||||
|
* @return the pool properties ready for conversion
|
||||||
|
*/
|
||||||
|
private PoolProperties setupPool(PoolIdentifier poolIdentifier, String connectionString)
|
||||||
|
{
|
||||||
|
PoolProperties poolProperties = new PoolProperties();
|
||||||
|
poolProperties.setDriverClassName(COM_MYSQL_JDBC_DRIVER);
|
||||||
|
poolProperties.setUrl(connectionString);
|
||||||
|
|
||||||
|
//MySQL User Name
|
||||||
|
poolProperties.setUsername(mcMMO.getMySQLConfigSettings().getConfigCategoryUser().getUsername());
|
||||||
|
//MySQL User Password
|
||||||
|
poolProperties.setPassword(mcMMO.getMySQLConfigSettings().getConfigCategoryUser().getPassword());
|
||||||
|
|
||||||
|
//Initial Size
|
||||||
|
poolProperties.setInitialSize(0);
|
||||||
|
|
||||||
|
//Max Pool Size for Misc
|
||||||
|
poolProperties.setMaxIdle(mcMMO.getMySQLConfigSettings().getMaxPoolSize(poolIdentifier));
|
||||||
|
//Max Connections for Misc
|
||||||
|
poolProperties.setMaxActive(mcMMO.getMySQLConfigSettings().getMaxConnections(poolIdentifier));
|
||||||
|
|
||||||
|
poolProperties.setMaxWait(-1);
|
||||||
|
poolProperties.setRemoveAbandoned(true);
|
||||||
|
poolProperties.setRemoveAbandonedTimeout(60);
|
||||||
|
poolProperties.setTestOnBorrow(true);
|
||||||
|
poolProperties.setValidationQuery("SELECT 1");
|
||||||
|
poolProperties.setValidationInterval(30000);
|
||||||
|
|
||||||
|
return poolProperties;
|
||||||
|
}
|
||||||
|
|
||||||
public void purgePowerlessUsers() {
|
public void purgePowerlessUsers() {
|
||||||
massUpdateLock.lock();
|
massUpdateLock.lock();
|
||||||
mcMMO.p.getLogger().info("Purging powerless users...");
|
mcMMO.p.getLogger().info("Purging powerless users...");
|
||||||
@ -779,7 +782,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
statement = connection.prepareStatement("SELECT table_name FROM INFORMATION_SCHEMA.TABLES"
|
statement = connection.prepareStatement("SELECT table_name FROM INFORMATION_SCHEMA.TABLES"
|
||||||
+ " WHERE table_schema = ?"
|
+ " WHERE table_schema = ?"
|
||||||
+ " AND table_name = ?");
|
+ " AND table_name = ?");
|
||||||
statement.setString(1, MainConfig.getInstance().getMySQLDatabaseName());
|
//Database name
|
||||||
|
statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName());
|
||||||
statement.setString(2, tablePrefix + "users");
|
statement.setString(2, tablePrefix + "users");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
if (!resultSet.next()) {
|
if (!resultSet.next()) {
|
||||||
@ -795,7 +799,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
tryClose(createStatement);
|
tryClose(createStatement);
|
||||||
}
|
}
|
||||||
tryClose(resultSet);
|
tryClose(resultSet);
|
||||||
statement.setString(1, MainConfig.getInstance().getMySQLDatabaseName());
|
//Database name
|
||||||
|
statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName());
|
||||||
statement.setString(2, tablePrefix + "huds");
|
statement.setString(2, tablePrefix + "huds");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
if (!resultSet.next()) {
|
if (!resultSet.next()) {
|
||||||
@ -809,7 +814,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
tryClose(createStatement);
|
tryClose(createStatement);
|
||||||
}
|
}
|
||||||
tryClose(resultSet);
|
tryClose(resultSet);
|
||||||
statement.setString(1, MainConfig.getInstance().getMySQLDatabaseName());
|
//Database name
|
||||||
|
statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName());
|
||||||
statement.setString(2, tablePrefix + "cooldowns");
|
statement.setString(2, tablePrefix + "cooldowns");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
if (!resultSet.next()) {
|
if (!resultSet.next()) {
|
||||||
@ -834,7 +840,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
tryClose(createStatement);
|
tryClose(createStatement);
|
||||||
}
|
}
|
||||||
tryClose(resultSet);
|
tryClose(resultSet);
|
||||||
statement.setString(1, MainConfig.getInstance().getMySQLDatabaseName());
|
//Database name
|
||||||
|
statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName());
|
||||||
statement.setString(2, tablePrefix + "skills");
|
statement.setString(2, tablePrefix + "skills");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
if (!resultSet.next()) {
|
if (!resultSet.next()) {
|
||||||
@ -862,7 +869,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
tryClose(createStatement);
|
tryClose(createStatement);
|
||||||
}
|
}
|
||||||
tryClose(resultSet);
|
tryClose(resultSet);
|
||||||
statement.setString(1, MainConfig.getInstance().getMySQLDatabaseName());
|
//Database name
|
||||||
|
statement.setString(1, mcMMO.getMySQLConfigSettings().getConfigCategoryDatabase().getDatabaseName());
|
||||||
statement.setString(2, tablePrefix + "experience");
|
statement.setString(2, tablePrefix + "experience");
|
||||||
resultSet = statement.executeQuery();
|
resultSet = statement.executeQuery();
|
||||||
if (!resultSet.next()) {
|
if (!resultSet.next()) {
|
||||||
|
@ -5,6 +5,7 @@ import com.gmail.nossr50.config.CoreSkillsConfig;
|
|||||||
import com.gmail.nossr50.config.MainConfig;
|
import com.gmail.nossr50.config.MainConfig;
|
||||||
import com.gmail.nossr50.config.WorldBlacklist;
|
import com.gmail.nossr50.config.WorldBlacklist;
|
||||||
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||||
|
import com.gmail.nossr50.config.hocon.database.ConfigCategoryMySQL;
|
||||||
import com.gmail.nossr50.database.DatabaseManager;
|
import com.gmail.nossr50.database.DatabaseManager;
|
||||||
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
import com.gmail.nossr50.database.DatabaseManagerFactory;
|
||||||
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
||||||
@ -322,6 +323,15 @@ public class mcMMO extends JavaPlugin {
|
|||||||
return databaseManager;
|
return databaseManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns settings for MySQL from the users config
|
||||||
|
* @return returns settings for MySQL from the users config
|
||||||
|
*/
|
||||||
|
public static ConfigCategoryMySQL getMySQLConfigSettings()
|
||||||
|
{
|
||||||
|
return configManager.getConfigDatabase().getConfigCategoryMySQL();
|
||||||
|
}
|
||||||
|
|
||||||
/*public static ModManager getModManager() {
|
/*public static ModManager getModManager() {
|
||||||
return modManager;
|
return modManager;
|
||||||
}*/
|
}*/
|
||||||
|
Loading…
Reference in New Issue
Block a user