Use DBPool for everything

This commit is contained in:
Shaun Bennett 2016-02-19 00:17:38 -06:00
parent eab992e621
commit 7714e4960c
56 changed files with 434 additions and 444 deletions

View File

@ -10,14 +10,13 @@ import java.util.UUID;
import mineplex.bungee.playerStats.data.IpInfo;
import mineplex.cache.player.PlayerInfo;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
public class PlayerStatsRepository
import javax.sql.DataSource;
public class PlayerStatsRepository extends RepositoryBase
{
private Connection _connection = null;
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String INSERT_PLAYERINFO = "INSERT INTO playerInfo (uuid, name, version) VALUES (?, ?, ?);";
private static String SELECT_PLAYERINFO = "SELECT id, name, version FROM playerInfo WHERE uuid = ?;";
private static String UPDATE_PLAYERINFO = "UPDATE playerInfo SET name = ?, version = ? WHERE id = ?;";
@ -31,19 +30,21 @@ public class PlayerStatsRepository
private static String UPDATE_LOGINSESSION = "UPDATE playerLoginSessions SET timeInGame = TIME_TO_SEC(TIMEDIFF(now(), loginTime)) / 60 WHERE id = ?;";
public void initialize()
public PlayerStatsRepository()
{
try
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
catch (Exception exception)
{
exception.printStackTrace();
super(DBPool.getStats());
}
System.out.println("Initialized PlayerStats.");
@Override
public void initialize()
{
}
@Override
protected void update()
{
}
public PlayerInfo getPlayer(UUID uuid, String name, int version)
@ -52,12 +53,9 @@ public class PlayerStatsRepository
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(SELECT_PLAYERINFO);
preparedStatement = connection.prepareStatement(SELECT_PLAYERINFO);
preparedStatement.setString(1, uuid.toString());
@ -73,7 +71,7 @@ public class PlayerStatsRepository
if (playerInfo == null)
{
preparedStatement = _connection.prepareStatement(INSERT_PLAYERINFO, Statement.RETURN_GENERATED_KEYS);
preparedStatement = connection.prepareStatement(INSERT_PLAYERINFO, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, uuid.toString());
preparedStatement.setString(2, name);
preparedStatement.setInt(3, version);
@ -96,7 +94,7 @@ public class PlayerStatsRepository
}
else if (!playerInfo.getName().equalsIgnoreCase(name) || playerInfo.getVersion() != version)
{
preparedStatement = _connection.prepareStatement(UPDATE_PLAYERINFO);
preparedStatement = connection.prepareStatement(UPDATE_PLAYERINFO);
preparedStatement.setString(1, name);
preparedStatement.setInt(2, version);
preparedStatement.setInt(3, playerInfo.getId());
@ -145,12 +143,9 @@ public class PlayerStatsRepository
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(SELECT_IPINFO);
preparedStatement = connection.prepareStatement(SELECT_IPINFO);
preparedStatement.setString(1, ipAddress);
resultSet = preparedStatement.executeQuery();
@ -167,7 +162,7 @@ public class PlayerStatsRepository
if (ipInfo == null)
{
preparedStatement = _connection.prepareStatement(INSERT_IPINFO, Statement.RETURN_GENERATED_KEYS);
preparedStatement = connection.prepareStatement(INSERT_IPINFO, Statement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, ipAddress);
preparedStatement.executeUpdate();
@ -228,12 +223,9 @@ public class PlayerStatsRepository
Statement statement = null;
ResultSet resultSet= null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
statement = _connection.createStatement();
statement = connection.createStatement();
String queryString = UPDATE_PLAYERSTATS;
queryString = queryString.replaceFirst("\\?", playerId + "");
@ -286,12 +278,9 @@ public class PlayerStatsRepository
{
PreparedStatement preparedStatement = null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(UPDATE_LOGINSESSION);
preparedStatement = connection.prepareStatement(UPDATE_LOGINSESSION);
preparedStatement.setInt(1, loginSessionId);
preparedStatement.executeUpdate();

View File

@ -1,36 +1,32 @@
package mineplex.bungee;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class PlayerStatsRepository
public class PlayerStatsRepository extends RepositoryBase
{
private Connection _connection = null;
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/PlayerStats?autoReconnect=true&failOverReadOnly=false&maxReconnects=10&allowMultiQueries=true";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String SELECT_IPINFO = "SELECT id, ipAddress FROM ipInfo WHERE regionName IS NULL LIMIT 1000;";
private static String UPDATE_IPINFO = "UPDATE ipInfo SET countryCode = ?, countryName = ?, regionCode = ?, regionName = ?, city = ?, zipCode = ?, timeZone = ?, latitude = ?, longitude = ?, metroCode = ? WHERE id = ?;";
public void initialize()
public PlayerStatsRepository()
{
try
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
catch (Exception exception)
{
exception.printStackTrace();
super(DBPool.getStats());
}
System.out.println("Initialized PlayerStats.");
@Override
protected void initialize()
{
}
@Override
protected void update()
{
}
public List<IpInfo> getIpAddresses()
@ -39,12 +35,9 @@ public class PlayerStatsRepository
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(SELECT_IPINFO);
preparedStatement = connection.prepareStatement(SELECT_IPINFO);
resultSet = preparedStatement.executeQuery();
@ -98,12 +91,9 @@ public class PlayerStatsRepository
{
PreparedStatement preparedStatement = null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(UPDATE_IPINFO);
preparedStatement = connection.prepareStatement(UPDATE_IPINFO);
for (IpInfo ipInfo : ips)
{

View File

@ -10,6 +10,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.Bukkit;
import com.google.gson.reflect.TypeToken;
import org.bukkit.plugin.java.JavaPlugin;
@ -21,16 +22,16 @@ import mineplex.core.account.repository.token.RankUpdateToken;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.DatabaseRunnable;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnBoolean;
import mineplex.core.database.column.ColumnTimestamp;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.DatabaseRunnable;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnBoolean;
import mineplex.serverdata.database.column.ColumnTimestamp;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.core.server.remotecall.JsonWebCall;
public class AccountRepository extends RepositoryBase
public class AccountRepository extends MinecraftRepository
{
private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));";
private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now());";
@ -234,7 +235,7 @@ public class AccountRepository extends RepositoryBase
executeUpdate(UPDATE_ACCOUNT_RANK, new ColumnVarChar("rank", 100, rank.toString()), new ColumnVarChar("uuid", 100, uuid.toString()));
}
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
{
@Override
public void run()

View File

@ -4,7 +4,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import mineplex.core.database.DBPool;
import mineplex.serverdata.database.DBPool;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;

View File

@ -3,14 +3,15 @@ package mineplex.core.benefit;
import java.sql.ResultSet;
import java.sql.SQLException;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import org.bukkit.plugin.java.JavaPlugin;
public class BenefitManagerRepository extends RepositoryBase
public class BenefitManagerRepository extends MinecraftRepository
{
private static String CREATE_BENEFIT_TABLE = "CREATE TABLE IF NOT EXISTS rankBenefits (id INT NOT NULL AUTO_INCREMENT, accountId INT, benefit VARCHAR(100), PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));";

View File

@ -27,7 +27,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.database.DBPool;
import mineplex.serverdata.database.DBPool;
import mineplex.core.donation.DonationManager;
import mineplex.core.donation.GiveDonorData;
import mineplex.core.facebook.FacebookManager;
@ -67,7 +67,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

View File

@ -10,9 +10,10 @@ import java.sql.Types;
import mineplex.core.common.Pair;
import mineplex.core.common.util.Callback;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.core.donation.DonationManager;
import mineplex.core.recharge.Recharge;
import mineplex.database.Tables;
@ -28,7 +29,7 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class BonusRepository extends RepositoryBase
public class BonusRepository extends MinecraftRepository
{
private static String CREATE_BONUS_TABLE = "CREATE TABLE IF NOT EXISTS bonus (accountId INT NOT NULL AUTO_INCREMENT, dailytime TIMESTAMP NULL DEFAULT NULL, ranktime DATE NULL DEFAULT NULL, PRIMARY KEY (accountId), FOREIGN KEY (accountId) REFERENCES accounts(id));";
private BonusManager _manager;

View File

@ -4,16 +4,17 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.core.botspam.SpamText;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
public class BotSpamRepository extends RepositoryBase
public class BotSpamRepository extends MinecraftRepository
{
private static final String GET_SPAM_TEXT = "SELECT * FROM botSpam";
private static final String ADD_SPAM_TEXT = "INSERT INTO botSpam (text, createdBy, enabledBy) VALUES (?, ?, ?)";

View File

@ -5,24 +5,24 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
import org.bukkit.entity.Player;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.customdata.CustomData;
import mineplex.core.customdata.CustomDataManager;
import mineplex.core.customdata.PlayerCustomData;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
/**
* Created by William (WilliamTiger).
* 16/12/15
*/
public class CustomDataRepository extends RepositoryBase
public class CustomDataRepository extends MinecraftRepository
{
private static final String SELECT_KEYS = "SELECT id, name FROM customData;";
private static final String INSERT_KEY = "INSERT INTO customData (name) VALUES (?);";

View File

@ -0,0 +1,112 @@
package mineplex.core.database;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import javax.sql.DataSource;
import mineplex.core.common.util.NautHashMap;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.DatabaseRunnable;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.Column;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public abstract class MinecraftRepository extends RepositoryBase implements Listener
{
// Queue for failed processes
private static Object _queueLock = new Object();
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
protected JavaPlugin _plugin; // Plugin responsible for this repository
/**
* 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 MinecraftRepository(JavaPlugin plugin, DataSource dataSource)
{
super(dataSource);
_plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
protected DSLContext jooq()
{
return DSL.using(DBPool.getAccount(), SQLDialect.MYSQL);
}
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
{
Thread asyncThread = new Thread(new Runnable()
{
public void run()
{
try
{
databaseRunnable.run();
}
catch (Exception exception)
{
processFailedDatabaseCall(databaseRunnable, exception.getMessage(), errorMessage);
}
}
});
asyncThread.start();
}
protected void processFailedDatabaseCall(DatabaseRunnable databaseRunnable, String errorPreMessage, String runnableMessage)
{
if (databaseRunnable.getFailedCounts() < 4)
{
databaseRunnable.incrementFailCount();
synchronized (_queueLock)
{
_failedQueue.put(databaseRunnable, runnableMessage);
}
}
}
@EventHandler
public void processDatabaseQueue(UpdateEvent event)
{
if (event.getType() != UpdateType.MIN_01)
return;
processFailedQueue();
}
private void processFailedQueue()
{
synchronized (_queueLock)
{
for (Iterator<DatabaseRunnable> runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();)
{
DatabaseRunnable databaseRunnable = runnablesIterator.next();
handleDatabaseCall(databaseRunnable, _failedQueue.get(databaseRunnable));
}
}
}
public JavaPlugin getPlugin()
{
return _plugin;
}
}

View File

@ -1,9 +0,0 @@
package mineplex.core.database;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.column.Column;
public class Row
{
public NautHashMap<String, Column<?>> Columns = new NautHashMap<String, Column<?>>();
}

View File

@ -1,21 +1,18 @@
package mineplex.core.donation.repository;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.util.Callback;
import mineplex.core.database.DBPool;
import mineplex.core.database.DatabaseRunnable;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.DatabaseRunnable;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.core.donation.Donor;
import mineplex.core.donation.repository.token.GemRewardToken;
import mineplex.core.donation.repository.token.PurchaseToken;
@ -24,7 +21,7 @@ import mineplex.core.server.remotecall.AsyncJsonWebCall;
import mineplex.core.server.remotecall.JsonWebCall;
import mineplex.core.server.util.TransactionResponse;
public class DonationRepository extends RepositoryBase
public class DonationRepository extends MinecraftRepository
{
private static String CREATE_COIN_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountCoinTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), coins INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));";
private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accountId INT, reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id));";
@ -54,7 +51,7 @@ public class DonationRepository extends RepositoryBase
{
public void run(final TransactionResponse response)
{
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
{
@Override
public void run()
@ -100,7 +97,7 @@ public class DonationRepository extends RepositoryBase
}
}
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
{
@Override
public void run()
@ -131,7 +128,7 @@ public class DonationRepository extends RepositoryBase
{
public void run(final Boolean response)
{
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
{
@Override
public void run()
@ -168,7 +165,7 @@ public class DonationRepository extends RepositoryBase
//executeUpdate(INSERT_COIN_TRANSACTION, new ColumnInt("id", accountId), new ColumnVarChar("reason", 100, "Rewarded by " + giver), new ColumnInt("coins", coins));
}
Bukkit.getServer().getScheduler().runTask(Plugin, new Runnable()
Bukkit.getServer().getScheduler().runTask(getPlugin(), new Runnable()
{
@Override
public void run()

View File

@ -3,14 +3,15 @@ package mineplex.core.elo;
import java.sql.ResultSet;
import java.sql.SQLException;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
public class EloRepository extends RepositoryBase
public class EloRepository extends MinecraftRepository
{
private static String CREATE_ELO_TABLE = "CREATE TABLE IF NOT EXISTS eloRating (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), gameType VARCHAR(256), elo INT, PRIMARY KEY (id), UNIQUE INDEX uuid_gameType_index (uuid, gameType));";
private static String INSERT_ELO = "INSERT INTO eloRating (uuid, gameType, elo) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE elo=VALUES(elo);";

View File

@ -3,16 +3,17 @@ package mineplex.core.facebook;
import java.sql.ResultSet;
import java.sql.SQLException;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.Callback;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
public class FacebookRepository extends RepositoryBase
public class FacebookRepository extends MinecraftRepository
{
private static final String GET_CODE = "SELECT code, activated FROM facebook WHERE code = ?";
private static final String ACTIVATE_CODE = "UPDATE facebook SET activated = 1, accountId = ?, activationTime = NOW() WHERE code = ?";

View File

@ -5,18 +5,18 @@ import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.core.friend.FriendStatusType;
import mineplex.serverdata.Region;
import mineplex.serverdata.data.DataRepository;
@ -24,7 +24,7 @@ import mineplex.serverdata.data.PlayerStatus;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ServerManager;
public class FriendRepository extends RepositoryBase
public class FriendRepository extends MinecraftRepository
{
private static String CREATE_FRIEND_TABLE = "CREATE TABLE IF NOT EXISTS accountFriend (id INT NOT NULL AUTO_INCREMENT, uuidSource VARCHAR(100), uuidTarget VARCHAR(100), status VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuidSource, uuidTarget));";
private static String RETRIEVE_MULTIPLE_FRIEND_RECORDS = "SELECT uuidSource, tA.Name, status, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget WHERE uuidSource IN ";

View File

@ -8,17 +8,17 @@ import java.sql.Types;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.Bukkit;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.serverdata.Region;
public class GiveawayRepository extends RepositoryBase
public class GiveawayRepository extends MinecraftRepository
{
private static final String INSERT_GIVEAWAY = "INSERT INTO Account.accountGiveaway (giveawayId, accountId, cooldownId, region, serverName, time, uuid) VALUES (?, ?, ?, ?, ?, now(), ?)";
private static final String LOAD_GIVEAWAY = "SELECT id, name, prettyName, header, message, max, notifyNetwork, notifyCooldown, canWinTwice FROM Account.giveaway WHERE enabled = TRUE";

View File

@ -3,14 +3,15 @@ package mineplex.core.ignore.data;
import java.sql.ResultSet;
import java.sql.SQLException;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnVarChar;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class IgnoreRepository extends RepositoryBase
public class IgnoreRepository extends MinecraftRepository
{
private static String ADD_IGNORE_RECORD = "INSERT INTO accountIgnore (uuidIgnorer, uuidIgnored) SELECT fA.uuid AS uuidIgnorer, tA.uuid AS uuidIgnored FROM accounts as fA LEFT JOIN accounts AS tA ON tA.name = ? WHERE fA.name = ?;";
private static String DELETE_IGNORE_RECORD = "DELETE aF FROM accountIgnore AS aF INNER JOIN accounts as fA ON aF.uuidIgnorer = fA.uuid INNER JOIN accounts AS tA ON aF.uuidIgnored = tA.uuid WHERE fA.name = ? AND tA.name = ?;";

View File

@ -5,18 +5,19 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.core.inventory.ClientInventory;
import mineplex.core.inventory.ClientItem;
public class InventoryRepository extends RepositoryBase
public class InventoryRepository extends MinecraftRepository
{
private static String CREATE_INVENTORY_TABLE = "CREATE TABLE IF NOT EXISTS items (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100), rarity INT, PRIMARY KEY (id), INDEX mameIndex (name));";
private static String CREATE_INVENTORY_RELATION_TABLE = "CREATE TABLE IF NOT EXISTS accountInventory (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, itemId INT NOT NULL, count INT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (itemId) REFERENCES items(id), UNIQUE INDEX accountItemIndex (accountId, itemId));";

View File

@ -1,9 +1,10 @@
package mineplex.core.leaderboard;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import org.bukkit.plugin.java.JavaPlugin;
@ -15,7 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin;
* @author MrTwiggy
*
*/
public class StatEventsRepository extends RepositoryBase
public class StatEventsRepository extends MinecraftRepository
{
// Insert or update stat events query

View File

@ -38,7 +38,7 @@ import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.creature.Creature;
import mineplex.core.creature.event.CreatureKillEntitiesEvent;
import mineplex.core.database.DBPool;
import mineplex.serverdata.database.DBPool;
import mineplex.core.npc.command.NpcCommand;
import mineplex.core.npc.event.NpcDamageByEntityEvent;
import mineplex.core.npc.event.NpcInteractEntityEvent;

View File

@ -2,21 +2,21 @@ package mineplex.core.pet.repository;
import java.util.List;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import com.google.gson.reflect.TypeToken;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.core.pet.repository.token.PetChangeToken;
import mineplex.core.pet.repository.token.PetExtraToken;
import mineplex.core.pet.repository.token.PetSalesToken;
import mineplex.core.server.remotecall.AsyncJsonWebCall;
import mineplex.core.server.remotecall.JsonWebCall;
public class PetRepository extends RepositoryBase
public class PetRepository extends MinecraftRepository
{
private String _webAddress;
@ -31,7 +31,7 @@ public class PetRepository extends RepositoryBase
{
new AsyncJsonWebCall(_webAddress + "Pets/AddPet").Execute(token);
Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable()
getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
{
@ -49,7 +49,7 @@ public class PetRepository extends RepositoryBase
{
new AsyncJsonWebCall(_webAddress + "Pets/RemovePet").Execute(token);
Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable()
getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
{
@ -72,7 +72,7 @@ public class PetRepository extends RepositoryBase
{
new AsyncJsonWebCall(_webAddress + "Pets/UpdatePet").Execute(token);
Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable()
getPlugin().getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
{

View File

@ -6,18 +6,19 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
/**
* Created by Shaun on 8/16/2014.
*/
public class PollRepository extends RepositoryBase
public class PollRepository extends MinecraftRepository
{
private static String CREATE_POLL_TABLE = "CREATE TABLE IF NOT EXISTS polls (id INT NOT NULL AUTO_INCREMENT, enabled BIT(1), question VARCHAR(256) NOT NULL, answerA VARCHAR(256) NOT NULL, answerB VARCHAR(256), answerC VARCHAR(256), answerD VARCHAR(256), coinReward INT NOT NULL, displayType INT DEFAULT 0 NOT NULL, PRIMARY KEY (id));";
private static String CREATE_RELATION_TABLE = "CREATE TABLE IF NOT EXISTS accountPolls (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, pollId INT NOT NULL, value TINYINT(1) NOT NULL, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (pollId) REFERENCES polls(id), UNIQUE INDEX accountPollIndex (accountId, pollId));";

View File

@ -6,14 +6,15 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map.Entry;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnVarChar;
public class PreferencesRepository extends RepositoryBase
public class PreferencesRepository extends MinecraftRepository
{
// private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS
// accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256),

View File

@ -1,22 +1,14 @@
package mineplex.core.report;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import java.util.Map.Entry;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.preferences.UserPreferences;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import org.bukkit.plugin.java.JavaPlugin;
public class ReportRepository extends RepositoryBase
public class ReportRepository extends MinecraftRepository
{
/*
* *ReportTicket

View File

@ -5,14 +5,15 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnVarChar;
public class SpawnRepository extends RepositoryBase
public class SpawnRepository extends MinecraftRepository
{
private static String CREATE_SPAWN_TABLE = "CREATE TABLE IF NOT EXISTS spawns (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(100), location VARCHAR(100), PRIMARY KEY (id), INDEX serverNameIndex (serverName));";
private static String RETRIEVE_SPAWNS = "SELECT location FROM spawns WHERE serverName = ?;";

View File

@ -7,10 +7,11 @@ import java.util.Collections;
import java.util.List;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.database.Tables;
import org.bukkit.plugin.java.JavaPlugin;
@ -23,7 +24,7 @@ import org.jooq.Update;
import org.jooq.impl.DSL;
import org.jooq.types.ULong;
public class StatsRepository extends RepositoryBase
public class StatsRepository extends MinecraftRepository
{
private static String RETRIEVE_STATS = "SELECT id, name FROM stats;";
private static String INSERT_STAT = "INSERT INTO stats (name) VALUES (?);";

View File

@ -5,17 +5,18 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.core.task.Task;
import mineplex.core.task.TaskClient;
public class TaskRepository extends RepositoryBase
public class TaskRepository extends MinecraftRepository
{
private static String ADD_ACCOUNT_TASK = "INSERT INTO accountTasks (accountId, taskId) VALUES (?, ?);";

View File

@ -4,15 +4,16 @@ import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.serverdata.Region;
public class TitanGiveawayRepository extends RepositoryBase
public class TitanGiveawayRepository extends MinecraftRepository
{
private static final String ADD_TITAN = "INSERT INTO titanGiveaway (accountId, region, serverName) VALUES (?, ?, ?)";

View File

@ -1,11 +1,12 @@
package mineplex.core.valentines;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import org.bukkit.plugin.java.JavaPlugin;
public class ValentinesGiftRepository extends RepositoryBase
public class ValentinesGiftRepository extends MinecraftRepository
{
private String GIVE_GIFT = "INSERT INTO accountValentinesGift (senderId, targetId) VALUES (?, ?);";

View File

@ -1,13 +1,14 @@
package mineplex.enjinTranslator;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
public class TempRepository extends RepositoryBase
public class TempRepository extends MinecraftRepository
{
private static String INSERT_CLIENT_INVENTORY = "INSERT INTO accountInventory (accountId, itemId, count) SELECT accounts.id, 5, ? FROM accounts WHERE accounts.name = ? ON DUPLICATE KEY UPDATE count=count + VALUES(count);";

View File

@ -9,7 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.ResultSetCallable;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.enjinTranslator.purchase.data.PurchaseRepository;
import mineplex.enjinTranslator.purchase.data.Package;

View File

@ -5,16 +5,17 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnBoolean;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnBoolean;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
public class PurchaseRepository extends RepositoryBase
public class PurchaseRepository extends MinecraftRepository
{
private static String INSERT_ACCOUNT_PURCHASE = "INSERT INTO accountPurchases (accountId, packageId, amount, date, success) VALUES (?, ?, ?, now(), ?);";

View File

@ -11,14 +11,15 @@ import java.util.UUID;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.Column;
import mineplex.core.database.column.ColumnBoolean;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnTimestamp;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.Column;
import mineplex.serverdata.database.column.ColumnBoolean;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnTimestamp;
import mineplex.serverdata.database.column.ColumnVarChar;
import mineplex.database.tables.records.ClansRecord;
import mineplex.game.clans.core.repository.tokens.ClanAllianceToken;
import mineplex.game.clans.core.repository.tokens.ClanMemberToken;
@ -36,7 +37,7 @@ import org.jooq.DSLContext;
import static mineplex.database.Tables.*;
import static org.jooq.impl.DSL.*;
public class ClanRepository extends RepositoryBase
public class ClanRepository extends MinecraftRepository
{
private static String CREATE_CLAN_TABLE = "CREATE TABLE IF NOT EXISTS clans (id INT NOT NULL AUTO_INCREMENT, serverId INT NOT NULL, name VARCHAR(100), description VARCHAR(140), home VARCHAR(140), admin BIT(1), dateCreated DATETIME, lastOnline DATETIME, energy INT, PRIMARY KEY (id), INDEX clanName (name));";
private static String CREATE_ACCOUNT_CLAN_TABLE = "CREATE TABLE IF NOT EXISTS accountClan (id INT NOT NULL AUTO_INCREMENT, accountId INT, clanId INT, clanRole VARCHAR(140), PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (clanId) REFERENCES clans(id), INDEX clanIdIndex (clanId));";

View File

@ -6,20 +6,21 @@ import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.account.CoreClient;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NonFinalInteger;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnBoolean;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnTimestamp;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnBoolean;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnTimestamp;
import mineplex.serverdata.database.column.ColumnVarChar;
public class ClansBanRepository extends RepositoryBase
public class ClansBanRepository extends MinecraftRepository
{
private ClansBanManager _manager;

View File

@ -5,17 +5,18 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnByte;
import mineplex.core.database.column.ColumnDouble;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnByte;
import mineplex.serverdata.database.column.ColumnDouble;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
public class FieldRepository extends RepositoryBase
public class FieldRepository extends MinecraftRepository
{
private static String ALL_STRING = "ALL";

View File

@ -1,20 +1,12 @@
package mineplex.hub;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.serverdata.database.DBPool;
public class HubRepository
{

View File

@ -4,10 +4,11 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.database.Tables;
import mineplex.database.tables.records.MailRecord;
@ -15,7 +16,7 @@ import org.jooq.DSLContext;
import org.jooq.Result;
import org.jooq.impl.DSL;
public class MailRepository extends RepositoryBase
public class MailRepository extends MinecraftRepository
{
private MailManager _manager;

View File

@ -1,14 +1,12 @@
package mineplex.hub.queue;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import mineplex.core.common.util.C;
import mineplex.core.database.DBPool;
import mineplex.serverdata.database.DBPool;
public class QueueRepository
{

View File

@ -20,5 +20,10 @@
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
</project>

View File

@ -1,4 +1,4 @@
package mineplex.core.database;
package mineplex.serverdata.database;
import javax.sql.DataSource;
@ -6,15 +6,10 @@ import java.io.File;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.dbcp2.BasicDataSource;
import mineplex.serverdata.redis.RedisConfig;
import mineplex.serverdata.servers.ConnectionData;
import mineplex.serverdata.servers.ConnectionData.ConnectionType;
public final class DBPool
{
private static DataSource ACCOUNT;

View File

@ -1,4 +1,4 @@
package mineplex.core.database;
package mineplex.serverdata.database;
public class DatabaseRunnable
{

View File

@ -1,57 +1,31 @@
package mineplex.core.database;
package mineplex.serverdata.database;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import javax.sql.DataSource;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.column.Column;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import mineplex.serverdata.database.column.Column;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public abstract class RepositoryBase implements Listener
public abstract class RepositoryBase
{
// Queue for failed processes
private static Object _queueLock = new Object();
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
private DataSource _dataSource; // Connection pool
protected JavaPlugin Plugin; // Plugin responsible for this repository
/**
* 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(DataSource dataSource)
{
Plugin = plugin;
_dataSource = dataSource;
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
{
public void run()
{
new Thread(() -> {
initialize();
update();
}
});
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}).start();
}
protected abstract void initialize();
@ -66,11 +40,6 @@ public abstract class RepositoryBase implements Listener
return _dataSource;
}
protected DSLContext jooq()
{
return DSL.using(DBPool.getAccount(), SQLDialect.MYSQL);
}
/**
* Requirements: {@link Connection}s must be closed after usage so they may be returned to the pool!
* @see Connection#close()
@ -178,58 +147,4 @@ public abstract class RepositoryBase implements Listener
exception.printStackTrace();
}
}
protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage)
{
Thread asyncThread = new Thread(new Runnable()
{
public void run()
{
try
{
databaseRunnable.run();
}
catch (Exception exception)
{
processFailedDatabaseCall(databaseRunnable, exception.getMessage(), errorMessage);
}
}
});
asyncThread.start();
}
protected void processFailedDatabaseCall(DatabaseRunnable databaseRunnable, String errorPreMessage, String runnableMessage)
{
if (databaseRunnable.getFailedCounts() < 4)
{
databaseRunnable.incrementFailCount();
synchronized (_queueLock)
{
_failedQueue.put(databaseRunnable, runnableMessage);
}
}
}
@EventHandler
public void processDatabaseQueue(UpdateEvent event)
{
if (event.getType() != UpdateType.MIN_01)
return;
processFailedQueue();
}
private void processFailedQueue()
{
synchronized (_queueLock)
{
for (Iterator<DatabaseRunnable> runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();)
{
DatabaseRunnable databaseRunnable = runnablesIterator.next();
handleDatabaseCall(databaseRunnable, _failedQueue.get(databaseRunnable));
}
}
}
}

View File

@ -1,4 +1,4 @@
package mineplex.core.database;
package mineplex.serverdata.database;
import java.sql.ResultSet;
import java.sql.SQLException;

View File

@ -1,4 +1,4 @@
package mineplex.core.database.column;
package mineplex.serverdata.database.column;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

View File

@ -1,4 +1,4 @@
package mineplex.core.database.column;
package mineplex.serverdata.database.column;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

View File

@ -1,4 +1,4 @@
package mineplex.core.database.column;
package mineplex.serverdata.database.column;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

View File

@ -1,4 +1,4 @@
package mineplex.core.database.column;
package mineplex.serverdata.database.column;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

View File

@ -1,4 +1,4 @@
package mineplex.core.database.column;
package mineplex.serverdata.database.column;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

View File

@ -1,4 +1,4 @@
package mineplex.core.database.column;
package mineplex.serverdata.database.column;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

View File

@ -1,4 +1,4 @@
package mineplex.core.database.column;
package mineplex.serverdata.database.column;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

View File

@ -1,4 +1,4 @@
package mineplex.core.database.column;
package mineplex.serverdata.database.column;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

View File

@ -1,7 +1,6 @@
package mineplex.servermonitor;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
@ -14,15 +13,13 @@ import mineplex.serverdata.data.BungeeServer;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.data.DedicatedServer;
import mineplex.serverdata.data.ServerGroup;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ServerManager;
public class StatusHistoryRepository
public class StatusHistoryRepository extends RepositoryBase
{
private String _connectionString = "jdbc:mysql://sqlstats.mineplex.com:3306/ServerStats";
private String _userName = "root";
private String _password = "tAbechAk3wR7tuTh";
private static String CREATE_GROUP_TABLE = "CREATE TABLE IF NOT EXISTS ServerGroupStats (id INT NOT NULL AUTO_INCREMENT, serverGroup VARCHAR(100), updated LONG, players INT, maxPlayers INT, totalNetworkCpuUsage DOUBLE(4,2), totalNetworkRamUsage DOUBLE(4,2), totalCpu MEDIUMINT, totalRam MEDIUMINT, US BOOLEAN NOT NULL DEFAULT '1', PRIMARY KEY (id));";
private static String CREATE_DEDICATED_TABLE = "CREATE TABLE IF NOT EXISTS DedicatedServerStats (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(100), address VARCHAR(25), updated LONG, cpu TINYINT, ram MEDIUMINT, usedCpuPercent DOUBLE(4,2), usedRamPercent DOUBLE(4,2), US BOOLEAN NOT NULL DEFAULT '1', PRIMARY KEY (id));";
private static String CREATE_BUNGEE_TABLE = "CREATE TABLE IF NOT EXISTS BungeeStats (id INT NOT NULL AUTO_INCREMENT, address VARCHAR(25), updated LONG, players INT, maxPlayers INT, alive BOOLEAN NOT NULL, online BOOLEAN NOT NULL, US BOOLEAN NOT NULL DEFAULT '1', PRIMARY KEY (id));";
@ -33,38 +30,33 @@ public class StatusHistoryRepository
private static String INSERT_BUNGEE_STATS = "INSERT INTO BungeeStats (address, updated, players, maxPlayers, alive, online, US) VALUES (?, now(), ?, ?, ?, ?, ?);";
private static String INSERT_NETWORK_STATS = "INSERT INTO NetworkStats (updated, players, totalNetworkCpuUsage, totalNetworkRamUsage, totalCpu, totalRam, US) VALUES (now(), ?, ?, ?, ?, ?, ?);";
private static Connection _connection;
private static DataRepository<BungeeServer> _repository;
public StatusHistoryRepository()
{
super(DBPool.getStats());
PreparedStatement preparedStatement = null;
try
try(Connection connection = getConnection())
{
Class.forName("com.mysql.jdbc.Driver");
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
// Create table
preparedStatement = _connection.prepareStatement(CREATE_GROUP_TABLE);
preparedStatement = connection.prepareStatement(CREATE_GROUP_TABLE);
preparedStatement.execute();
preparedStatement.close();
// Create table
preparedStatement = _connection.prepareStatement(CREATE_DEDICATED_TABLE);
preparedStatement = connection.prepareStatement(CREATE_DEDICATED_TABLE);
preparedStatement.execute();
preparedStatement.close();
// Create table
preparedStatement = _connection.prepareStatement(CREATE_BUNGEE_TABLE);
preparedStatement = connection.prepareStatement(CREATE_BUNGEE_TABLE);
preparedStatement.execute();
preparedStatement.close();
// Create table
preparedStatement = _connection.prepareStatement(CREATE_NETWORKSTATS_TABLE);
preparedStatement = connection.prepareStatement(CREATE_NETWORKSTATS_TABLE);
preparedStatement.execute();
preparedStatement.close();
@ -95,12 +87,9 @@ public class StatusHistoryRepository
{
PreparedStatement preparedStatement = null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(INSERT_SERVERGROUP_STATS);
preparedStatement = connection.prepareStatement(INSERT_SERVERGROUP_STATS);
for (ServerGroup serverGroup : collection)
{
@ -144,12 +133,9 @@ public class StatusHistoryRepository
{
PreparedStatement preparedStatement = null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(INSERT_DEDICATEDSERVER_STATS);
preparedStatement = connection.prepareStatement(INSERT_DEDICATEDSERVER_STATS);
for (DedicatedServer dedicatedServer : dedicatedServers)
{
@ -204,12 +190,9 @@ public class StatusHistoryRepository
PreparedStatement preparedStatement = null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(INSERT_BUNGEE_STATS);
preparedStatement = connection.prepareStatement(INSERT_BUNGEE_STATS);
for (BungeeServer bungeeStatusData : bungeeServers)
{
@ -246,12 +229,9 @@ public class StatusHistoryRepository
preparedStatement = null;
try
try(Connection connection = getConnection())
{
if (_connection == null || _connection.isClosed())
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(INSERT_NETWORK_STATS);
preparedStatement = connection.prepareStatement(INSERT_NETWORK_STATS);
preparedStatement.setInt(1, totalPlayers);
preparedStatement.setDouble(2, usedCpuPercent);
preparedStatement.setDouble(3, usedRamPercent);
@ -280,4 +260,16 @@ public class StatusHistoryRepository
}
}
}
@Override
protected void initialize()
{
}
@Override
protected void update()
{
}
}

View File

@ -5,14 +5,15 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import mineplex.core.database.MinecraftRepository;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnVarChar;
public class PasswordRepository extends RepositoryBase
public class PasswordRepository extends MinecraftRepository
{
private static String CREATE_SERVER_PASSWORD_TABLE = "CREATE TABLE IF NOT EXISTS serverPassword (id INT NOT NULL AUTO_INCREMENT, server VARCHAR(100), password VARCHAR(100), PRIMARY KEY (id));";
private static String RETRIEVE_SERVER_PASSWORD = "SELECT password FROM serverPassword WHERE server = ?;";

View File

@ -11,12 +11,11 @@ import com.vexsoftware.votifier.model.VotifierEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.bonuses.BonusAmount;
import mineplex.core.bonuses.BonusClientData;
import mineplex.core.bonuses.BonusManager;
import mineplex.core.common.Pair;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.database.DBPool;
import mineplex.serverdata.database.DBPool;
import mineplex.core.donation.DonationManager;
import mineplex.core.bonuses.redis.VotifierCommand;
import mineplex.database.Tables;

View File

@ -4,12 +4,13 @@ import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.Types;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.MinecraftRepository;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
import org.bukkit.plugin.java.JavaPlugin;
public class TitanGiveawayRepository extends RepositoryBase
public class TitanGiveawayRepository extends MinecraftRepository
{
private int _titanGiveawayCount;