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

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

@ -12,7 +12,12 @@ package engine.db.handlers; @@ -12,7 +12,12 @@ package engine.db.handlers;
import engine.Enum;
import engine.gameManager.DbManager;
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;
public class dbCharacterRuneHandler extends dbHandlerBase {
@ -23,41 +28,98 @@ public class dbCharacterRuneHandler extends dbHandlerBase { @@ -23,41 +28,98 @@ public class dbCharacterRuneHandler extends dbHandlerBase {
}
public CharacterRune ADD_CHARACTER_RUNE(final CharacterRune toAdd) {
prepareCallable("INSERT INTO `dyn_character_rune` (`CharacterID`, `RuneBaseID`) VALUES (?, ?);");
setLong(1, (long)toAdd.getPlayerID());
setInt(2, toAdd.getRuneBaseID());
int runeID = insertGetUUID();
return GET_CHARACTER_RUNE(runeID);
CharacterRune characterRune = null;
try (Connection connection = DbManager.getConnection();
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) {
CharacterRune charRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID);
if (charRune != null)
return charRune;
prepareCallable("SELECT * FROM `dyn_character_rune` WHERE `UID`=?");
setInt(1, runeID);
return (CharacterRune) getObjectSingle(runeID);
CharacterRune characterRune = (CharacterRune) DbManager.getFromCache(Enum.GameObjectType.CharacterRune, runeID);
if (characterRune != null)
return characterRune;
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) {
prepareCallable("SELECT * FROM `dyn_character_rune` WHERE `CharacterID` = ?");
setInt(1, characterId);
return getObjectList();
ArrayList<CharacterRune> characterRunes = new ArrayList<>();
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) {
prepareCallable("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?");
setInt(1, cr.getPlayerID());
setInt(2, cr.getRuneBaseID());
setLong(3, (long) cr.getObjectUUID());
executeUpdate();
public void updateDatabase(final CharacterRune characterRune) {
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_character_rune` SET `CharacterID`=?, `RuneBaseID`=? WHERE `UID` = ?")) {
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 { @@ -172,7 +172,7 @@ public class dbItemHandler extends dbHandlerBase {
preparedStatement.setLong(1, (long) targetId);
ResultSet rs = preparedStatement.executeQuery();
itemList = getObjectsFromRs(rs, 50);
itemList = getObjectsFromRs(rs, 10);
} catch (SQLException e) {
Logger.error(e);

Loading…
Cancel
Save