From 4b0a3627d495f8f8b870db09e8044b96a2c43aa7 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 22 May 2023 12:50:04 -0400 Subject: [PATCH] Refactor to remove abstraction. --- .../db/handlers/dbRuneBaseEffectHandler.java | 54 +++++++++++++------ 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/engine/db/handlers/dbRuneBaseEffectHandler.java b/src/engine/db/handlers/dbRuneBaseEffectHandler.java index 0e84c8d0..14c51683 100644 --- a/src/engine/db/handlers/dbRuneBaseEffectHandler.java +++ b/src/engine/db/handlers/dbRuneBaseEffectHandler.java @@ -13,7 +13,12 @@ import engine.Enum.GameObjectType; import engine.gameManager.DbManager; import engine.objects.AbstractGameObject; import engine.objects.RuneBaseEffect; +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.HashMap; @@ -25,34 +30,49 @@ public class dbRuneBaseEffectHandler extends dbHandlerBase { } public ArrayList GET_EFFECTS_FOR_RUNEBASE(int id) { - prepareCallable("SELECT * FROM `static_rune_baseeffect` WHERE `runeID`=?"); - setInt(1, id); - return getObjectList(); - } - public RuneBaseEffect GET_RUNEBASE_EFFECT(int id) { + ArrayList runeBaseEffectsList = new ArrayList<>(); + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect` WHERE `runeID`=?")) { + + preparedStatement.setInt(1, id); + + ResultSet rs = preparedStatement.executeQuery(); + runeBaseEffectsList = getObjectsFromRs(rs, 250); - if (id == 0) - return null; - RuneBaseEffect runeBaseEffect = (RuneBaseEffect) DbManager.getFromCache(GameObjectType.RuneBaseEffect, id); - if (runeBaseEffect != null) - return runeBaseEffect; - prepareCallable("SELECT * FROM `static_rune_baseeffect` WHERE `ID` = ?"); - setInt(1, id); - return (RuneBaseEffect) getObjectSingle(id); + } catch (SQLException e) { + Logger.error(e); + } + + return runeBaseEffectsList; } - public ArrayList GET_ALL_RUNEBASE_EFFECTS(){ - prepareCallable("SELECT * FROM `static_rune_baseeffect`;"); - return getObjectList(); + public ArrayList GET_ALL_RUNEBASE_EFFECTS() { + + ArrayList runeBaseEffectsList = new ArrayList<>(); + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_rune_baseeffect`;")) { + + + ResultSet rs = preparedStatement.executeQuery(); + runeBaseEffectsList = getObjectsFromRs(rs, 250); + + } catch (SQLException e) { + Logger.error(e); + } + + return runeBaseEffectsList; } //This calls from cache only. Call this AFTER caching all runebase effects; + public HashMap> LOAD_BASEEFFECTS_FOR_RUNEBASE() { + HashMap> runeBaseEffectSet; runeBaseEffectSet = new HashMap<>(); - for (AbstractGameObject runeBaseEffect:DbManager.getList(GameObjectType.RuneBaseEffect)){ int runeBaseID = ((RuneBaseEffect)runeBaseEffect).getRuneBaseID();