Browse Source

Refactor to remove abstraction

master
MagicBot 2 years ago
parent
commit
3c9b624ca0
  1. 178
      src/engine/db/handlers/dbGuildHandler.java

178
src/engine/db/handlers/dbGuildHandler.java

@ -542,62 +542,115 @@ public class dbGuildHandler extends dbHandlerBase {
// It's not like this shit ever changes. // It's not like this shit ever changes.
public boolean updateDatabase(final Guild g) { public boolean updateDatabase(final Guild g) {
prepareCallable("UPDATE `obj_guild` SET `name`=?, `backgroundColor01`=?, `backgroundColor02`=?, `symbolColor`=?, `backgroundDesign`=?, `symbol`=?, `charter`=?, `motd`=?, `icMotd`=?, `nationMotd`=?, `leaderUID`=? WHERE `UID`=?");
setString(1, g.getName()); try (Connection connection = DbManager.getConnection();
setInt(2, g.getGuildTag().backgroundColor01); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_guild` SET `name`=?, `backgroundColor01`=?, `backgroundColor02`=?, `symbolColor`=?, `backgroundDesign`=?, `symbol`=?, `charter`=?, `motd`=?, `icMotd`=?, `nationMotd`=?, `leaderUID`=? WHERE `UID`=?")) {
setInt(3, g.getGuildTag().backgroundColor02);
setInt(4, g.getGuildTag().symbolColor); preparedStatement.setString(1, g.getName());
setInt(5, g.getGuildTag().backgroundDesign); preparedStatement.setInt(2, g.getGuildTag().backgroundColor01);
setInt(6, g.getGuildTag().symbol); preparedStatement.setInt(3, g.getGuildTag().backgroundColor02);
setInt(7, g.getCharter()); preparedStatement.setInt(4, g.getGuildTag().symbolColor);
setString(8, g.getMOTD()); preparedStatement.setInt(5, g.getGuildTag().backgroundDesign);
setString(9, g.getICMOTD()); preparedStatement.setInt(6, g.getGuildTag().symbol);
setString(10, ""); preparedStatement.setInt(7, g.getCharter());
setInt(11, g.getGuildLeaderUUID()); preparedStatement.setString(8, g.getMOTD());
setLong(12, (long) g.getObjectUUID()); preparedStatement.setString(9, g.getICMOTD());
return (executeUpdate() != 0); preparedStatement.setString(10, "");
preparedStatement.setInt(11, g.getGuildLeaderUUID());
preparedStatement.setLong(12, (long) g.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean ADD_TO_ALLIANCE_LIST(final long sourceGuildID, final long targetGuildID, boolean isRecommended, boolean isAlly, String recommender) { public boolean ADD_TO_ALLIANCE_LIST(final long sourceGuildID, final long targetGuildID, boolean isRecommended, boolean isAlly, String recommender) {
prepareCallable("INSERT INTO `dyn_guild_allianceenemylist` (`GuildID`, `OtherGuildID`,`isRecommended`, `isAlliance`, `recommender`) VALUES (?,?,?,?,?)");
setLong(1, sourceGuildID); try (Connection connection = DbManager.getConnection();
setLong(2, targetGuildID); PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guild_allianceenemylist` (`GuildID`, `OtherGuildID`,`isRecommended`, `isAlliance`, `recommender`) VALUES (?,?,?,?,?)")) {
setBoolean(3, isRecommended);
setBoolean(4, isAlly); preparedStatement.setLong(1, sourceGuildID);
setString(5, recommender); preparedStatement.setLong(2, targetGuildID);
return (executeUpdate() > 0); preparedStatement.setBoolean(3, isRecommended);
preparedStatement.setBoolean(4, isAlly);
preparedStatement.setString(5, recommender);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean REMOVE_FROM_ALLIANCE_LIST(final long sourceGuildID, long targetGuildID) { public boolean REMOVE_FROM_ALLIANCE_LIST(final long sourceGuildID, long targetGuildID) {
prepareCallable("DELETE FROM `dyn_guild_allianceenemylist` WHERE `GuildID`=? AND `OtherGuildID`=?");
setLong(1, sourceGuildID); try (Connection connection = DbManager.getConnection();
setLong(2, targetGuildID); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guild_allianceenemylist` WHERE `GuildID`=? AND `OtherGuildID`=?")) {
return (executeUpdate() > 0);
preparedStatement.setLong(1, sourceGuildID);
preparedStatement.setLong(2, targetGuildID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean UPDATE_RECOMMENDED(final long sourceGuildID, long targetGuildID) { public boolean UPDATE_RECOMMENDED(final long sourceGuildID, long targetGuildID) {
prepareCallable("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ? WHERE `GuildID`=? AND `OtherGuildID`=?");
setByte(1,(byte)0); try (Connection connection = DbManager.getConnection();
setLong(2, sourceGuildID); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) {
setLong(3, targetGuildID);
return (executeUpdate() > 0); preparedStatement.setLong(1, sourceGuildID);
preparedStatement.setLong(2, targetGuildID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean UPDATE_ALLIANCE(final long sourceGuildID, long targetGuildID, boolean isAlly) { public boolean UPDATE_ALLIANCE(final long sourceGuildID, long targetGuildID, boolean isAlly) {
prepareCallable("UPDATE `dyn_guild_allianceenemylist` SET `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?");
setBoolean(1,isAlly); try (Connection connection = DbManager.getConnection();
setLong(2, sourceGuildID); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) {
setLong(3, targetGuildID);
return (executeUpdate() > 0); preparedStatement.setLong(1, sourceGuildID);
preparedStatement.setLong(2, targetGuildID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean UPDATE_ALLIANCE_AND_RECOMMENDED(final long sourceGuildID, long targetGuildID, boolean isAlly) { public boolean UPDATE_ALLIANCE_AND_RECOMMENDED(final long sourceGuildID, long targetGuildID, boolean isAlly) {
prepareCallable("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ?, `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?");
setByte(1,(byte)0);
setBoolean(2,isAlly);
setLong(3, sourceGuildID);
setLong(4, targetGuildID);
return (executeUpdate() > 0); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_guild_allianceenemylist` SET `isRecommended` = ?, `isAlliance` = ? WHERE `GuildID`=? AND `OtherGuildID`=?")) {
preparedStatement.setByte(1, (byte) 0);
preparedStatement.setBoolean(2, isAlly);
preparedStatement.setLong(3, sourceGuildID);
preparedStatement.setLong(4, targetGuildID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public void LOAD_ALL_ALLIANCES_FOR_GUILD(Guild guild) { public void LOAD_ALL_ALLIANCES_FOR_GUILD(Guild guild) {
@ -605,54 +658,45 @@ public class dbGuildHandler extends dbHandlerBase {
if (guild == null) if (guild == null)
return; return;
prepareCallable("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?"); try (Connection connection = DbManager.getConnection();
setInt(1,guild.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) {
try { preparedStatement.setInt(1, guild.getObjectUUID());
ResultSet rs = executeQuery(); ResultSet rs = preparedStatement.executeQuery();
//shrines cached in rs for easy cache on creation.
while (rs.next()) { while (rs.next()) {
GuildAlliances guildAlliance = new GuildAlliances(rs); GuildAlliances guildAlliance = new GuildAlliances(rs);
guild.guildAlliances.put(guildAlliance.getAllianceGuild(), guildAlliance); guild.guildAlliances.put(guildAlliance.getAllianceGuild(), guildAlliance);
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error( e.getMessage()); Logger.error(e);
} finally {
closeCallable();
} }
} }
public void LOAD_GUILD_HISTORY_FOR_PLAYER(PlayerCharacter pc) { public static void LOAD_GUILD_HISTORY_FOR_PLAYER(PlayerCharacter playerCharacter) {
if (pc == null) if (playerCharacter == null)
return; return;
prepareCallable("SELECT * FROM `dyn_character_guildhistory` WHERE `CharacterID` = ?"); ArrayList<GuildHistory> guildList = new ArrayList<>();
setInt(1,pc.getObjectUUID());
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_guild_allianceenemylist` WHERE `GuildID` = ?")) {
try { preparedStatement.setInt(1, playerCharacter.getObjectUUID());
ArrayList<GuildHistory> tempList = new ArrayList<>(); ResultSet rs = preparedStatement.executeQuery();
ResultSet rs = executeQuery();
//shrines cached in rs for easy cache on creation.
while (rs.next()) { while (rs.next()) {
GuildHistory guildHistory = new GuildHistory(rs); GuildHistory guildEntry = new GuildHistory(rs);
tempList.add(guildHistory); guildList.add(guildEntry);
} }
pc.setGuildHistory(tempList);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e.getMessage()); Logger.error(e);
} finally {
closeCallable();
} }
playerCharacter.setGuildHistory(guildList);
} }
//TODO uncomment this when finished with guild history warehouse integration //TODO uncomment this when finished with guild history warehouse integration

Loading…
Cancel
Save