Browse Source

Refactor to remove abstraction

master
MagicBot 2 years ago
parent
commit
608a286428
  1. 133
      src/engine/db/handlers/dbMobHandler.java

133
src/engine/db/handlers/dbMobHandler.java

@ -132,60 +132,117 @@ public class dbMobHandler extends dbHandlerBase {
} }
public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) { public boolean ADD_TO_GUARDS(final long captainUID, final int mobBaseID, final String name, final int slot) {
prepareCallable("INSERT INTO `dyn_guards` (`captainUID`, `mobBaseID`,`name`, `slot`) VALUES (?,?,?,?)");
setLong(1, captainUID); try (Connection connection = DbManager.getConnection();
setInt(2, mobBaseID); PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_guards` (`captainUID`, `mobBaseID`,`name`, `slot`) VALUES (?,?,?,?)")) {
setString(3, name);
setInt(4, slot); preparedStatement.setLong(1, captainUID);
return (executeUpdate() > 0); preparedStatement.setInt(2, mobBaseID);
preparedStatement.setString(3, name);
preparedStatement.setInt(4, slot);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean REMOVE_FROM_GUARDS(final long captainUID, final int mobBaseID, final int slot) { public boolean REMOVE_FROM_GUARDS(final long captainUID, final int mobBaseID, final int slot) {
prepareCallable("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?");
setLong(1, captainUID); try (Connection connection = DbManager.getConnection();
setInt(2, mobBaseID); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_guards` WHERE `captainUID`=? AND `mobBaseID`=? AND `slot` =?")) {
setInt(3, slot);
return (executeUpdate() > 0); preparedStatement.setLong(1, captainUID);
preparedStatement.setInt(2, mobBaseID);
preparedStatement.setInt(3, slot);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public ArrayList<Mob> GET_ALL_MOBS_FOR_ZONE(Zone zone) { public ArrayList<Mob> GET_ALL_MOBS_FOR_ZONE(Zone zone) {
prepareCallable("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;");
setLong(1, zone.getObjectUUID()); ArrayList<Mob> mobileList = new ArrayList<>();
return getLargeObjectList();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;")) {
preparedStatement.setLong(1, zone.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery();
mobileList = getObjectsFromRs(rs, 1000);
} catch (SQLException e) {
Logger.error(e);
}
return mobileList;
} }
public Mob GET_MOB(final int objectUUID) { public Mob GET_MOB(final int objectUUID) {
prepareCallable("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;");
setLong(1, objectUUID); Mob mobile = null;
return (Mob) getObjectSingle(objectUUID);
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mob`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mob` ON `obj_mob`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery();
mobile = (Mob) getObjectFromRs(rs);
} catch (SQLException e) {
Logger.error(e);
}
return mobile;
} }
public int MOVE_MOB(long mobID, long parentID, float locX, float locY, float locZ) { public int MOVE_MOB(long mobID, long parentID, float locX, float locY, float locZ) {
prepareCallable("UPDATE `object` INNER JOIN `obj_mob` On `object`.`UID` = `obj_mob`.`UID` SET `object`.`parent`=?, `obj_mob`.`mob_spawnX`=?, `obj_mob`.`mob_spawnY`=?, `obj_mob`.`mob_spawnZ`=? WHERE `obj_mob`.`UID`=?;");
setLong(1, parentID); int row_count = 0;
setFloat(2, locX);
setFloat(3, locY); try (Connection connection = DbManager.getConnection();
setFloat(4, locZ); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `object` INNER JOIN `obj_mob` On `object`.`UID` = `obj_mob`.`UID` SET `object`.`parent`=?, `obj_mob`.`mob_spawnX`=?, `obj_mob`.`mob_spawnY`=?, `obj_mob`.`mob_spawnZ`=? WHERE `obj_mob`.`UID`=?;")) {
setLong(5, mobID);
return executeUpdate(); preparedStatement.setLong(1, parentID);
preparedStatement.setFloat(2, locX);
preparedStatement.setFloat(3, locY);
preparedStatement.setFloat(4, locZ);
preparedStatement.setLong(5, mobID);
ResultSet rs = preparedStatement.executeQuery();
row_count = preparedStatement.executeUpdate();
} catch (SQLException e) {
Logger.error(e);
}
return row_count;
} }
public String SET_PROPERTY(final Mob m, String name, Object new_value) { public String SET_PROPERTY(final Mob m, String name, Object new_value) {
prepareCallable("CALL mob_SETPROP(?,?,?)");
setLong(1, m.getObjectUUID()); String result = "";
setString(2, name);
setString(3, String.valueOf(new_value)); try (Connection connection = DbManager.getConnection();
return getResult(); PreparedStatement preparedStatement = connection.prepareStatement("CALL mob_SETPROP(?,?,?)")) {
}
preparedStatement.setLong(1, m.getObjectUUID());
public String SET_PROPERTY(final Mob m, String name, Object new_value, Object old_value) { preparedStatement.setString(2, name);
prepareCallable("CALL mob_GETSETPROP(?,?,?,?)"); preparedStatement.setString(3, String.valueOf(new_value));
setLong(1, m.getObjectUUID());
setString(2, name); ResultSet rs = preparedStatement.executeQuery();
setString(3, String.valueOf(new_value)); result = rs.getString("result");
setString(4, String.valueOf(old_value));
return getResult(); } catch (SQLException e) {
Logger.error(e);
}
return result;
} }
} }

Loading…
Cancel
Save