Added pool based repository and converted everything but account and donation repositories to it.

This commit is contained in:
Jonathan Williams 2015-01-10 11:53:25 -08:00
parent 836547f4f6
commit 8de8d31eec
16 changed files with 363 additions and 76 deletions

View File

@ -23,8 +23,8 @@ public final class DBPool
source.setUrl(url);
source.setUsername(username);
source.setPassword(password);
source.setMaxTotal(10);
source.setMaxIdle(3);
source.setMaxTotal(4);
source.setMaxIdle(2);
source.setTimeBetweenEvictionRunsMillis(180 * 1000);
source.setSoftMinEvictableIdleTimeMillis(180 * 1000);

View File

@ -66,7 +66,7 @@ public abstract class RepositoryBase implements Listener
{
try
{
if (_connection == null || !_connection.isValid(1))
if (_connection == null)
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
}
catch (SQLException e)
@ -90,7 +90,7 @@ public abstract class RepositoryBase implements Listener
try
{
if (_connection == null || !_connection.isValid(1))
if (_connection == null)
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
@ -168,7 +168,7 @@ public abstract class RepositoryBase implements Listener
try
{
if (_connection == null || !_connection.isValid(1))
if (_connection == null)
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
preparedStatement = _connection.prepareStatement(query);

View File

@ -0,0 +1,257 @@
package mineplex.core.database;
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 java.util.Iterator;
import javax.sql.DataSource;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.column.Column;
import mineplex.core.logger.Logger;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
public abstract class RepositoryPoolBase implements Listener
{
protected static Object _connectionLock = new Object();
private DataSource _dataSource = null;
private static Object _queueLock = new Object();
private NautHashMap<DatabaseRunnable, String> _failedQueue = new NautHashMap<DatabaseRunnable, String>();
protected JavaPlugin Plugin;
public RepositoryPoolBase(JavaPlugin plugin, DataSource dataSource)
{
Plugin = plugin;
_dataSource = dataSource;
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
{
public void run()
{
synchronized (_connectionLock)
{
initialize();
update();
}
}
});
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
protected abstract void initialize();
protected abstract void update();
protected DataSource getDataSource()
{
return _dataSource;
}
protected int executeUpdate(String query, Column<?>...columns)
{
return executeInsert(query, null, columns);
}
protected int executeInsert(String query, ResultSetCallable callable, Column<?>...columns)
{
PreparedStatement preparedStatement = null;
int affectedRows = 0;
try (Connection connection = _dataSource.getConnection())
{
preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
for (int i=0; i < columns.length; i++)
{
columns[i].setValue(preparedStatement, i+1);
}
affectedRows = preparedStatement.executeUpdate();
if (callable != null)
callable.processResultSet(preparedStatement.getGeneratedKeys());
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
return affectedRows;
}
protected void executeQuery(PreparedStatement statement, ResultSetCallable callable, Column<?>...columns)
{
ResultSet resultSet = null;
try
{
for (int i=0; i < columns.length; i++)
{
columns[i].setValue(statement, i+1);
}
resultSet = statement.executeQuery();
callable.processResultSet(resultSet);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (resultSet != null)
{
try
{
resultSet.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
protected void executeQuery(String query, ResultSetCallable callable, Column<?>...columns)
{
PreparedStatement preparedStatement = null;
try (Connection connection = _dataSource.getConnection())
{
preparedStatement = connection.prepareStatement(query);
executeQuery(preparedStatement, callable, columns);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
if (preparedStatement != null)
{
try
{
preparedStatement.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 (Exception exception)
{
exception.printStackTrace();
}
return affectedRows;
}
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);
}
Logger.Instance.log(errorPreMessage + runnableMessage);
}
else
{
Logger.Instance.log("Abandoning database call : " + 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

@ -5,18 +5,19 @@ import java.sql.SQLException;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
public class EloRepository extends RepositoryBase
public class EloRepository extends RepositoryPoolBase
{
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);";
public EloRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
initialize();
}

View File

@ -7,12 +7,14 @@ 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.RepositoryPoolBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.friend.FriendStatusType;
public class FriendRepository extends RepositoryBase
public class FriendRepository extends RepositoryPoolBase
{
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, serverName, tA.lastLogin, now() FROM accountFriend INNER Join accounts AS fA ON fA.uuid = uuidSource INNER JOIN accounts AS tA ON tA.uuid = uuidTarget LEFT JOIN playerMap ON tA.name = playerName WHERE uuidSource IN ";
@ -22,7 +24,7 @@ public class FriendRepository extends RepositoryBase
public FriendRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
}
@Override

View File

@ -7,14 +7,16 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.inventory.ClientInventory;
import mineplex.core.inventory.ClientItem;
public class InventoryRepository extends RepositoryBase
public class InventoryRepository extends RepositoryPoolBase
{
private static String CREATE_INVENTORY_TABLE = "CREATE TABLE IF NOT EXISTS items (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100), categoryId INT, rarity INT, PRIMARY KEY (id), FOREIGN KEY (categoryId) REFERENCES itemCategories(id), UNIQUE INDEX uniqueNameCategoryIndex (name, categoryId));";
private static String CREATE_INVENTORY_CATEGORY_TABLE = "CREATE TABLE IF NOT EXISTS itemCategories (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX nameIndex (name));";
@ -31,7 +33,7 @@ public class InventoryRepository extends RepositoryBase
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

View File

@ -38,7 +38,7 @@ public class PreferencesManager extends MiniDbClientPlugin<UserPreferences>
setupConfigValues();
_repository = new PreferencesRepository(plugin, plugin.getConfig().getString("preferences.connectionurl"));
_repository = new PreferencesRepository(plugin);
_shop = new PreferencesShop(this, clientManager, donationManager);
addCommand(new PreferencesCommand(this));

View File

@ -1,5 +1,6 @@
package mineplex.core.preferences;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -8,18 +9,19 @@ import java.util.Map.Entry;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.column.ColumnVarChar;
public class PreferencesRepository extends RepositoryBase
public class PreferencesRepository extends RepositoryPoolBase
{
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 UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ? WHERE uuid=?;";
public PreferencesRepository(JavaPlugin plugin, String connectionString)
public PreferencesRepository(JavaPlugin plugin)
{
super(plugin, connectionString, "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
}
@Override
@ -37,9 +39,9 @@ public class PreferencesRepository extends RepositoryBase
{
PreparedStatement preparedStatement = null;
try
try (Connection connection = getDataSource().getConnection())
{
preparedStatement = getConnection().prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
preparedStatement = connection.prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
for (Entry<String, UserPreferences> entry : preferences.entrySet())
{

View File

@ -51,7 +51,7 @@ public class ReportManager {
this.activeReports = new HashMap<String, Integer>();
// TODO: Get JavaPlugin instance and locate ConnectionString from config?
this.reportSqlRepository = new ReportRepository(ReportPlugin.getPlugin(), "CONNECTION STRING HERE");
this.reportSqlRepository = new ReportRepository(ReportPlugin.getPlugin());
reportSqlRepository.initialize();
}

View File

@ -1,21 +1,13 @@
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.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.preferences.UserPreferences;
import org.bukkit.plugin.java.JavaPlugin;
public class ReportRepository extends RepositoryBase
public class ReportRepository extends RepositoryPoolBase
{
/*
* *ReportTicket
@ -38,9 +30,9 @@ This will be used to determine if staff are handling
private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);";
private static String INSERT_SENDER = "INSERT INTO reportSenders (eventDate, reportId, reporterId, reason) VALUES(now(), ?, ?, ?);";
public ReportRepository(JavaPlugin plugin, String connectionString)
public ReportRepository(JavaPlugin plugin)
{
super(plugin, connectionString, "root", "tAbechAk3wR7tuTh"); // TODO: Config file for host/pass?
super(plugin, DBPool.ACCOUNT); // TODO: Config file for host/pass?
}
@Override

View File

@ -7,11 +7,13 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
public class SpawnRepository extends RepositoryBase
public class SpawnRepository extends RepositoryPoolBase
{
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 = ?;";
@ -22,7 +24,7 @@ public class SpawnRepository extends RepositoryBase
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;
}

View File

@ -138,9 +138,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
for (String statName : _statUploadQueue.get(player).keySet())
{
int statId = _stats.get(statName);
uploadQueue.get(uploadKey).put(statId, _statUploadQueue.get(player).get(statName));
System.out.println(player.getName() + " saving stat : " + statName + " adding " + _statUploadQueue.get(player).get(statName));
uploadQueue.get(uploadKey).put(_stats.get(statName), _statUploadQueue.get(player).get(statName));
}
statIterator.remove();

View File

@ -1,5 +1,6 @@
package mineplex.core.stats;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@ -9,7 +10,8 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.database.Tables;
@ -21,7 +23,7 @@ import org.jooq.Result;
import org.jooq.Update;
import org.jooq.impl.DSL;
public class StatsRepository extends RepositoryBase
public class StatsRepository extends RepositoryPoolBase
{
private static String CREATE_STAT_TABLE = "CREATE TABLE IF NOT EXISTS stats (id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100), PRIMARY KEY (id), UNIQUE INDEX nameIndex (name));";
private static String CREATE_STAT_RELATION_TABLE = "CREATE TABLE IF NOT EXISTS accountStats (id INT NOT NULL AUTO_INCREMENT, accountId INT NOT NULL, statId INT NOT NULL, value INT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id), UNIQUE INDEX accountStatIndex (accountId, statId));";
@ -31,7 +33,7 @@ public class StatsRepository extends RepositoryBase
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
@ -79,7 +81,7 @@ public class StatsRepository extends RepositoryBase
{
try
{
DSLContext context = DSL.using(getConnection());
DSLContext context = DSL.using(getDataSource().getConnection());
List<Update> updates = new ArrayList<>();
List<Insert> inserts = new ArrayList<>();
@ -130,28 +132,33 @@ public class StatsRepository extends RepositoryBase
DSLContext context;
synchronized (this)
try (Connection connection = getDataSource().getConnection())
{
context = DSL.using(getConnection());
}
Result<Record2<String, Integer>> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)
.join(Tables.stats)
.on(Tables.stats.id.eq(Tables.accountStats.statId))
.where(Tables.accountStats.accountId.eq(DSL.select(Tables.accounts.id)
.from(Tables.accounts)
.where(Tables.accounts.name.eq(playerName)))
).fetch();
context = DSL.using(connection);
if (result.isNotEmpty())
{
playerStats = new PlayerStats();
for (Record2<String, Integer> record : result)
Result<Record2<String, Integer>> result = context.select(Tables.stats.name, Tables.accountStats.value).from(Tables.accountStats)
.join(Tables.stats)
.on(Tables.stats.id.eq(Tables.accountStats.statId))
.where(Tables.accountStats.accountId.eq(DSL.select(Tables.accounts.id)
.from(Tables.accounts)
.where(Tables.accounts.name.eq(playerName)))
).fetch();
if (result.isNotEmpty())
{
playerStats.addStat(record.value1(), record.value2());
playerStats = new PlayerStats();
for (Record2<String, Integer> record : result)
{
playerStats.addStat(record.value1(), record.value2());
}
}
}
catch (Exception exception)
{
exception.printStackTrace();
}
return playerStats;
}

View File

@ -1,25 +1,29 @@
package mineplex.hub.mail;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.database.Tables;
import mineplex.database.tables.records.MailRecord;
import org.jooq.DSLContext;
import org.jooq.Result;
import org.jooq.impl.DSL;
public class MailRepository extends RepositoryBase
public class MailRepository extends RepositoryPoolBase
{
private 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;
}
@ -48,16 +52,23 @@ public class MailRepository extends RepositoryBase
{
PlayerMailData data = new PlayerMailData();
DSLContext context = DSL.using(getConnection());
Result<MailRecord> resultSet = context.selectFrom(Tables.mail).where(Tables.mail.accountId.eq(DSL.select(Tables.accounts.id)
.from(Tables.accounts)
.where(Tables.accounts.uuid.eq(uuid.toString())))
).and(Tables.mail.deleted.isFalse()).fetch();
for (MailRecord record : resultSet)
try (Connection connection = getDataSource().getConnection())
{
data.getMessages().add(createMessage(record));
DSLContext context = DSL.using(connection);
Result<MailRecord> resultSet = context.selectFrom(Tables.mail).where(Tables.mail.accountId.eq(DSL.select(Tables.accounts.id)
.from(Tables.accounts)
.where(Tables.accounts.uuid.eq(uuid.toString())))
).and(Tables.mail.deleted.isFalse()).fetch();
for (MailRecord record : resultSet)
{
data.getMessages().add(createMessage(record));
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
return data;
@ -70,9 +81,18 @@ public class MailRepository extends RepositoryBase
public boolean archive(MailMessage mailMessage)
{
DSLContext context = DSL.using(getConnection());
int recordsUpdated = 0;
int recordsUpdated = context.update(Tables.mail).set(Tables.mail.archived, (byte) 1).where(Tables.mail.id.eq(mailMessage.getMessageId())).execute();
try (Connection connection = getDataSource().getConnection())
{
DSLContext context = DSL.using(connection);
recordsUpdated = context.update(Tables.mail).set(Tables.mail.archived, (byte) 1).where(Tables.mail.id.eq(mailMessage.getMessageId())).execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
return recordsUpdated == 1;
}

View File

@ -8,7 +8,9 @@ import java.util.UUID;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
@ -16,7 +18,7 @@ import mineplex.core.database.column.ColumnVarChar;
/**
* Created by Shaun on 8/16/2014.
*/
public class PollRepository extends RepositoryBase
public class PollRepository extends RepositoryPoolBase
{
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, 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));";
@ -28,7 +30,7 @@ public class PollRepository extends RepositoryBase
public PollRepository(JavaPlugin plugin)
{
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
super(plugin, DBPool.ACCOUNT);
}
@Override

View File

@ -7,11 +7,13 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
public class PasswordRepository extends RepositoryBase
public class PasswordRepository extends RepositoryPoolBase
{
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 = ?;";
@ -23,7 +25,7 @@ public class PasswordRepository extends RepositoryBase
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;
}