Browse Source

Refactor to remove abstraction

master
MagicBot 2 years ago
parent
commit
daa5764bfb
  1. 96
      src/engine/db/handlers/dbBuildingHandler.java

96
src/engine/db/handlers/dbBuildingHandler.java

@ -165,7 +165,7 @@ public class dbBuildingHandler extends dbHandlerBase {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
result = rs.getString("result"); result = rs.getString("result");
;
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);
@ -372,30 +372,65 @@ public class dbBuildingHandler extends dbHandlerBase {
} }
public boolean REMOVE_FROM_CONDEMNED_LIST(final long buildingID, long friendID, long guildID, int friendType) { public boolean REMOVE_FROM_CONDEMNED_LIST(final long buildingID, long friendID, long guildID, int friendType) {
prepareCallable("DELETE FROM `dyn_building_condemned` WHERE `buildingUID`=? AND `playerUID`=? AND `guildUID` =? AND `friendType` = ?");
setLong(1, buildingID); try (Connection connection = DbManager.getConnection();
setLong(2, friendID); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_condemned` WHERE `buildingUID`=? AND `playerUID`=? AND `guildUID` =? AND `friendType` = ?")) {
setLong(3,guildID);
setInt(4, friendType); preparedStatement.setLong(1, buildingID);
return (executeUpdate() > 0); preparedStatement.setLong(2, friendID);
preparedStatement.setLong(3, guildID);
preparedStatement.setInt(4, friendType);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public void CLEAR_FRIENDS_LIST(final long buildingID) { public void CLEAR_FRIENDS_LIST(final long buildingID) {
prepareCallable("DELETE FROM `dyn_building_friends` WHERE `buildingUID`=?");
setLong(1, buildingID); try (Connection connection = DbManager.getConnection();
executeUpdate(); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_friends` WHERE `buildingUID`=?")) {
preparedStatement.setLong(1, buildingID);
preparedStatement.execute();
} catch (SQLException e) {
Logger.error(e);
}
} }
public void CLEAR_CONDEMNED_LIST(final long buildingID) { public void CLEAR_CONDEMNED_LIST(final long buildingID) {
prepareCallable("DELETE FROM `dyn_building_condemned` WHERE `buildingUID`=?");
setLong(1, buildingID); try (Connection connection = DbManager.getConnection();
executeUpdate(); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_condemned` WHERE `buildingUID`=?")) {
preparedStatement.setLong(1, buildingID);
preparedStatement.execute();
} catch (SQLException e) {
Logger.error(e);
}
} }
public boolean CLEAR_PATROL(final long buildingID) { public boolean CLEAR_PATROL(final long buildingID) {
prepareCallable("DELETE FROM `dyn_building_patrol_points` WHERE `buildingUID`=?");
setLong(1, buildingID); try (Connection connection = DbManager.getConnection();
return (executeUpdate() > 0); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_building_patrol_points` WHERE `buildingUID`=?")) {
preparedStatement.setLong(1, buildingID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public void LOAD_ALL_FRIENDS_FOR_BUILDING(Building building) { public void LOAD_ALL_FRIENDS_FOR_BUILDING(Building building) {
@ -403,30 +438,27 @@ public class dbBuildingHandler extends dbHandlerBase {
if (building == null) if (building == null)
return; return;
prepareCallable("SELECT * FROM `dyn_building_friends` WHERE `buildingUID` = ?"); try (Connection connection = DbManager.getConnection();
setInt(1,building.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_building_friends` WHERE `buildingUID` = ?")) {
try { preparedStatement.setInt(1, building.getObjectUUID());
ResultSet rs = executeQuery(); ResultSet rs = preparedStatement.executeQuery();
//shrines cached in rs for easy cache on creation.
while (rs.next()) { while (rs.next()) {
BuildingFriends friend = new BuildingFriends(rs); BuildingFriends friend = new BuildingFriends(rs);
switch(friend.getFriendType()){ switch (friend.getFriendType()) {
case 7: case 7:
building.getFriends().put(friend.getPlayerUID(), friend); building.getFriends().put(friend.getPlayerUID(), friend);
break; break;
case 8: case 8:
case 9: case 9:
building.getFriends().put(friend.getGuildUID(), friend); building.getFriends().put(friend.getGuildUID(), friend);
break; break;
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("LOAD friends for building: " + e.getErrorCode() + ' ' + e.getMessage(), e); Logger.error(e);
} finally {
closeCallable();
} }
} }

Loading…
Cancel
Save