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

This reverts commit 8de8d31eec.
This commit is contained in:
Jonathan Williams 2015-01-11 00:41:40 -08:00
parent 0a99a9aa40
commit 47fc6e3b94
15 changed files with 74 additions and 361 deletions

View File

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

View File

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

View File

@ -7,14 +7,12 @@ 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 RepositoryPoolBase
public class FriendRepository extends RepositoryBase
{
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 ";
@ -24,7 +22,7 @@ public class FriendRepository extends RepositoryPoolBase
public FriendRepository(JavaPlugin plugin)
{
super(plugin, DBPool.ACCOUNT);
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
}
@Override

View File

@ -7,16 +7,14 @@ 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 RepositoryPoolBase
public class InventoryRepository extends RepositoryBase
{
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));";
@ -33,7 +31,7 @@ public class InventoryRepository extends RepositoryPoolBase
public InventoryRepository(JavaPlugin plugin)
{
super(plugin, DBPool.ACCOUNT);
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
}
@Override

View File

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

View File

@ -1,6 +1,5 @@
package mineplex.core.preferences;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@ -9,19 +8,18 @@ import java.util.Map.Entry;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.column.ColumnVarChar;
public class PreferencesRepository extends RepositoryPoolBase
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 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)
public PreferencesRepository(JavaPlugin plugin, String connectionString)
{
super(plugin, DBPool.ACCOUNT);
super(plugin, connectionString, "root", "tAbechAk3wR7tuTh");
}
@Override
@ -39,9 +37,9 @@ public class PreferencesRepository extends RepositoryPoolBase
{
PreparedStatement preparedStatement = null;
try (Connection connection = getDataSource().getConnection())
try
{
preparedStatement = connection.prepareStatement(UPDATE_ACCOUNT_PREFERENCES);
preparedStatement = getConnection().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());
this.reportSqlRepository = new ReportRepository(ReportPlugin.getPlugin(), "CONNECTION STRING HERE");
reportSqlRepository.initialize();
}

View File

@ -1,13 +1,21 @@
package mineplex.core.report;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryPoolBase;
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.column.ColumnInt;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.core.preferences.UserPreferences;
import org.bukkit.plugin.java.JavaPlugin;
public class ReportRepository extends RepositoryPoolBase
public class ReportRepository extends RepositoryBase
{
/*
* *ReportTicket
@ -30,9 +38,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)
public ReportRepository(JavaPlugin plugin, String connectionString)
{
super(plugin, DBPool.ACCOUNT); // TODO: Config file for host/pass?
super(plugin, connectionString, "root", "tAbechAk3wR7tuTh"); // TODO: Config file for host/pass?
}
@Override

View File

@ -7,13 +7,11 @@ 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 RepositoryPoolBase
public class SpawnRepository extends RepositoryBase
{
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 = ?;";
@ -24,7 +22,7 @@ public class SpawnRepository extends RepositoryPoolBase
public SpawnRepository(JavaPlugin plugin, String serverName)
{
super(plugin, DBPool.ACCOUNT);
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
_serverName = serverName;
}

View File

@ -138,7 +138,9 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
for (String statName : _statUploadQueue.get(player).keySet())
{
uploadQueue.get(uploadKey).put(_stats.get(statName), _statUploadQueue.get(player).get(statName));
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));
}
statIterator.remove();

View File

@ -1,6 +1,5 @@
package mineplex.core.stats;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@ -10,8 +9,7 @@ import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.database.DBPool;
import mineplex.core.database.RepositoryPoolBase;
import mineplex.core.database.RepositoryBase;
import mineplex.core.database.ResultSetCallable;
import mineplex.core.database.column.ColumnVarChar;
import mineplex.database.Tables;
@ -23,7 +21,7 @@ import org.jooq.Result;
import org.jooq.Update;
import org.jooq.impl.DSL;
public class StatsRepository extends RepositoryPoolBase
public class StatsRepository extends RepositoryBase
{
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));";
@ -33,7 +31,7 @@ public class StatsRepository extends RepositoryPoolBase
public StatsRepository(JavaPlugin plugin)
{
super(plugin, DBPool.ACCOUNT);
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
}
@Override
@ -81,7 +79,7 @@ public class StatsRepository extends RepositoryPoolBase
{
try
{
DSLContext context = DSL.using(getDataSource().getConnection());
DSLContext context = DSL.using(getConnection());
List<Update> updates = new ArrayList<>();
List<Insert> inserts = new ArrayList<>();
@ -132,32 +130,27 @@ public class StatsRepository extends RepositoryPoolBase
DSLContext context;
try (Connection connection = getDataSource().getConnection())
synchronized (this)
{
context = DSL.using(connection);
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 = new PlayerStats();
for (Record2<String, Integer> record : result)
{
playerStats.addStat(record.value1(), record.value2());
}
}
context = DSL.using(getConnection());
}
catch (Exception exception)
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())
{
exception.printStackTrace();
playerStats = new PlayerStats();
for (Record2<String, Integer> record : result)
{
playerStats.addStat(record.value1(), record.value2());
}
}
return playerStats;

View File

@ -1,29 +1,25 @@
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 RepositoryPoolBase
public class MailRepository extends RepositoryBase
{
private MailManager _manager;
public MailRepository(JavaPlugin plugin, MailManager manager)
{
super(plugin, DBPool.ACCOUNT);
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
_manager = manager;
}
@ -52,23 +48,16 @@ public class MailRepository extends RepositoryPoolBase
{
PlayerMailData data = new PlayerMailData();
try (Connection connection = getDataSource().getConnection())
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)
{
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();
data.getMessages().add(createMessage(record));
}
return data;
@ -81,18 +70,9 @@ public class MailRepository extends RepositoryPoolBase
public boolean archive(MailMessage mailMessage)
{
int recordsUpdated = 0;
try (Connection connection = getDataSource().getConnection())
{
DSLContext context = DSL.using(connection);
DSLContext context = DSL.using(getConnection());
recordsUpdated = context.update(Tables.mail).set(Tables.mail.archived, (byte) 1).where(Tables.mail.id.eq(mailMessage.getMessageId())).execute();
}
catch (Exception exception)
{
exception.printStackTrace();
}
int recordsUpdated = context.update(Tables.mail).set(Tables.mail.archived, (byte) 1).where(Tables.mail.id.eq(mailMessage.getMessageId())).execute();
return recordsUpdated == 1;
}

View File

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

View File

@ -7,13 +7,11 @@ 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 RepositoryPoolBase
public class PasswordRepository extends RepositoryBase
{
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 = ?;";
@ -25,7 +23,7 @@ public class PasswordRepository extends RepositoryPoolBase
public PasswordRepository(JavaPlugin plugin, String serverName)
{
super(plugin, DBPool.ACCOUNT);
super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh");
_serverName = serverName;
}