Update DBPool to load from file
This commit is contained in:
parent
2c09fd969b
commit
f80648bfbc
@ -46,7 +46,7 @@ public class AccountRepository extends RepositoryBase
|
||||
|
||||
public AccountRepository(JavaPlugin plugin, String webAddress)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
|
||||
_webAddress = webAddress;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class AntiHackRepository
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.STATS_MINEPLEX.getConnection())
|
||||
try (Connection connection = DBPool.getStats().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(UPDATE_PLAYER_OFFENSES);
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class BenefitManagerRepository extends RepositoryBase
|
||||
|
||||
public BenefitManagerRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -789,7 +789,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
|
||||
{
|
||||
try
|
||||
{
|
||||
final int newTickets = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL).update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.add(tickets)).
|
||||
final int newTickets = DSL.using(DBPool.getAccount(), SQLDialect.MYSQL).update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.add(tickets)).
|
||||
where(Tables.bonus.accountId.eq(accountId)).returning(Tables.bonus.tickets).fetchOne().getTickets();
|
||||
runSync(new Runnable()
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ public class BonusRepository extends RepositoryBase
|
||||
|
||||
public BonusRepository(JavaPlugin plugin, BonusManager bonusManager, DonationManager donationManager)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
_manager = bonusManager;
|
||||
_donationManager = donationManager;
|
||||
}
|
||||
@ -145,7 +145,7 @@ public class BonusRepository extends RepositoryBase
|
||||
{
|
||||
try
|
||||
{
|
||||
DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
|
||||
DSLContext create = DSL.using(DBPool.getAccount(), SQLDialect.MYSQL);
|
||||
create.update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.add(tickets)).
|
||||
where(Tables.bonus.accountId.eq(accountId)).execute();
|
||||
final int newTickets = create.select(Tables.bonus.tickets).from(Tables.bonus).where(Tables.bonus.accountId.eq(accountId)).fetchOne().value1();
|
||||
|
@ -24,7 +24,7 @@ public class BotSpamRepository extends RepositoryBase
|
||||
|
||||
public BotSpamRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
public ArrayList<SpamText> getSpamText()
|
||||
|
@ -35,7 +35,7 @@ public class CustomDataRepository extends RepositoryBase
|
||||
|
||||
public CustomDataRepository(JavaPlugin plugin, CoreClientManager clientManager, CustomDataManager customDataManager)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
|
||||
_clientManager = clientManager;
|
||||
_customDataManager = customDataManager;
|
||||
|
@ -1,16 +1,26 @@
|
||||
package mineplex.core.database;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
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
|
||||
{
|
||||
public static final DataSource ACCOUNT = openDataSource("jdbc:mysql://db.mineplex.com/Account", "MilitaryPolice", "CUPr6Wuw2Rus$qap");
|
||||
public static final DataSource QUEUE = openDataSource("jdbc:mysql://db.mineplex.com/Queue", "MilitaryPolice", "CUPr6Wuw2Rus$qap");
|
||||
public static final DataSource MINEPLEX = openDataSource("jdbc:mysql://db.mineplex.com:3306/Mineplex", "MilitaryPolice", "CUPr6Wuw2Rus$qap");
|
||||
public static final DataSource STATS_MINEPLEX = openDataSource("jdbc:mysql://sqlstats.mineplex.com:3306/Mineplex", "root", "tAbechAk3wR7tuTh");
|
||||
private static DataSource ACCOUNT;
|
||||
private static DataSource QUEUE;
|
||||
private static DataSource MINEPLEX;
|
||||
private static DataSource STATS_MINEPLEX;
|
||||
|
||||
private static DataSource openDataSource(String url, String username, String password)
|
||||
{
|
||||
@ -30,8 +40,86 @@ public final class DBPool
|
||||
return source;
|
||||
}
|
||||
|
||||
private DBPool()
|
||||
public static DataSource getAccount()
|
||||
{
|
||||
if (ACCOUNT == null)
|
||||
loadDataSources();
|
||||
|
||||
return ACCOUNT;
|
||||
}
|
||||
|
||||
public static DataSource getQueue()
|
||||
{
|
||||
if (QUEUE == null)
|
||||
loadDataSources();
|
||||
|
||||
return QUEUE;
|
||||
}
|
||||
|
||||
public static DataSource getMineplex()
|
||||
{
|
||||
if (MINEPLEX == null)
|
||||
loadDataSources();
|
||||
|
||||
return MINEPLEX;
|
||||
}
|
||||
|
||||
public static DataSource getStats()
|
||||
{
|
||||
if (STATS_MINEPLEX == null)
|
||||
loadDataSources();
|
||||
|
||||
return STATS_MINEPLEX;
|
||||
}
|
||||
|
||||
private static void loadDataSources()
|
||||
{
|
||||
try
|
||||
{
|
||||
File configFile = new File("database-config.dat");
|
||||
|
||||
if (configFile.exists())
|
||||
{
|
||||
List<String> lines = Files.readAllLines(configFile.toPath(), Charset.defaultCharset());
|
||||
|
||||
for (String line : lines)
|
||||
{
|
||||
deserializeConnection(line);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("database-config.dat not found at " + configFile.toPath().toString());
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
System.out.println("---Unable To Parse DBPOOL Configuration File---");
|
||||
}
|
||||
}
|
||||
|
||||
private static void deserializeConnection(String line)
|
||||
{
|
||||
String[] args = line.split(" ");
|
||||
|
||||
if (args.length == 4)
|
||||
{
|
||||
String dbSource = args[0];
|
||||
String dbHost = args[1];
|
||||
String userName = args[2];
|
||||
String password = args[3];
|
||||
|
||||
System.out.println(dbSource + " " + dbHost + " " + userName + " " + password);
|
||||
|
||||
if (dbSource.toUpperCase().equalsIgnoreCase("ACCOUNT"))
|
||||
ACCOUNT = openDataSource("jdbc:mysql://" + dbHost, userName, password);
|
||||
else if (dbSource.toUpperCase().equalsIgnoreCase("QUEUE"))
|
||||
QUEUE = openDataSource("jdbc:mysql://" + dbHost, userName, password);
|
||||
else if (dbSource.toUpperCase().equalsIgnoreCase("MINEPLEX"))
|
||||
MINEPLEX = openDataSource("jdbc:mysql://" + dbHost, userName, password);
|
||||
else if (dbSource.toUpperCase().equalsIgnoreCase("STATS"))
|
||||
STATS_MINEPLEX = openDataSource("jdbc:mysql://" + dbHost, userName, password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public abstract class RepositoryBase implements Listener
|
||||
|
||||
protected DSLContext jooq()
|
||||
{
|
||||
return DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
|
||||
return DSL.using(DBPool.getAccount(), SQLDialect.MYSQL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ public class DonationRepository extends RepositoryBase
|
||||
|
||||
public DonationRepository(JavaPlugin plugin, String webAddress)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
|
||||
_webAddress = webAddress;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class EloRepository extends RepositoryBase
|
||||
|
||||
public EloRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class FriendRepository extends RepositoryBase
|
||||
|
||||
public FriendRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
|
||||
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||
Region.currentRegion(), PlayerStatus.class, "playerStatus");
|
||||
|
@ -26,7 +26,7 @@ public class GiveawayRepository extends RepositoryBase
|
||||
|
||||
public GiveawayRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
public boolean canGiveaway(int accountId, String giveawayName, String cooldownName)
|
||||
|
@ -17,7 +17,7 @@ public class IgnoreRepository extends RepositoryBase
|
||||
|
||||
public IgnoreRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,7 +29,7 @@ public class InventoryRepository extends RepositoryBase
|
||||
|
||||
public InventoryRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,7 +36,7 @@ public class StatEventsRepository extends RepositoryBase
|
||||
*/
|
||||
public StatEventsRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -268,7 +268,7 @@ public class NpcManager extends MiniPlugin
|
||||
|
||||
public Entity addNpc(Player player, EntityType entityType, double radius, boolean adult, String name, String entityMeta) throws SQLException
|
||||
{
|
||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||
try (Connection connection = DBPool.getAccount().getConnection())
|
||||
{
|
||||
String helmet = itemStackToYaml(player.getInventory().getHelmet());
|
||||
String chestplate = itemStackToYaml(player.getInventory().getChestplate());
|
||||
@ -386,7 +386,7 @@ public class NpcManager extends MiniPlugin
|
||||
|
||||
if (npc != null)
|
||||
{
|
||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||
try (Connection connection = DBPool.getAccount().getConnection())
|
||||
{
|
||||
npc.getDatabaseRecord().attach(DSL.using(connection).configuration());
|
||||
npc.getDatabaseRecord().delete();
|
||||
@ -493,7 +493,7 @@ public class NpcManager extends MiniPlugin
|
||||
{
|
||||
String serverType = getServerName();
|
||||
|
||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||
try (Connection connection = DBPool.getAccount().getConnection())
|
||||
{
|
||||
Result<NpcsRecord> result = DSL.using(connection)
|
||||
.selectFrom(Tables.npcs)
|
||||
@ -519,7 +519,7 @@ public class NpcManager extends MiniPlugin
|
||||
{
|
||||
String serverType = getServerName();
|
||||
|
||||
try (Connection connection = DBPool.ACCOUNT.getConnection())
|
||||
try (Connection connection = DBPool.getAccount().getConnection())
|
||||
{
|
||||
DSL.using(connection)
|
||||
.delete(Tables.npcs)
|
||||
|
@ -22,7 +22,7 @@ public class PetRepository extends RepositoryBase
|
||||
|
||||
public PetRepository(JavaPlugin plugin, String webAddress)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
|
||||
_webAddress = webAddress;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class PollRepository extends RepositoryBase
|
||||
|
||||
public PollRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,7 +28,7 @@ public class PreferencesRepository extends RepositoryBase
|
||||
|
||||
public PreferencesRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -41,7 +41,7 @@ This will be used to determine if staff are handling
|
||||
|
||||
public ReportRepository(JavaPlugin plugin, String connectionString)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,7 @@ public class SpawnRepository extends RepositoryBase
|
||||
|
||||
public SpawnRepository(JavaPlugin plugin, String serverName)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
_serverName = serverName;
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class StatsRepository extends RepositoryBase
|
||||
|
||||
public StatsRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +24,7 @@ public class TaskRepository extends RepositoryBase
|
||||
|
||||
public TaskRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,7 +20,7 @@ public class TitanGiveawayRepository extends RepositoryBase
|
||||
|
||||
public TitanGiveawayRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
_titanCount = 0;
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class ClanRepository extends RepositoryBase
|
||||
|
||||
public ClanRepository(JavaPlugin plugin, String serverName, boolean isClansServer)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
|
||||
_serverName = serverName;
|
||||
_serverId = -1;
|
||||
|
@ -34,7 +34,7 @@ public class FieldRepository extends RepositoryBase
|
||||
|
||||
public FieldRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
}
|
||||
|
||||
public List<FieldBlockToken> getFieldBlocks(String server)
|
||||
|
@ -41,7 +41,7 @@ public class HubRepository
|
||||
PreparedStatement preparedStatement = null;
|
||||
HashMap<String, String> newsEntries = new HashMap<String, String>();
|
||||
|
||||
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||
try (Connection connection = DBPool.getMineplex().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(RETRIEVE_NEWS_ENTRIES);
|
||||
|
||||
@ -91,7 +91,7 @@ public class HubRepository
|
||||
int result = 0;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||
try (Connection connection = DBPool.getMineplex().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(SET_NEWS_ENTRY);
|
||||
preparedStatement.setString(1, newsEntry);
|
||||
@ -127,7 +127,7 @@ public class HubRepository
|
||||
ResultSet resultSet = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||
try (Connection connection = DBPool.getMineplex().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(RETRIEVE_MAX_NEWS_POSITION);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
@ -165,7 +165,7 @@ public class HubRepository
|
||||
int maxPos = retrieveMaxNewsPosition();
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||
try (Connection connection = DBPool.getMineplex().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(ADD_NEWS_ENTRY);
|
||||
preparedStatement.setString(1, newsEntry);
|
||||
@ -201,7 +201,7 @@ public class HubRepository
|
||||
int maxPos = retrieveMaxNewsPosition();
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.MINEPLEX.getConnection())
|
||||
try (Connection connection = DBPool.getMineplex().getConnection())
|
||||
{
|
||||
//preparedStatement = connection.prepareStatement(DELETE_RECALC_NEWS_ENTRY);
|
||||
preparedStatement = connection.prepareStatement(DELETE_NEWS_ENTRY);
|
||||
|
@ -21,7 +21,7 @@ public class MailRepository extends RepositoryBase
|
||||
|
||||
public MailRepository(JavaPlugin plugin, MailManager manager)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
|
||||
_manager = manager;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class QueueRepository
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.QUEUE.getConnection())
|
||||
try (Connection connection = DBPool.getQueue().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(DELETE_QUEUE_RECORD);
|
||||
|
||||
@ -71,7 +71,7 @@ public class QueueRepository
|
||||
{
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.QUEUE.getConnection())
|
||||
try (Connection connection = DBPool.getQueue().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(SAVE_STATE_VALUE);
|
||||
preparedStatement.setString(1, matchStatus.State);
|
||||
@ -108,7 +108,7 @@ public class QueueRepository
|
||||
PreparedStatement preparedStatement = null;
|
||||
PlayerMatchStatus matchStatus = new PlayerMatchStatus();
|
||||
|
||||
try (Connection connection = DBPool.QUEUE.getConnection())
|
||||
try (Connection connection = DBPool.getQueue().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(INSERT_ACCOUNT, Statement.RETURN_GENERATED_KEYS);
|
||||
preparedStatement.setString(1, playerList);
|
||||
@ -165,7 +165,7 @@ public class QueueRepository
|
||||
PreparedStatement preparedStatement = null;
|
||||
PlayerMatchStatus matchStatus = null;
|
||||
|
||||
try (Connection connection = DBPool.QUEUE.getConnection())
|
||||
try (Connection connection = DBPool.getQueue().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(RETRIEVE_MATCH_STATUS);
|
||||
preparedStatement.setInt(1, id);
|
||||
@ -220,7 +220,7 @@ public class QueueRepository
|
||||
ResultSet resultSet = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
|
||||
try (Connection connection = DBPool.QUEUE.getConnection())
|
||||
try (Connection connection = DBPool.getQueue().getConnection())
|
||||
{
|
||||
preparedStatement = connection.prepareStatement(RETRIEVE_OTHER_MATCH_STATUS);
|
||||
preparedStatement.setInt(1, matchStatus.AssignedMatch);
|
||||
|
@ -179,7 +179,7 @@ public class VotifierManager extends MiniPlugin
|
||||
|
||||
private void awardBonus(final String playerName, final UUID uuid, final Callback<Integer> onComplete)
|
||||
{
|
||||
DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
|
||||
DSLContext create = DSL.using(DBPool.getAccount(), SQLDialect.MYSQL);
|
||||
|
||||
Record1<Integer> idRecord = create.select(Tables.accounts.id).from(Tables.accounts).where(Tables.accounts.uuid.eq(uuid.toString())).fetchOne();
|
||||
if (idRecord != null)
|
||||
|
@ -15,7 +15,7 @@ public class TitanGiveawayRepository extends RepositoryBase
|
||||
|
||||
public TitanGiveawayRepository(JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, DBPool.ACCOUNT);
|
||||
super(plugin, DBPool.getAccount());
|
||||
_titanGiveawayCount = 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user