Browse Source

Refactor to remove abstraction.

master
MagicBot 2 years ago
parent
commit
860f7b7b49
  1. 71
      src/engine/db/handlers/dbNPCHandler.java

71
src/engine/db/handlers/dbNPCHandler.java

@ -215,24 +215,51 @@ public class dbNPCHandler extends dbHandlerBase {
} }
public boolean UPDATE_MOBBASE(NPC npc, int mobBaseID) { public boolean UPDATE_MOBBASE(NPC npc, int mobBaseID) {
prepareCallable("UPDATE `obj_npc` SET `npc_raceID`=? WHERE `UID`=?");
setLong(1, mobBaseID); try (Connection connection = DbManager.getConnection();
setLong(2, npc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `npc_raceID`=? WHERE `UID`=?")) {
return (executeUpdate() > 0);
preparedStatement.setLong(1, mobBaseID);
preparedStatement.setLong(2, npc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean UPDATE_EQUIPSET(NPC npc, int equipSetID) { public boolean UPDATE_EQUIPSET(NPC npc, int equipSetID) {
prepareCallable("UPDATE `obj_npc` SET `equipsetID`=? WHERE `UID`=?");
setInt(1, equipSetID); try (Connection connection = DbManager.getConnection();
setLong(2, npc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `equipsetID`=? WHERE `UID`=?")) {
return (executeUpdate() > 0);
preparedStatement.setInt(1, equipSetID);
preparedStatement.setLong(2, npc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean UPDATE_NAME(NPC npc, String name) { public boolean UPDATE_NAME(NPC npc, String name) {
prepareCallable("UPDATE `obj_npc` SET `npc_name`=? WHERE `UID`=?");
setString(1, name); try (Connection connection = DbManager.getConnection();
setLong(2, npc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_npc` SET `npc_name`=? WHERE `UID`=?")) {
return (executeUpdate() > 0);
preparedStatement.setString(1, name);
preparedStatement.setLong(2, npc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public void LOAD_PIRATE_NAMES() { public void LOAD_PIRATE_NAMES() {
@ -241,10 +268,10 @@ public class dbNPCHandler extends dbHandlerBase {
int mobBase; int mobBase;
int recordsRead = 0; int recordsRead = 0;
prepareCallable("SELECT * FROM static_piratenames"); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_piratenames")) {
try { ResultSet rs = preparedStatement.executeQuery();
ResultSet rs = executeQuery();
while (rs.next()) { while (rs.next()) {
@ -254,24 +281,20 @@ public class dbNPCHandler extends dbHandlerBase {
// Handle new mobbbase entries // Handle new mobbbase entries
if (NPC._pirateNames.get(mobBase) == null) { if (NPC._pirateNames.get(mobBase) == null)
NPC._pirateNames.putIfAbsent(mobBase, new ArrayList<>()); NPC._pirateNames.putIfAbsent(mobBase, new ArrayList<>());
}
// Insert name into proper arraylist // Insert name into proper arraylist
NPC._pirateNames.get(mobBase).add(pirateName); NPC._pirateNames.get(mobBase).add(pirateName);
} }
Logger.info("names read: " + recordsRead + " for "
+ NPC._pirateNames.size() + " mobBases");
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e.getErrorCode() + ' ' + e.getMessage(), e); Logger.error(e);
} finally {
closeCallable();
} }
Logger.info("names read: " + recordsRead + " for "
+ NPC._pirateNames.size() + " mobBases");
} }

Loading…
Cancel
Save