Browse Source

Refactor to remove abstraction.

master
MagicBot 2 years ago
parent
commit
0924fa2bdb
  1. 2
      src/engine/db/handlers/dbBuildingHandler.java
  2. 110
      src/engine/db/handlers/dbCharacterRuneHandler.java
  3. 2
      src/engine/db/handlers/dbItemHandler.java

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

@ -96,7 +96,7 @@ public class dbBuildingHandler extends dbHandlerBase {
preparedStatement.setLong(1, zone.getObjectUUID()); preparedStatement.setLong(1, zone.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
buildings = getObjectsFromRs(rs, 2000); buildings = getObjectsFromRs(rs, 1000);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);

110
src/engine/db/handlers/dbCharacterRuneHandler.java

@ -12,7 +12,12 @@ package engine.db.handlers;
import engine.Enum; import engine.Enum;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.objects.CharacterRune; import engine.objects.CharacterRune;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
public class dbCharacterRuneHandler extends dbHandlerBase { public class dbCharacterRuneHandler extends dbHandlerBase {
@ -23,41 +28,98 @@ public class dbCharacterRuneHandler extends dbHandlerBase {
} }
public CharacterRune ADD_CHARACTER_RUNE(final CharacterRune toAdd) { public CharacterRune ADD_CHARACTER_RUNE(final CharacterRune toAdd) {
prepareCallable("INSERT INTO `dyn_character_rune` (`CharacterID`, `RuneBaseID`) VALUES (?, ?);");
setLong(1, (long)toAdd.getPlayerID()); CharacterRune characterRune = null;
setInt(2, toAdd.getRuneBaseID());
int runeID = insertGetUUID(); try (Connection connection = DbManager.getConnection();
return GET_CHARACTER_RUNE(runeID); PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_character_rune` (`CharacterID`, `RuneBaseID`) VALUES (?, ?);")) {
preparedStatement.setLong(1, toAdd.getPlayerID());
preparedStatement.setInt(2, toAdd.getRuneBaseID());
preparedStatement.executeUpdate();
ResultSet rs = preparedStatement.getGeneratedKeys();
if (rs.next())
characterRune = GET_CHARACTER_RUNE(rs.getInt(1));
} catch (SQLException e) {
Logger.error(e);
}
return characterRune;
} }
public CharacterRune GET_CHARACTER_RUNE(int runeID) { public CharacterRune GET_CHARACTER_RUNE(int runeID) {
CharacterRune charRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID); CharacterRune characterRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID);
if (charRune != null)
return charRune; if (characterRune != null)
prepareCallable("SELECT * FROM `dyn_character_rune` WHERE `UID`=?"); return characterRune;
setInt(1, runeID);
return (CharacterRune) getObjectSingle(runeID); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `UID`=?")) {
preparedStatement.setInt(1, runeID);
ResultSet rs = preparedStatement.executeQuery();
characterRune = (CharacterRune) getObjectFromRs(rs);
} catch (SQLException e) {
Logger.error(e);
}
return characterRune;
} }
public boolean DELETE_CHARACTER_RUNE(final CharacterRune characterRune) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `dyn_character_rune` WHERE `UID`=?;")) {
preparedStatement.setLong(1, characterRune.getObjectUUID());
return (preparedStatement.executeUpdate() > 0);
} catch (SQLException e) {
Logger.error(e);
return false;
}
public boolean DELETE_CHARACTER_RUNE(final CharacterRune cr) {
prepareCallable("DELETE FROM `dyn_character_rune` WHERE `UID`=?;");
setLong(1, (long)cr.getObjectUUID());
return (executeUpdate() != 0);
} }
public ArrayList<CharacterRune> GET_RUNES_FOR_CHARACTER(final int characterId) { public ArrayList<CharacterRune> GET_RUNES_FOR_CHARACTER(final int characterId) {
prepareCallable("SELECT * FROM `dyn_character_rune` WHERE `CharacterID` = ?");
setInt(1, characterId); ArrayList<CharacterRune> characterRunes = new ArrayList<>();
return getObjectList();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_character_rune` WHERE `CharacterID` = ?")) {
preparedStatement.setInt(1, characterId);
ResultSet rs = preparedStatement.executeQuery();
characterRunes = getObjectsFromRs(rs, 10);
} catch (SQLException e) {
Logger.error(e);
}
return characterRunes;
} }
public void updateDatabase(final CharacterRune cr) { public void updateDatabase(final CharacterRune characterRune) {
prepareCallable("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?");
setInt(1, cr.getPlayerID()); try (Connection connection = DbManager.getConnection();
setInt(2, cr.getRuneBaseID()); PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?")) {
setLong(3, (long) cr.getObjectUUID());
executeUpdate(); preparedStatement.setInt(1, characterRune.getPlayerID());
preparedStatement.setInt(2, characterRune.getRuneBaseID());
preparedStatement.setLong(3, (long) characterRune.getObjectUUID());
preparedStatement.execute();
} catch (SQLException e) {
Logger.error(e);
}
} }
} }

2
src/engine/db/handlers/dbItemHandler.java

@ -172,7 +172,7 @@ public class dbItemHandler extends dbHandlerBase {
preparedStatement.setLong(1, (long) targetId); preparedStatement.setLong(1, (long) targetId);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
itemList = getObjectsFromRs(rs, 50); itemList = getObjectsFromRs(rs, 10);
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e); Logger.error(e);

Loading…
Cancel
Save