Browse Source

Refactor to remove abstraction.

master
MagicBot 2 years ago
parent
commit
20bbf85082
  1. 447
      src/engine/db/handlers/dbPlayerCharacterHandler.java

447
src/engine/db/handlers/dbPlayerCharacterHandler.java

@ -177,224 +177,397 @@ public class dbPlayerCharacterHandler extends dbHandlerBase {
if (objectUUID == 0) if (objectUUID == 0)
return null; return null;
PlayerCharacter pc = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID); PlayerCharacter playerCharacter = (PlayerCharacter) DbManager.getFromCache(Enum.GameObjectType.PlayerCharacter, objectUUID);
if (pc != null)
return pc; if (playerCharacter != null)
prepareCallable("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?"); return playerCharacter;
setLong(1, (long) objectUUID);
return (PlayerCharacter) getObjectSingle(objectUUID); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_character`.*, `object`.`parent` FROM `object` INNER JOIN `obj_character` ON `obj_character`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?")) {
preparedStatement.setLong(1, objectUUID);
ResultSet rs = preparedStatement.executeQuery();
playerCharacter = (PlayerCharacter) getObjectFromRs(rs);
} catch (SQLException e) {
Logger.error(e);
}
;
return playerCharacter;
} }
public boolean IS_CHARACTER_NAME_UNIQUE(final String firstName) { public boolean IS_CHARACTER_NAME_UNIQUE(final String firstName) {
boolean unique = true; boolean unique = true;
prepareCallable("SELECT `char_firstname` FROM `obj_character` WHERE `char_isActive`=1 && `char_firstname`=?");
setString(1, firstName); try (Connection connection = DbManager.getConnection();
try { PreparedStatement preparedStatement = connection.prepareStatement("SELECT `char_firstname` FROM `obj_character` WHERE `char_isActive`=1 && `char_firstname`=?")) {
ResultSet rs = executeQuery();
if (rs.next()) { preparedStatement.setString(1, firstName);
ResultSet rs = preparedStatement.executeQuery();
if (rs.next())
unique = false; unique = false;
}
rs.close();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getMessage()); Logger.error(e);
unique = false;
} finally {
closeCallable();
} }
return unique; return unique;
} }
public boolean UPDATE_NAME(String oldFirstName, String newFirstName, String newLastName) { public boolean UPDATE_NAME(String oldFirstName, String newFirstName, String newLastName) {
prepareCallable("UPDATE `obj_character` SET `char_firstname`=?, `char_lastname`=? WHERE `char_firstname`=? AND `char_isActive`='1'");
setString(1, newFirstName); try (Connection connection = DbManager.getConnection();
setString(2, newLastName); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_firstname`=?, `char_lastname`=? WHERE `char_firstname`=? AND `char_isActive`='1'")) {
setString(3, oldFirstName);
return (executeUpdate() != 0); preparedStatement.setString(1, newFirstName);
preparedStatement.setString(2, newLastName);
preparedStatement.setString(3, oldFirstName);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean SET_DELETED(final PlayerCharacter pc) { public boolean SET_DELETED(final PlayerCharacter pc) {
prepareCallable("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?");
setBoolean(1, !pc.isDeleted()); try (Connection connection = DbManager.getConnection();
setLong(2, (long) pc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
return (executeUpdate() != 0);
preparedStatement.setBoolean(1, !pc.isDeleted());
preparedStatement.setLong(2, pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean SET_ACTIVE(final PlayerCharacter pc, boolean status) { public boolean SET_ACTIVE(final PlayerCharacter pc, boolean status) {
prepareCallable("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?");
setBoolean(1, status); try (Connection connection = DbManager.getConnection();
setLong(2, (long) pc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_isActive`=? WHERE `UID` = ?")) {
return (executeUpdate() != 0);
preparedStatement.setBoolean(1, status);
preparedStatement.setLong(2, (long) pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean SET_BIND_BUILDING(final PlayerCharacter pc, int bindBuildingID) { public boolean SET_BIND_BUILDING(final PlayerCharacter pc, int bindBuildingID) {
prepareCallable("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?");
setInt(1, bindBuildingID); try (Connection connection = DbManager.getConnection();
setLong(2, (long) pc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_bindBuilding`=? WHERE `UID` = ?")) {
return (executeUpdate() != 0);
preparedStatement.setInt(1, bindBuildingID);
preparedStatement.setLong(2, (long) pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean SET_ANNIVERSERY(final PlayerCharacter pc, boolean flag) { public boolean SET_ANNIVERSERY(final PlayerCharacter pc, boolean flag) {
prepareCallable("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?");
setBoolean(1, flag); try (Connection connection = DbManager.getConnection();
setLong(2, (long) pc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `anniversery`=? WHERE `UID` = ?")) {
return (executeUpdate() != 0);
preparedStatement.setBoolean(1, flag);
preparedStatement.setLong(2, (long) pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean UPDATE_CHARACTER_EXPERIENCE(final PlayerCharacter pc) { public boolean UPDATE_CHARACTER_EXPERIENCE(final PlayerCharacter pc) {
prepareCallable("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?");
setInt(1, pc.getExp()); try (Connection connection = DbManager.getConnection();
setLong(2, (long) pc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_experience`=? WHERE `UID` = ?")) {
return (executeUpdate() != 0);
preparedStatement.setInt(1, pc.getExp());
preparedStatement.setLong(2, (long) pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean UPDATE_GUILD(final PlayerCharacter pc, int guildUUID) { public boolean UPDATE_GUILD(final PlayerCharacter pc, int guildUUID) {
prepareCallable("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?");
setInt(1, guildUUID); try (Connection connection = DbManager.getConnection();
setLong(2, (long) pc.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guildUID`=? WHERE `UID` = ?")) {
return (executeUpdate() != 0);
preparedStatement.setInt(1, guildUUID);
preparedStatement.setLong(2, (long) pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean UPDATE_CHARACTER_STATS(final PlayerCharacter pc) { public boolean UPDATE_CHARACTER_STATS(final PlayerCharacter pc) {
prepareCallable("UPDATE `obj_character` SET `char_strMod`=?, `char_dexMod`=?, `char_conMod`=?, `char_intMod`=?, `char_spiMod`=? WHERE `UID`=?");
setInt(1, pc.getStrMod());
setInt(2, pc.getDexMod());
setInt(3, pc.getConMod());
setInt(4, pc.getIntMod());
setInt(5, pc.getSpiMod());
setLong(6, (long) pc.getObjectUUID());
return (executeUpdate() != 0);
}
public String SET_PROPERTY(final PlayerCharacter c, String name, Object new_value) { try (Connection connection = DbManager.getConnection();
prepareCallable("CALL character_SETPROP(?,?,?)"); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_strMod`=?, `char_dexMod`=?, `char_conMod`=?, `char_intMod`=?, `char_spiMod`=? WHERE `UID`=?")) {
setLong(1, (long) c.getObjectUUID());
setString(2, name); preparedStatement.setInt(1, pc.getStrMod());
setString(3, String.valueOf(new_value)); preparedStatement.setInt(2, pc.getDexMod());
return getResult(); preparedStatement.setInt(3, pc.getConMod());
preparedStatement.setInt(4, pc.getIntMod());
preparedStatement.setInt(5, pc.getSpiMod());
preparedStatement.setLong(6, (long) pc.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public String SET_PROPERTY(final PlayerCharacter c, String name, Object new_value, Object old_value) { public String SET_PROPERTY(final PlayerCharacter playerCharacter, String name, Object new_value) {
prepareCallable("CALL character_GETSETPROP(?,?,?,?)");
setLong(1, (long) c.getObjectUUID()); String result = "";
setString(2, name);
setString(3, String.valueOf(new_value)); try (Connection connection = DbManager.getConnection();
setString(4, String.valueOf(old_value)); PreparedStatement preparedStatement = connection.prepareStatement("CALL character_SETPROP(?,?,?)")) {
return getResult();
preparedStatement.setLong(1, playerCharacter.getObjectUUID());
preparedStatement.setString(2, name);
;
preparedStatement.setString(3, String.valueOf(new_value));
ResultSet rs = preparedStatement.executeQuery();
result = rs.getString("result");
} catch (SQLException e) {
Logger.error(e);
}
return result;
} }
public boolean SET_PROMOTION_CLASS(PlayerCharacter player, int promotionClassID) { public boolean SET_PROMOTION_CLASS(PlayerCharacter player, int promotionClassID) {
prepareCallable("UPDATE `obj_character` SET `char_promotionClassID`=? WHERE `UID`=?;");
setInt(1,promotionClassID); try (Connection connection = DbManager.getConnection();
setInt(2, player.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `char_promotionClassID`=? WHERE `UID`=?;")) {
return (executeUpdate() != 0);
preparedStatement.setInt(1, promotionClassID);
preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean SET_INNERCOUNCIL(PlayerCharacter player, boolean isInnerCouncil) { public boolean SET_INNERCOUNCIL(PlayerCharacter player, boolean isInnerCouncil) {
prepareCallable("UPDATE `obj_character` SET `guild_isInnerCouncil`=? WHERE `UID`=?;");
setBoolean(1,isInnerCouncil); try (Connection connection = DbManager.getConnection();
setInt(2, player.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isInnerCouncil`=? WHERE `UID`=?;")) {
return (executeUpdate() != 0);
preparedStatement.setBoolean(1, isInnerCouncil);
preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean SET_FULL_MEMBER(PlayerCharacter player, boolean isFullMember) { public boolean SET_FULL_MEMBER(PlayerCharacter player, boolean isFullMember) {
prepareCallable("UPDATE `obj_character` SET `guild_isFullMember`=? WHERE `UID`=?;");
setBoolean(1,isFullMember); try (Connection connection = DbManager.getConnection();
setInt(2, player.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isFullMember`=? WHERE `UID`=?;")) {
return (executeUpdate() != 0);
preparedStatement.setBoolean(1, isFullMember);
preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean SET_TAX_COLLECTOR(PlayerCharacter player, boolean isTaxCollector) { public boolean SET_TAX_COLLECTOR(PlayerCharacter player, boolean isTaxCollector) {
prepareCallable("UPDATE `obj_character` SET `guild_isTaxCollector`=? WHERE `UID`=?;");
setBoolean(1,isTaxCollector); try (Connection connection = DbManager.getConnection();
setInt(2, player.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isTaxCollector`=? WHERE `UID`=?;")) {
return (executeUpdate() != 0);
preparedStatement.setBoolean(1, isTaxCollector);
preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean SET_RECRUITER(PlayerCharacter player, boolean isRecruiter) { public boolean SET_RECRUITER(PlayerCharacter player, boolean isRecruiter) {
prepareCallable("UPDATE `obj_character` SET `guild_isRecruiter`=? WHERE `UID`=?;");
setBoolean(1,isRecruiter); try (Connection connection = DbManager.getConnection();
setInt(2, player.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_isRecruiter`=? WHERE `UID`=?;")) {
return (executeUpdate() != 0);
preparedStatement.setBoolean(1, isRecruiter);
preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean SET_GUILD_TITLE(PlayerCharacter player, int title) { public boolean SET_GUILD_TITLE(PlayerCharacter player, int title) {
prepareCallable("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=?;");
setInt(1,title); try (Connection connection = DbManager.getConnection();
setInt(2, player.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_character` SET `guild_title`=? WHERE `UID`=?;")) {
return (executeUpdate() != 0);
preparedStatement.setInt(1, title);
preparedStatement.setInt(2, player.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean ADD_FRIEND(int source, long friend) {
public boolean ADD_FRIEND(int source, long friend){ try (Connection connection = DbManager.getConnection();
prepareCallable("INSERT INTO `dyn_character_friends` (`playerUID`, `friendUID`) VALUES (?, ?)"); PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_friends` (`playerUID`, `friendUID`) VALUES (?, ?)")) {
setLong(1, (long) source);
setLong(2, (long)friend); preparedStatement.setLong(1, source);
return (executeUpdate() != 0); preparedStatement.setLong(2, friend);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean REMOVE_FRIEND(int source, int friend){ public boolean REMOVE_FRIEND(int source, int friend) {
prepareCallable("DELETE FROM `dyn_character_friends` WHERE (`playerUID`=?) AND (`friendUID`=?)");
setLong(1, (long) source); try (Connection connection = DbManager.getConnection();
setLong(2, (long)friend); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_friends` WHERE (`playerUID`=?) AND (`friendUID`=?)")) {
return (executeUpdate() != 0);
preparedStatement.setLong(1, source);
preparedStatement.setLong(2, friend);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public void LOAD_PLAYER_FRIENDS() { public void LOAD_PLAYER_FRIENDS() {
PlayerFriends playerFriend; PlayerFriends playerFriend;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_friends")) {
prepareCallable("SELECT * FROM dyn_character_friends"); ResultSet rs = preparedStatement.executeQuery();
try {
ResultSet rs = executeQuery();
while (rs.next()) { while (rs.next())
playerFriend = new PlayerFriends(rs); playerFriend = new PlayerFriends(rs);
}
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("LoadMeshBounds: " + e.getErrorCode() + ' ' + e.getMessage(), e); Logger.error(e);
} finally {
closeCallable();
} }
prepareCallable("SELECT * FROM dyn_character_friends");
} }
public boolean ADD_HERALDY(int source, AbstractWorldObject character){ public boolean ADD_HERALDY(int source, AbstractWorldObject character) {
prepareCallable("INSERT INTO `dyn_character_heraldy` (`playerUID`, `characterUID`,`characterType`) VALUES (?, ?,?)");
setLong(1, (long) source); try (Connection connection = DbManager.getConnection();
setLong(2, (long)character.getObjectUUID()); PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_heraldy` (`playerUID`, `characterUID`,`characterType`) VALUES (?, ?,?)")) {
setInt(3, character.getObjectType().ordinal());
return (executeUpdate() != 0); preparedStatement.setLong(1, source);
preparedStatement.setLong(2, character.getObjectUUID());
preparedStatement.setInt(3, character.getObjectType().ordinal());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public boolean REMOVE_HERALDY(int source, int characterUID){ public boolean REMOVE_HERALDY(int source, int characterUID) {
prepareCallable("DELETE FROM `dyn_character_heraldy` WHERE (`playerUID`=?) AND (`characterUID`=?)");
setLong(1, (long) source); try (Connection connection = DbManager.getConnection();
setLong(2, (long)characterUID); PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_heraldy` WHERE (`playerUID`=?) AND (`characterUID`=?)")) {
return (executeUpdate() != 0);
preparedStatement.setLong(1, source);
preparedStatement.setLong(2, characterUID);
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
} }
public void LOAD_HERALDY() { public void LOAD_HERALDY() {
Heraldry heraldy; Heraldry heraldy;
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM dyn_character_heraldy")) {
prepareCallable("SELECT * FROM dyn_character_heraldy"); ResultSet rs = preparedStatement.executeQuery();
try {
ResultSet rs = executeQuery();
while (rs.next()) { while (rs.next())
heraldy = new Heraldry(rs); heraldy = new Heraldry(rs);
}
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("LoadHeraldy: " + e.getErrorCode() + ' ' + e.getMessage(), e); Logger.error(e);
} finally {
closeCallable();
} }
} }

Loading…
Cancel
Save