Revert "Revert "Implement usage of SQL connection pooling in RepositoryBase to prevent unnecessary idle connections.""
This reverts commit 215ec7b00d
.
Enabled multi-queries on db pool.
Cleaned up some code using new pooling getConnection inappropriately
This commit is contained in:
parent
215ec7b00d
commit
626bfc35fc
@ -1,5 +1,6 @@
|
|||||||
package mineplex.core.account.repository;
|
package mineplex.core.account.repository;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
@ -19,6 +20,7 @@ import mineplex.core.common.Rank;
|
|||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
import mineplex.core.common.util.UUIDFetcher;
|
import mineplex.core.common.util.UUIDFetcher;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.DatabaseRunnable;
|
import mineplex.core.database.DatabaseRunnable;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
@ -43,34 +45,9 @@ public class AccountRepository extends RepositoryBase
|
|||||||
|
|
||||||
public AccountRepository(JavaPlugin plugin, String webAddress)
|
public AccountRepository(JavaPlugin plugin, String webAddress)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
|
|
||||||
_webAddress = webAddress;
|
_webAddress = webAddress;
|
||||||
|
|
||||||
Statement statement = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
statement = getConnection().createStatement();
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (statement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
statement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -81,13 +58,11 @@ public class AccountRepository extends RepositoryBase
|
|||||||
|
|
||||||
public void login(NautHashMap<String, ILoginProcessor> loginProcessors, String uuid, String name)
|
public void login(NautHashMap<String, ILoginProcessor> loginProcessors, String uuid, String name)
|
||||||
{
|
{
|
||||||
Statement statement = null;
|
try (
|
||||||
ResultSet resultSet = null;
|
Connection connection = getConnection();
|
||||||
|
Statement statement = connection.createStatement()
|
||||||
try
|
)
|
||||||
{
|
{
|
||||||
statement = getConnection().createStatement();
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
boolean statementStatus = statement.execute(
|
boolean statementStatus = statement.execute(
|
||||||
"UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';"
|
"UPDATE accounts SET name='" + name + "', lastLogin=now() WHERE accounts.uuid = '" + uuid + "';"
|
||||||
@ -152,32 +127,6 @@ public class AccountRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (statement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
statement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resultSet != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
resultSet.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String GetClient(String name, UUID uuid, String ipAddress)
|
public String GetClient(String name, UUID uuid, String ipAddress)
|
||||||
|
@ -3,6 +3,7 @@ package mineplex.core.benefit;
|
|||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ public class BenefitManagerRepository extends RepositoryBase
|
|||||||
|
|
||||||
public BenefitManagerRepository(JavaPlugin plugin)
|
public BenefitManagerRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,6 +16,7 @@ public final class DBPool
|
|||||||
{
|
{
|
||||||
BasicDataSource source = new BasicDataSource();
|
BasicDataSource source = new BasicDataSource();
|
||||||
source.addConnectionProperty("autoReconnect", "true");
|
source.addConnectionProperty("autoReconnect", "true");
|
||||||
|
source.addConnectionProperty("allowMultiQueries", "true");
|
||||||
source.setDefaultAutoCommit(true);
|
source.setDefaultAutoCommit(true);
|
||||||
source.setEnableAutoCommitOnReturn(true);
|
source.setEnableAutoCommitOnReturn(true);
|
||||||
source.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
|
source.setDefaultTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
|
||||||
@ -23,8 +24,8 @@ public final class DBPool
|
|||||||
source.setUrl(url);
|
source.setUrl(url);
|
||||||
source.setUsername(username);
|
source.setUsername(username);
|
||||||
source.setPassword(password);
|
source.setPassword(password);
|
||||||
source.setMaxTotal(2);
|
source.setMaxTotal(3);
|
||||||
source.setMaxIdle(2);
|
source.setMaxIdle(3);
|
||||||
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
|
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
|
||||||
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);
|
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package mineplex.core.database;
|
package mineplex.core.database;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -22,59 +21,30 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public abstract class RepositoryBase implements Listener
|
public abstract class RepositoryBase implements Listener
|
||||||
{
|
{
|
||||||
protected static Object _connectionLock = new Object();
|
// Queue for failed processes
|
||||||
|
|
||||||
private Connection _connection = null;
|
|
||||||
|
|
||||||
private static Object _queueLock = new Object();
|
private static Object _queueLock = new Object();
|
||||||
|
|
||||||
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
|
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
|
||||||
|
|
||||||
private String _connectionString;
|
private DataSource _dataSource; // Connection pool
|
||||||
private String _userName;
|
protected JavaPlugin Plugin; // Plugin responsible for this repository
|
||||||
private String _password;
|
|
||||||
|
|
||||||
protected JavaPlugin Plugin;
|
|
||||||
protected DataSource DataSource;
|
|
||||||
|
|
||||||
public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password)
|
|
||||||
{
|
|
||||||
Plugin = plugin;
|
|
||||||
|
|
||||||
_connectionString = connectionString;
|
|
||||||
_userName = username;
|
|
||||||
_password = password;
|
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
synchronized (_connectionLock)
|
|
||||||
{
|
|
||||||
initialize();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param plugin - the {@link JavaPlugin} module responsible for this repository.
|
||||||
|
* @param dataSource - the {@link DataSource} responsible for providing the connection pool to this repository.
|
||||||
|
*/
|
||||||
public RepositoryBase(JavaPlugin plugin, DataSource dataSource)
|
public RepositoryBase(JavaPlugin plugin, DataSource dataSource)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
DataSource = dataSource;
|
_dataSource = dataSource;
|
||||||
|
|
||||||
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
|
||||||
{
|
{
|
||||||
public void run()
|
public void run()
|
||||||
{
|
|
||||||
synchronized (_connectionLock)
|
|
||||||
{
|
{
|
||||||
initialize();
|
initialize();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
@ -84,34 +54,39 @@ public abstract class RepositoryBase implements Listener
|
|||||||
|
|
||||||
protected abstract void update();
|
protected abstract void update();
|
||||||
|
|
||||||
protected Connection getConnection()
|
/**
|
||||||
|
* @return the {@link DataSource} used by the repository for connection pooling.
|
||||||
|
*/
|
||||||
|
protected DataSource getConnectionPool()
|
||||||
{
|
{
|
||||||
return getConnection(false);
|
return _dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Connection getConnection(boolean validate)
|
/**
|
||||||
{
|
* Requirements: {@link Connection}s must be closed after usage so they may be returned to the pool!
|
||||||
synchronized (_connectionLock)
|
* @see Connection#close()
|
||||||
|
* @return a newly fetched {@link Connection} from the connection pool, if a connection can be made, null otherwise.
|
||||||
|
*/
|
||||||
|
protected Connection getConnection()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_connection == null || (validate && !_connection.isValid(2)))
|
return _dataSource.getConnection();
|
||||||
{
|
|
||||||
if (DataSource != null)
|
|
||||||
_connection = DataSource.getConnection();
|
|
||||||
else
|
|
||||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
// TODO: Log connection failures?
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _connection;
|
/**
|
||||||
}
|
* Execute a query against the repository.
|
||||||
|
* @param query - the concatenated query to execute in string form.
|
||||||
|
* @param columns - the column data values used for insertion into the query.
|
||||||
|
* @return the number of rows affected by this query in the repository.
|
||||||
|
*/
|
||||||
protected int executeUpdate(String query, Column<?>...columns)
|
protected int executeUpdate(String query, Column<?>...columns)
|
||||||
{
|
{
|
||||||
return executeInsert(query, null, columns);
|
return executeInsert(query, null, columns);
|
||||||
@ -119,16 +94,14 @@ public abstract class RepositoryBase implements Listener
|
|||||||
|
|
||||||
protected int executeInsert(String query, ResultSetCallable callable, Column<?>...columns)
|
protected int executeInsert(String query, ResultSetCallable callable, Column<?>...columns)
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
int affectedRows = 0;
|
int affectedRows = 0;
|
||||||
|
|
||||||
try
|
// Automatic resource management for handling/closing objects.
|
||||||
|
try (
|
||||||
|
Connection connection = getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
getConnection(false);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
|
|
||||||
|
|
||||||
for (int i=0; i < columns.length; i++)
|
for (int i=0; i < columns.length; i++)
|
||||||
{
|
{
|
||||||
columns[i].setValue(preparedStatement, i+1);
|
columns[i].setValue(preparedStatement, i+1);
|
||||||
@ -137,49 +110,24 @@ public abstract class RepositoryBase implements Listener
|
|||||||
affectedRows = preparedStatement.executeUpdate();
|
affectedRows = preparedStatement.executeUpdate();
|
||||||
|
|
||||||
if (callable != null)
|
if (callable != null)
|
||||||
|
{
|
||||||
callable.processResultSet(preparedStatement.getGeneratedKeys());
|
callable.processResultSet(preparedStatement.getGeneratedKeys());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (SQLException exception)
|
catch (SQLException exception)
|
||||||
{
|
{
|
||||||
getConnection(true);
|
|
||||||
executeInsert(query, callable, columns);
|
executeInsert(query, callable, columns);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (DataSource != null)
|
|
||||||
_connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return affectedRows;
|
return affectedRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
|
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
|
||||||
{
|
{
|
||||||
ResultSet resultSet = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (int i=0; i < columns.length; i++)
|
for (int i=0; i < columns.length; i++)
|
||||||
@ -187,116 +135,39 @@ public abstract class RepositoryBase implements Listener
|
|||||||
columns[i].setValue(statement, i+1);
|
columns[i].setValue(statement, i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
resultSet = statement.executeQuery();
|
try (ResultSet resultSet = statement.executeQuery())
|
||||||
|
{
|
||||||
callable.processResultSet(resultSet);
|
callable.processResultSet(resultSet);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (SQLException exception)
|
catch (SQLException exception)
|
||||||
{
|
{
|
||||||
getConnection(true);
|
|
||||||
executeQuery(statement, callable, columns);
|
executeQuery(statement, callable, columns);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (resultSet != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
resultSet.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (DataSource != null)
|
|
||||||
_connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
|
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
// Automatic resource management for handling/closing objects.
|
||||||
|
try (
|
||||||
try
|
Connection connection = getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(query)
|
||||||
|
)
|
||||||
{
|
{
|
||||||
getConnection(false);
|
|
||||||
|
|
||||||
preparedStatement = _connection.prepareStatement(query);
|
|
||||||
|
|
||||||
executeQuery(preparedStatement, callable, columns);
|
executeQuery(preparedStatement, callable, columns);
|
||||||
}
|
}
|
||||||
catch (SQLException exception)
|
catch (SQLException exception)
|
||||||
{
|
{
|
||||||
getConnection(true);
|
|
||||||
executeQuery(query, callable, columns);
|
executeQuery(query, callable, columns);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (DataSource != null)
|
|
||||||
_connection.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int executeUpdate(PreparedStatement preparedStatement, Column<?>...columns)
|
|
||||||
{
|
|
||||||
int affectedRows = 0;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
for (int i=0; i < columns.length; i++)
|
|
||||||
{
|
|
||||||
columns[i].setValue(preparedStatement, i+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
affectedRows = preparedStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
catch (SQLException exception)
|
|
||||||
{
|
|
||||||
getConnection(true);
|
|
||||||
executeUpdate(preparedStatement, columns);
|
|
||||||
}
|
|
||||||
catch (Exception exception)
|
|
||||||
{
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return affectedRows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
|
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
|
||||||
@ -341,24 +212,6 @@ public abstract class RepositoryBase implements Listener
|
|||||||
processFailedQueue();
|
processFailedQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void validateConnection(UpdateEvent event)
|
|
||||||
{
|
|
||||||
if (event.getType() != UpdateType.MIN_02 || DataSource != null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(Plugin, new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
synchronized (_connectionLock)
|
|
||||||
{
|
|
||||||
getConnection(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processFailedQueue()
|
private void processFailedQueue()
|
||||||
{
|
{
|
||||||
synchronized (_queueLock)
|
synchronized (_queueLock)
|
||||||
|
@ -8,6 +8,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.DatabaseRunnable;
|
import mineplex.core.database.DatabaseRunnable;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
@ -33,7 +34,7 @@ public class DonationRepository extends RepositoryBase
|
|||||||
|
|
||||||
public DonationRepository(JavaPlugin plugin, String webAddress)
|
public DonationRepository(JavaPlugin plugin, String webAddress)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
|
|
||||||
_webAddress = webAddress;
|
_webAddress = webAddress;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
@ -31,7 +32,7 @@ public class InventoryRepository extends RepositoryBase
|
|||||||
|
|
||||||
public InventoryRepository(JavaPlugin plugin)
|
public InventoryRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package mineplex.core.leaderboard;
|
package mineplex.core.leaderboard;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -35,7 +36,7 @@ public class StatEventsRepository extends RepositoryBase
|
|||||||
*/
|
*/
|
||||||
public StatEventsRepository(JavaPlugin plugin)
|
public StatEventsRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package mineplex.core.preferences;
|
package mineplex.core.preferences;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -14,7 +15,7 @@ import mineplex.core.database.column.ColumnVarChar;
|
|||||||
|
|
||||||
public class PreferencesRepository extends RepositoryBase
|
public class PreferencesRepository extends RepositoryBase
|
||||||
{
|
{
|
||||||
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));";
|
//private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));";
|
||||||
private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;";
|
private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;";
|
||||||
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ? WHERE uuid=?;";
|
private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ? WHERE uuid=?;";
|
||||||
|
|
||||||
@ -36,12 +37,12 @@ public class PreferencesRepository extends RepositoryBase
|
|||||||
|
|
||||||
public void saveUserPreferences(NautHashMap<String, UserPreferences> preferences)
|
public void saveUserPreferences(NautHashMap<String, UserPreferences> preferences)
|
||||||
{
|
{
|
||||||
PreparedStatement preparedStatement = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
|
(
|
||||||
|
Connection connection = getConnection();
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
|
||||||
|
)
|
||||||
{
|
{
|
||||||
preparedStatement = getConnection().prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
|
|
||||||
|
|
||||||
for (Entry<String, UserPreferences> entry : preferences.entrySet())
|
for (Entry<String, UserPreferences> entry : preferences.entrySet())
|
||||||
{
|
{
|
||||||
preparedStatement.setBoolean(1, entry.getValue().HubGames);
|
preparedStatement.setBoolean(1, entry.getValue().HubGames);
|
||||||
@ -93,20 +94,6 @@ public class PreferencesRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (preparedStatement != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
preparedStatement.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserPreferences loadClientInformation(final ResultSet resultSet) throws SQLException
|
public UserPreferences loadClientInformation(final ResultSet resultSet) throws SQLException
|
||||||
|
@ -7,6 +7,7 @@ import java.util.UUID;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
@ -40,7 +41,7 @@ This will be used to determine if staff are handling
|
|||||||
|
|
||||||
public ReportRepository(JavaPlugin plugin, String connectionString)
|
public ReportRepository(JavaPlugin plugin, String connectionString)
|
||||||
{
|
{
|
||||||
super(plugin, connectionString, "root", "tAbechAk3wR7tuTh"); // TODO: Config file for host/pass?
|
super(plugin, DBPool.ACCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -22,8 +23,7 @@ public class SpawnRepository extends RepositoryBase
|
|||||||
|
|
||||||
public SpawnRepository(JavaPlugin plugin, String serverName)
|
public SpawnRepository(JavaPlugin plugin, String serverName)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
|
|
||||||
_serverName = serverName;
|
_serverName = serverName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import mineplex.core.common.util.NautHashMap;
|
import mineplex.core.common.util.NautHashMap;
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -18,6 +19,7 @@ import org.jooq.DSLContext;
|
|||||||
import org.jooq.Insert;
|
import org.jooq.Insert;
|
||||||
import org.jooq.Record2;
|
import org.jooq.Record2;
|
||||||
import org.jooq.Result;
|
import org.jooq.Result;
|
||||||
|
import org.jooq.SQLDialect;
|
||||||
import org.jooq.Update;
|
import org.jooq.Update;
|
||||||
import org.jooq.impl.DSL;
|
import org.jooq.impl.DSL;
|
||||||
|
|
||||||
@ -31,7 +33,7 @@ public class StatsRepository extends RepositoryBase
|
|||||||
|
|
||||||
public StatsRepository(JavaPlugin plugin)
|
public StatsRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,8 +81,7 @@ public class StatsRepository extends RepositoryBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
DSLContext context = DSL.using(getConnectionPool(), SQLDialect.MYSQL);
|
||||||
DSLContext context = DSL.using(getConnection(true));
|
|
||||||
|
|
||||||
List<Update> updates = new ArrayList<>();
|
List<Update> updates = new ArrayList<>();
|
||||||
List<Insert> inserts = new ArrayList<>();
|
List<Insert> inserts = new ArrayList<>();
|
||||||
@ -133,7 +134,7 @@ public class StatsRepository extends RepositoryBase
|
|||||||
|
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
{
|
{
|
||||||
context = DSL.using(getConnection());
|
context = DSL.using(getConnectionPool(), SQLDialect.MYSQL);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<Record2<String, Integer>> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)
|
Result<Record2<String, Integer>> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)
|
||||||
|
@ -2,6 +2,7 @@ package mineplex.enjinTranslator;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.column.ColumnInt;
|
import mineplex.core.database.column.ColumnInt;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -12,7 +13,7 @@ public class TempRepository extends RepositoryBase
|
|||||||
|
|
||||||
public TempRepository(JavaPlugin plugin)
|
public TempRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addGemBooster(String name, int amount)
|
public void addGemBooster(String name, int amount)
|
||||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnByte;
|
import mineplex.core.database.column.ColumnByte;
|
||||||
@ -31,7 +32,7 @@ public class FieldRepository extends RepositoryBase
|
|||||||
|
|
||||||
public FieldRepository(JavaPlugin plugin)
|
public FieldRepository(JavaPlugin plugin)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FieldBlockToken> getFieldBlocks(String server)
|
public List<FieldBlockToken> getFieldBlocks(String server)
|
||||||
|
@ -6,9 +6,11 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.database.Tables;
|
import mineplex.database.Tables;
|
||||||
import mineplex.database.tables.records.MailRecord;
|
import mineplex.database.tables.records.MailRecord;
|
||||||
|
|
||||||
import org.jooq.DSLContext;
|
import org.jooq.DSLContext;
|
||||||
import org.jooq.Result;
|
import org.jooq.Result;
|
||||||
import org.jooq.impl.DSL;
|
import org.jooq.impl.DSL;
|
||||||
@ -19,7 +21,7 @@ public class MailRepository extends RepositoryBase
|
|||||||
|
|
||||||
public MailRepository(JavaPlugin plugin, MailManager manager)
|
public MailRepository(JavaPlugin plugin, MailManager manager)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
|
|
||||||
_manager = manager;
|
_manager = manager;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.database.DBPool;
|
||||||
import mineplex.core.database.RepositoryBase;
|
import mineplex.core.database.RepositoryBase;
|
||||||
import mineplex.core.database.ResultSetCallable;
|
import mineplex.core.database.ResultSetCallable;
|
||||||
import mineplex.core.database.column.ColumnVarChar;
|
import mineplex.core.database.column.ColumnVarChar;
|
||||||
@ -23,8 +24,7 @@ public class PasswordRepository extends RepositoryBase
|
|||||||
|
|
||||||
public PasswordRepository(JavaPlugin plugin, String serverName)
|
public PasswordRepository(JavaPlugin plugin, String serverName)
|
||||||
{
|
{
|
||||||
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
|
super(plugin, DBPool.ACCOUNT);
|
||||||
|
|
||||||
_serverName = serverName;
|
_serverName = serverName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user