Project cleanup pre merge.
This commit is contained in:
@@ -33,123 +33,123 @@ import java.util.ArrayList;
|
||||
|
||||
public class DestroyCityThread implements Runnable {
|
||||
|
||||
City city;
|
||||
City city;
|
||||
|
||||
public DestroyCityThread(City city) {
|
||||
public DestroyCityThread(City city) {
|
||||
|
||||
this.city = city;
|
||||
}
|
||||
this.city = city;
|
||||
}
|
||||
|
||||
public void run(){
|
||||
public void run() {
|
||||
|
||||
// Member variable declaration
|
||||
// Member variable declaration
|
||||
|
||||
Zone cityZone;
|
||||
Zone newParent;
|
||||
Guild formerGuild;
|
||||
Vector3fImmutable localCoords;
|
||||
ArrayList<Guild> subGuildList;
|
||||
Zone cityZone;
|
||||
Zone newParent;
|
||||
Guild formerGuild;
|
||||
Vector3fImmutable localCoords;
|
||||
ArrayList<Guild> subGuildList;
|
||||
|
||||
// Member variable assignment
|
||||
// Member variable assignment
|
||||
|
||||
cityZone = city.getParent();
|
||||
newParent = cityZone.getParent();
|
||||
formerGuild = city.getTOL().getGuild();
|
||||
cityZone = city.getParent();
|
||||
newParent = cityZone.getParent();
|
||||
formerGuild = city.getTOL().getGuild();
|
||||
|
||||
// Former guild loses it's tree!
|
||||
// Former guild loses it's tree!
|
||||
|
||||
if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) {
|
||||
if (DbManager.GuildQueries.SET_GUILD_OWNED_CITY(formerGuild.getObjectUUID(), 0)) {
|
||||
|
||||
//Successful Update of guild
|
||||
//Successful Update of guild
|
||||
|
||||
formerGuild.setGuildState(engine.Enum.GuildState.Errant);
|
||||
formerGuild.setNation(null);
|
||||
formerGuild.setCityUUID(0);
|
||||
GuildManager.updateAllGuildTags(formerGuild);
|
||||
GuildManager.updateAllGuildBinds(formerGuild, null);
|
||||
}
|
||||
formerGuild.setGuildState(engine.Enum.GuildState.Errant);
|
||||
formerGuild.setNation(null);
|
||||
formerGuild.setCityUUID(0);
|
||||
GuildManager.updateAllGuildTags(formerGuild);
|
||||
GuildManager.updateAllGuildBinds(formerGuild, null);
|
||||
}
|
||||
|
||||
// By losing the tree, the former owners lose all of their subguilds.
|
||||
// By losing the tree, the former owners lose all of their subguilds.
|
||||
|
||||
if (formerGuild.getSubGuildList().isEmpty() == false) {
|
||||
if (formerGuild.getSubGuildList().isEmpty() == false) {
|
||||
|
||||
subGuildList = new ArrayList<>();
|
||||
subGuildList = new ArrayList<>();
|
||||
|
||||
for (Guild subGuild : formerGuild.getSubGuildList()) {
|
||||
subGuildList.add(subGuild);
|
||||
}
|
||||
for (Guild subGuild : formerGuild.getSubGuildList()) {
|
||||
subGuildList.add(subGuild);
|
||||
}
|
||||
|
||||
for (Guild subGuild : subGuildList) {
|
||||
formerGuild.removeSubGuild(subGuild);
|
||||
}
|
||||
}
|
||||
for (Guild subGuild : subGuildList) {
|
||||
formerGuild.removeSubGuild(subGuild);
|
||||
}
|
||||
}
|
||||
|
||||
// Build list of buildings within this parent zone
|
||||
// Build list of buildings within this parent zone
|
||||
|
||||
for (Building cityBuilding : cityZone.zoneBuildingSet) {
|
||||
for (Building cityBuilding : cityZone.zoneBuildingSet) {
|
||||
|
||||
// Sanity Check in case player deletes the building
|
||||
// before this thread can get to it
|
||||
// Sanity Check in case player deletes the building
|
||||
// before this thread can get to it
|
||||
|
||||
if (cityBuilding == null)
|
||||
continue;
|
||||
if (cityBuilding == null)
|
||||
continue;
|
||||
|
||||
// Do nothing with the banestone. It will be removed elsewhere
|
||||
// Do nothing with the banestone. It will be removed elsewhere
|
||||
|
||||
if (cityBuilding.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.BANESTONE))
|
||||
continue;
|
||||
|
||||
// All buildings are moved to a location relative
|
||||
// to their new parent zone
|
||||
if (cityBuilding.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.BANESTONE))
|
||||
continue;
|
||||
|
||||
localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent);
|
||||
// All buildings are moved to a location relative
|
||||
// to their new parent zone
|
||||
|
||||
DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z);
|
||||
localCoords = ZoneManager.worldToLocal(cityBuilding.getLoc(), newParent);
|
||||
|
||||
// All buildings are re-parented to a zone one node
|
||||
// higher in the tree (continent) as we will be
|
||||
// deleting the city zone very shortly.
|
||||
DbManager.BuildingQueries.MOVE_BUILDING(cityBuilding.getObjectUUID(), newParent.getObjectUUID(), localCoords.x, localCoords.y, localCoords.z);
|
||||
|
||||
if (cityBuilding.getParentZoneID() != newParent.getParentZoneID())
|
||||
cityBuilding.setParentZone(newParent);
|
||||
// All buildings are re-parented to a zone one node
|
||||
// higher in the tree (continent) as we will be
|
||||
// deleting the city zone very shortly.
|
||||
|
||||
// No longer a tree, no longer any protection contract!
|
||||
if (cityBuilding.getParentZoneID() != newParent.getParentZoneID())
|
||||
cityBuilding.setParentZone(newParent);
|
||||
|
||||
cityBuilding.setProtectionState(Enum.ProtectionState.NONE);
|
||||
// No longer a tree, no longer any protection contract!
|
||||
|
||||
// Destroy all remaining city assets
|
||||
cityBuilding.setProtectionState(Enum.ProtectionState.NONE);
|
||||
|
||||
if ((cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BARRACK)
|
||||
|| (cityBuilding.getBlueprint().isWallPiece())
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SHRINE)
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.TOL)
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SPIRE)
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.WAREHOUSE)) {
|
||||
// Destroy all remaining city assets
|
||||
|
||||
if (cityBuilding.getRank() != -1)
|
||||
cityBuilding.setRank(-1);
|
||||
}
|
||||
}
|
||||
if ((cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.BARRACK)
|
||||
|| (cityBuilding.getBlueprint().isWallPiece())
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SHRINE)
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.TOL)
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.SPIRE)
|
||||
|| (cityBuilding.getBlueprint().getBuildingGroup() == Enum.BuildingGroup.WAREHOUSE)) {
|
||||
|
||||
if (city.getRealm() != null)
|
||||
city.getRealm().removeCity(city.getObjectUUID());
|
||||
if (cityBuilding.getRank() != -1)
|
||||
cityBuilding.setRank(-1);
|
||||
}
|
||||
}
|
||||
|
||||
// It's now safe to delete the city zone from the database
|
||||
// which will cause a cascade delete of everything else
|
||||
if (city.getRealm() != null)
|
||||
city.getRealm().removeCity(city.getObjectUUID());
|
||||
|
||||
// It's now safe to delete the city zone from the database
|
||||
// which will cause a cascade delete of everything else
|
||||
|
||||
|
||||
if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) {
|
||||
Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) {
|
||||
Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID());
|
||||
return;
|
||||
}
|
||||
|
||||
// Refresh the city for map requests
|
||||
// Refresh the city for map requests
|
||||
|
||||
City.lastCityUpdate = System.currentTimeMillis();
|
||||
City.lastCityUpdate = System.currentTimeMillis();
|
||||
|
||||
// Zone and city should vanish upon next reboot
|
||||
// if the codebase reaches here.
|
||||
// Zone and city should vanish upon next reboot
|
||||
// if the codebase reaches here.
|
||||
|
||||
Logger.info(city.getParent().getName() + " uuid:" + city.getObjectUUID() + "has been destroyed!");
|
||||
}
|
||||
Logger.info(city.getParent().getName() + " uuid:" + city.getObjectUUID() + "has been destroyed!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,28 +25,29 @@ public class DisconnectTrashTask extends TimerTask {
|
||||
// Pass it a list of characters and it will disconnect them
|
||||
// 5 seconds in the future.
|
||||
|
||||
public DisconnectTrashTask(ArrayList<PlayerCharacter> trashList)
|
||||
{
|
||||
public DisconnectTrashTask(ArrayList<PlayerCharacter> trashList) {
|
||||
this.trashList = new ArrayList<>(trashList);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
Logger.info("Disconnecting actives from pool of: " + trashList.size());
|
||||
Logger.info("Disconnecting actives from pool of: " + trashList.size());
|
||||
|
||||
Session trashSession;
|
||||
int accountUID;
|
||||
|
||||
for (PlayerCharacter trashPlayer:trashList) {
|
||||
trashSession = SessionManager.getSession(trashPlayer);
|
||||
accountUID = trashPlayer.getAccount().getObjectUUID();
|
||||
for (PlayerCharacter trashPlayer : trashList) {
|
||||
trashSession = SessionManager.getSession(trashPlayer);
|
||||
accountUID = trashPlayer.getAccount().getObjectUUID();
|
||||
|
||||
if (trashSession != null)
|
||||
trashSession.getConn().disconnect();
|
||||
if (trashSession != null)
|
||||
trashSession.getConn().disconnect();
|
||||
|
||||
// Remove account from cache
|
||||
// Remove account from cache
|
||||
|
||||
DbManager.removeFromCache(Enum.GameObjectType.Account, accountUID);
|
||||
}
|
||||
};
|
||||
DbManager.removeFromCache(Enum.GameObjectType.Account, accountUID);
|
||||
}
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PurgeOprhans implements Runnable {
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error( e.toString());
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
|
||||
Logger.info("Thread is exiting with " + recordsDeleted.toString() + " items deleted");
|
||||
|
||||
@@ -39,7 +39,7 @@ public class TransferCityThread implements Runnable {
|
||||
this.newOwner = newOwner;
|
||||
}
|
||||
|
||||
public void run(){
|
||||
public void run() {
|
||||
|
||||
Guild formerGuild;
|
||||
ArrayList<Guild> subGuildList;
|
||||
@@ -81,7 +81,7 @@ public class TransferCityThread implements Runnable {
|
||||
city.claim(newOwner);
|
||||
|
||||
//Set name of City to attacker's guild name
|
||||
BuildingManager.setUpgradeDateTime(city.getTOL(),null, 0);
|
||||
BuildingManager.setUpgradeDateTime(city.getTOL(), null, 0);
|
||||
city.getTOL().setName(newOwner.getGuild().getName());
|
||||
|
||||
// Send updated cityZone to players
|
||||
@@ -94,6 +94,6 @@ public class TransferCityThread implements Runnable {
|
||||
City.lastCityUpdate = System.currentTimeMillis();
|
||||
|
||||
Logger.info("uuid:" + city.getObjectUUID() + "transferred from " + formerGuild.getName() +
|
||||
" to " + newOwner.getGuild().getName());
|
||||
" to " + newOwner.getGuild().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,427 +25,424 @@ import java.sql.*;
|
||||
|
||||
public class WarehousePushThread implements Runnable {
|
||||
|
||||
// Used to track last push. These are read
|
||||
// at thread startup and written back out
|
||||
// when we're done
|
||||
// Used to track last push. These are read
|
||||
// at thread startup and written back out
|
||||
// when we're done
|
||||
|
||||
public static int charIndex, charDelta;
|
||||
public static int cityIndex, cityDelta;
|
||||
public static int guildIndex, guildDelta;
|
||||
public static int realmIndex, realmDelta;
|
||||
public static int baneIndex, baneDelta;
|
||||
public static int pvpIndex, pvpDelta;
|
||||
public static int mineIndex, mineDelta;
|
||||
public static int charIndex, charDelta;
|
||||
public static int cityIndex, cityDelta;
|
||||
public static int guildIndex, guildDelta;
|
||||
public static int realmIndex, realmDelta;
|
||||
public static int baneIndex, baneDelta;
|
||||
public static int pvpIndex, pvpDelta;
|
||||
public static int mineIndex, mineDelta;
|
||||
|
||||
public WarehousePushThread() {
|
||||
public WarehousePushThread() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
public static boolean pushMineRecords() {
|
||||
|
||||
int recordCount = 0;
|
||||
boolean writeSuccess = true;
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = MineRecord.buildMineQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
if ( ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equals("false")) {
|
||||
while (rs.next()) {
|
||||
pushMineRecord(rs);
|
||||
mineDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean pushCharacterRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = CharacterRecord.buildCharacterQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
pushCharacterRecord(rs);
|
||||
charDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushGuildRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = GuildRecord.buildGuildQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
pushGuildRecord(rs);
|
||||
guildDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushMineRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = MineRecord.buildMinePushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushGuildRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = GuildRecord.buildGuildPushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushBaneRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = BaneRecord.buildBaneQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
pushBaneRecord(rs);
|
||||
baneDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushBaneRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = BaneRecord.buildBanePushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushCityRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = CityRecord.buildCityQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
pushCityRecord(rs);
|
||||
cityDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushPvpRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = PvpRecord.buildPvpQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
if (pushPvpRecord(rs) == true)
|
||||
pvpDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushPvpRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = PvpRecord.buildPvpPushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean pushRealmRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = RealmRecord.buildRealmQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
if (pushRealmRecord(rs) == true)
|
||||
realmDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushRealmRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = RealmRecord.buildRealmPushStatement(remoteConnection, rs)) {
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean pushCharacterRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = CharacterRecord.buildCharacterPushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean pushCityRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = CityRecord.buildCityPushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean readWarehouseIndex() {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
String queryString;
|
||||
|
||||
queryString = "SELECT * FROM `warehouse_index`";
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
CallableStatement statement = localConnection.prepareCall(queryString);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
charIndex = rs.getInt("charIndex");
|
||||
cityIndex = rs.getInt("cityIndex");
|
||||
guildIndex = rs.getInt("guildIndex");
|
||||
realmIndex = rs.getInt("realmIndex");
|
||||
baneIndex = rs.getInt("baneIndex");
|
||||
pvpIndex = rs.getInt("pvpIndex");
|
||||
mineIndex = rs.getInt("mineIndex");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error reading warehouse index" + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean updateWarehouseIndex() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = WarehousePushThread.buildIndexUpdateStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildIndexUpdateStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_index` SET `charIndex` = ?, `cityIndex` = ?, `guildIndex` = ?, `realmIndex` = ?, `baneIndex` = ?, `pvpIndex` = ?, `mineIndex` = ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, charIndex);
|
||||
outStatement.setInt(2, cityIndex);
|
||||
outStatement.setInt(3, guildIndex);
|
||||
outStatement.setInt(4, realmIndex);
|
||||
outStatement.setInt(5, baneIndex);
|
||||
outStatement.setInt(6, pvpIndex);
|
||||
outStatement.setInt(7, mineIndex);
|
||||
return outStatement;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
int recordCount = 0;
|
||||
boolean writeSuccess = true;
|
||||
|
||||
if (ConfigManager.MB_WORLD_WAREHOUSE_PUSH.getValue().equals("false")) {
|
||||
Logger.info("WAREHOUSEPUSH DISABLED: EARLY EXIT");
|
||||
return;
|
||||
}
|
||||
|
||||
// Cache where we left off from the last push
|
||||
// for each of the warehouse tables
|
||||
|
||||
if (readWarehouseIndex() == false)
|
||||
return;
|
||||
|
||||
// Log run to console
|
||||
|
||||
Logger.info( "Pushing records to remote...");
|
||||
|
||||
// Push records to remote database
|
||||
|
||||
for (Enum.DataRecordType recordType : Enum.DataRecordType.values()) {
|
||||
|
||||
switch (recordType) {
|
||||
case PVP:
|
||||
if (pushPvpRecords() == true) {
|
||||
recordCount = Math.max(0, pvpDelta - pvpIndex);
|
||||
pvpIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case CHARACTER:
|
||||
if (pushCharacterRecords() == true) {
|
||||
recordCount = Math.max(0, charDelta - charIndex);
|
||||
charIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case REALM:
|
||||
if (pushRealmRecords() == true) {
|
||||
recordCount = Math.max(0, realmDelta - realmIndex);
|
||||
realmIndex += recordCount;
|
||||
}
|
||||
else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case GUILD:
|
||||
if (pushGuildRecords() == true) {
|
||||
recordCount = Math.max(0, guildDelta - guildIndex);
|
||||
guildIndex += recordCount;
|
||||
}
|
||||
else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case BANE:
|
||||
if (pushBaneRecords() == true) {
|
||||
recordCount = Math.max(0, baneDelta - baneIndex);
|
||||
baneIndex += recordCount;
|
||||
}
|
||||
else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case CITY:
|
||||
if (pushCityRecords() == true) {
|
||||
recordCount = Math.max(0, cityDelta - cityIndex);
|
||||
cityIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case MINE:
|
||||
if (pushMineRecords() == true) {
|
||||
recordCount = Math.max(0, mineDelta - mineIndex);
|
||||
mineIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
default:
|
||||
recordCount = 0;
|
||||
writeSuccess = false;
|
||||
break; // unhandled type
|
||||
}
|
||||
|
||||
if (writeSuccess == true)
|
||||
Logger.info( recordCount + " " + recordType.name() + " records sent to remote");
|
||||
else
|
||||
Logger.info( recordCount + " returning failed success");
|
||||
|
||||
} // Iterate switch
|
||||
|
||||
// Update indices
|
||||
|
||||
updateWarehouseIndex();
|
||||
|
||||
// Update dirty records
|
||||
|
||||
Logger.info( "Pushing updates of dirty warehouse records");
|
||||
CharacterRecord.updateDirtyRecords();
|
||||
|
||||
if (charDelta > 0)
|
||||
Logger.info( charDelta + " dirty character records were sent");
|
||||
;
|
||||
BaneRecord.updateDirtyRecords();
|
||||
|
||||
if (baneDelta > 0)
|
||||
Logger.info( baneDelta + " dirty bane records were sent");
|
||||
|
||||
Logger.info( "Process has completed");
|
||||
|
||||
}
|
||||
|
||||
public static boolean pushMineRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = MineRecord.buildMineQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
pushMineRecord(rs);
|
||||
mineDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean pushCharacterRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = CharacterRecord.buildCharacterQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
pushCharacterRecord(rs);
|
||||
charDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushGuildRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = GuildRecord.buildGuildQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
pushGuildRecord(rs);
|
||||
guildDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushMineRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = MineRecord.buildMinePushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error( e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushGuildRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = GuildRecord.buildGuildPushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushBaneRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = BaneRecord.buildBaneQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
pushBaneRecord(rs);
|
||||
baneDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushBaneRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = BaneRecord.buildBanePushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushCityRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = CityRecord.buildCityQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
pushCityRecord(rs);
|
||||
cityDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushPvpRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = PvpRecord.buildPvpQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
if (pushPvpRecord(rs) == true)
|
||||
pvpDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushPvpRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = PvpRecord.buildPvpPushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean pushRealmRecords() {
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
PreparedStatement statement = RealmRecord.buildRealmQueryStatement(localConnection);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
if (pushRealmRecord(rs) == true)
|
||||
realmDelta = rs.getInt("event_number");
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Logger.error("Error with local DB connection: " + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean pushRealmRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = RealmRecord.buildRealmPushStatement(remoteConnection, rs)) {
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error( e.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean pushCharacterRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = CharacterRecord.buildCharacterPushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static boolean pushCityRecord(ResultSet rs) {
|
||||
|
||||
try (Connection remoteConnection = DataWarehouse.remoteConnectionPool.getConnection();
|
||||
PreparedStatement statement = CityRecord.buildCityPushStatement(remoteConnection, rs)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error( e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean readWarehouseIndex() {
|
||||
|
||||
// Member variable declaration
|
||||
|
||||
String queryString;
|
||||
|
||||
queryString = "SELECT * FROM `warehouse_index`";
|
||||
|
||||
try (Connection localConnection = DbManager.getConnection();
|
||||
CallableStatement statement = localConnection.prepareCall(queryString);
|
||||
ResultSet rs = statement.executeQuery()) {
|
||||
|
||||
while (rs.next()) {
|
||||
charIndex = rs.getInt("charIndex");
|
||||
cityIndex = rs.getInt("cityIndex");
|
||||
guildIndex = rs.getInt("guildIndex");
|
||||
realmIndex = rs.getInt("realmIndex");
|
||||
baneIndex = rs.getInt("baneIndex");
|
||||
pvpIndex = rs.getInt("pvpIndex");
|
||||
mineIndex = rs.getInt("mineIndex");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error( "Error reading warehouse index" + e.toString());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean updateWarehouseIndex() {
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement statement = WarehousePushThread.buildIndexUpdateStatement(connection)) {
|
||||
|
||||
statement.execute();
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
Logger.error(e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static PreparedStatement buildIndexUpdateStatement(Connection connection) throws SQLException {
|
||||
|
||||
PreparedStatement outStatement = null;
|
||||
String queryString = "UPDATE `warehouse_index` SET `charIndex` = ?, `cityIndex` = ?, `guildIndex` = ?, `realmIndex` = ?, `baneIndex` = ?, `pvpIndex` = ?, `mineIndex` = ?";
|
||||
outStatement = connection.prepareStatement(queryString);
|
||||
|
||||
// Bind record data
|
||||
|
||||
outStatement.setInt(1, charIndex);
|
||||
outStatement.setInt(2, cityIndex);
|
||||
outStatement.setInt(3, guildIndex);
|
||||
outStatement.setInt(4, realmIndex);
|
||||
outStatement.setInt(5, baneIndex);
|
||||
outStatement.setInt(6, pvpIndex);
|
||||
outStatement.setInt(7, mineIndex);
|
||||
return outStatement;
|
||||
}
|
||||
// Cache where we left off from the last push
|
||||
// for each of the warehouse tables
|
||||
|
||||
if (readWarehouseIndex() == false)
|
||||
return;
|
||||
|
||||
// Log run to console
|
||||
|
||||
Logger.info("Pushing records to remote...");
|
||||
|
||||
// Push records to remote database
|
||||
|
||||
for (Enum.DataRecordType recordType : Enum.DataRecordType.values()) {
|
||||
|
||||
switch (recordType) {
|
||||
case PVP:
|
||||
if (pushPvpRecords() == true) {
|
||||
recordCount = Math.max(0, pvpDelta - pvpIndex);
|
||||
pvpIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case CHARACTER:
|
||||
if (pushCharacterRecords() == true) {
|
||||
recordCount = Math.max(0, charDelta - charIndex);
|
||||
charIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case REALM:
|
||||
if (pushRealmRecords() == true) {
|
||||
recordCount = Math.max(0, realmDelta - realmIndex);
|
||||
realmIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case GUILD:
|
||||
if (pushGuildRecords() == true) {
|
||||
recordCount = Math.max(0, guildDelta - guildIndex);
|
||||
guildIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case BANE:
|
||||
if (pushBaneRecords() == true) {
|
||||
recordCount = Math.max(0, baneDelta - baneIndex);
|
||||
baneIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case CITY:
|
||||
if (pushCityRecords() == true) {
|
||||
recordCount = Math.max(0, cityDelta - cityIndex);
|
||||
cityIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
case MINE:
|
||||
if (pushMineRecords() == true) {
|
||||
recordCount = Math.max(0, mineDelta - mineIndex);
|
||||
mineIndex += recordCount;
|
||||
} else
|
||||
writeSuccess = false;
|
||||
break;
|
||||
default:
|
||||
recordCount = 0;
|
||||
writeSuccess = false;
|
||||
break; // unhandled type
|
||||
}
|
||||
|
||||
if (writeSuccess == true)
|
||||
Logger.info(recordCount + " " + recordType.name() + " records sent to remote");
|
||||
else
|
||||
Logger.info(recordCount + " returning failed success");
|
||||
|
||||
} // Iterate switch
|
||||
|
||||
// Update indices
|
||||
|
||||
updateWarehouseIndex();
|
||||
|
||||
// Update dirty records
|
||||
|
||||
Logger.info("Pushing updates of dirty warehouse records");
|
||||
CharacterRecord.updateDirtyRecords();
|
||||
|
||||
if (charDelta > 0)
|
||||
Logger.info(charDelta + " dirty character records were sent");
|
||||
;
|
||||
BaneRecord.updateDirtyRecords();
|
||||
|
||||
if (baneDelta > 0)
|
||||
Logger.info(baneDelta + " dirty bane records were sent");
|
||||
|
||||
Logger.info("Process has completed");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user