Browse Source

Refactor to remove abstraction.

master
MagicBot 2 years ago
parent
commit
3e604b53fa
  1. 1
      src/engine/db/handlers/dbRuneBaseEffectHandler.java
  2. 116
      src/engine/db/handlers/dbRuneBaseHandler.java

1
src/engine/db/handlers/dbRuneBaseEffectHandler.java

@ -55,7 +55,6 @@ public class dbRuneBaseEffectHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect`;")) { PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect`;")) {
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
runeBaseEffectsList = getObjectsFromRs(rs, 250); runeBaseEffectsList = getObjectsFromRs(rs, 250);

116
src/engine/db/handlers/dbRuneBaseHandler.java

@ -9,14 +9,16 @@
package engine.db.handlers; package engine.db.handlers;
import engine.gameManager.DbManager;
import engine.objects.RuneBase; import engine.objects.RuneBase;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
public class dbRuneBaseHandler extends dbHandlerBase { public class dbRuneBaseHandler extends dbHandlerBase {
@ -26,11 +28,13 @@ public class dbRuneBaseHandler extends dbHandlerBase {
} }
public void GET_RUNE_REQS(final RuneBase rb) { public void GET_RUNE_REQS(final RuneBase rb) {
prepareCallable("SELECT * FROM `static_rune_runereq` WHERE `runeID` = ?");
setInt(1, rb.getObjectUUID());
try {
ResultSet rs = executeQuery(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runereq` WHERE `runeID` = ?")) {
preparedStatement.setInt(1, rb.getObjectUUID());
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) { while (rs.next()) {
int type = rs.getInt("type"); int type = rs.getInt("type");
@ -56,36 +60,58 @@ public class dbRuneBaseHandler extends dbHandlerBase {
break; break;
} }
} }
rs.close();
} catch (SQLException e) { } catch (SQLException e) {
Logger.error("SQL Error number: " + e.getErrorCode()); Logger.error(e);
} finally {
closeCallable();
} }
} }
public RuneBase GET_RUNEBASE(final int id) { public RuneBase GET_RUNEBASE(final int id) {
prepareCallable("SELECT * FROM `static_rune_runebase` WHERE `ID` = ?");
setInt(1, id); RuneBase runeBase = null;
return (RuneBase) getObjectSingle(id);
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase` WHERE `ID` = ?")) {
preparedStatement.setInt(1, id);
ResultSet rs = preparedStatement.executeQuery();
runeBase = (RuneBase) getObjectFromRs(rs);
} catch (SQLException e) {
Logger.error(e);
}
return runeBase;
} }
public ArrayList<RuneBase> LOAD_ALL_RUNEBASES() { public ArrayList<RuneBase> LOAD_ALL_RUNEBASES() {
prepareCallable("SELECT * FROM `static_rune_runebase`;");
return getObjectList(); ArrayList<RuneBase> runeBasesList = new ArrayList<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_runebase`;")) {
ResultSet rs = preparedStatement.executeQuery();
runeBasesList = getObjectsFromRs(rs, 1000);
} catch (SQLException e) {
Logger.error(e);
}
return runeBasesList;
} }
public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() { public HashMap<Integer, ArrayList<Integer>> LOAD_ALLOWED_STARTING_RUNES_FOR_BASECLASS() {
HashMap<Integer, ArrayList<Integer>> runeSets; HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();
runeSets = new HashMap<>();
int recordsRead = 0; int recordsRead = 0;
prepareCallable("SELECT * FROM static_rune_baseclassrune"); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_baseclassrune")) {
try { ResultSet rs = preparedStatement.executeQuery();
ResultSet rs = executeQuery();
while (rs.next()) { while (rs.next()) {
@ -94,25 +120,23 @@ public class dbRuneBaseHandler extends dbHandlerBase {
int baseClassID = rs.getInt("BaseClassesID"); int baseClassID = rs.getInt("BaseClassesID");
int runeBaseID = rs.getInt("RuneBaseID"); int runeBaseID = rs.getInt("RuneBaseID");
if (runeSets.get(baseClassID) == null){ if (runeSets.get(baseClassID) == null) {
ArrayList<Integer> runeList = new ArrayList<>(); ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID); runeList.add(runeBaseID);
runeSets.put(baseClassID, runeList); runeSets.put(baseClassID, runeList);
} } else {
else{ ArrayList<Integer> runeList = runeSets.get(baseClassID);
ArrayList<Integer>runeList = runeSets.get(baseClassID);
runeList.add(runeBaseID); runeList.add(runeBaseID);
runeSets.put(baseClassID, runeList); runeSets.put(baseClassID, runeList);
} }
} }
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e.getErrorCode() + ' ' + e.getMessage(), e); Logger.error(e);
} finally {
closeCallable();
} }
Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
return runeSets; return runeSets;
} }
@ -123,10 +147,10 @@ public class dbRuneBaseHandler extends dbHandlerBase {
runeSets = new HashMap<>(); runeSets = new HashMap<>();
int recordsRead = 0; int recordsRead = 0;
prepareCallable("SELECT * FROM static_rune_racerune"); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_rune_racerune")) {
try { ResultSet rs = preparedStatement.executeQuery();
ResultSet rs = executeQuery();
while (rs.next()) { while (rs.next()) {
@ -135,39 +159,21 @@ public class dbRuneBaseHandler extends dbHandlerBase {
int raceID = rs.getInt("RaceID"); int raceID = rs.getInt("RaceID");
int runeBaseID = rs.getInt("RuneBaseID"); int runeBaseID = rs.getInt("RuneBaseID");
if (runeSets.get(raceID) == null){ if (runeSets.get(raceID) == null) {
ArrayList<Integer> runeList = new ArrayList<>(); ArrayList<Integer> runeList = new ArrayList<>();
runeList.add(runeBaseID); runeList.add(runeBaseID);
runeSets.put(raceID, runeList); runeSets.put(raceID, runeList);
} } else {
else{ ArrayList<Integer> runeList = runeSets.get(raceID);
ArrayList<Integer>runeList = runeSets.get(raceID);
runeList.add(runeBaseID); runeList.add(runeBaseID);
runeSets.put(raceID, runeList); runeSets.put(raceID, runeList);
} }
} }
Logger.info( "read: " + recordsRead + " cached: " + runeSets.size());
} catch (SQLException e) { } catch (SQLException e) {
Logger.error(e.getErrorCode() + ' ' + e.getMessage(), e); Logger.error(e);
} finally {
closeCallable();
}
return runeSets;
} }
public ArrayList<RuneBase> GET_RUNEBASE_FOR_BASECLASS(final int id) { Logger.info("read: " + recordsRead + " cached: " + runeSets.size());
prepareCallable("SELECT rb.* FROM static_rune_baseclassrune bcr, static_rune_runebase rb WHERE bcr.RuneBaseID = rb.ID " return runeSets;
+ "&& ( bcr.BaseClassesID = 111111 || bcr.BaseClassesID = ? )");
setInt(1, id);
return getObjectList();
}
public HashSet<RuneBase> GET_RUNEBASE_FOR_RACE(final int id) {
prepareCallable("SELECT rb.* FROM static_rune_racerune rr, static_rune_runebase rb"
+ " WHERE rr.RuneBaseID = rb.ID && ( rr.RaceID = 111111 || rr.RaceID = ?)");
setInt(1, id);
return new HashSet<>(getObjectList());
} }
} }

Loading…
Cancel
Save