From 9bdbeeaf70c5911e264058f9d341d8ef068c406c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 22 May 2023 13:00:47 -0400 Subject: [PATCH] Refactor to remove abstraction. --- src/engine/db/handlers/dbRunegateHandler.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/engine/db/handlers/dbRunegateHandler.java b/src/engine/db/handlers/dbRunegateHandler.java index c0cc5b01..50b928b0 100644 --- a/src/engine/db/handlers/dbRunegateHandler.java +++ b/src/engine/db/handlers/dbRunegateHandler.java @@ -15,6 +15,8 @@ import engine.objects.Building; import engine.objects.Portal; 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; @@ -29,17 +31,18 @@ public class dbRunegateHandler extends dbHandlerBase { ArrayList gateList = new ArrayList<>(); - prepareCallable("SELECT DISTINCT `sourceBuilding` FROM `static_runegate_portals`;"); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT DISTINCT `sourceBuilding` FROM `static_runegate_portals`;")) { - try { - ResultSet rs = executeQuery(); - while (rs.next()) { + ResultSet rs = preparedStatement.executeQuery(); + + while (rs.next()) gateList.add(rs.getInt("sourceBuilding")); - } + } catch (SQLException e) { - } finally { - closeCallable(); + Logger.error(e); } + return gateList; } @@ -48,11 +51,12 @@ public class dbRunegateHandler extends dbHandlerBase { ArrayList portalList = new ArrayList<>(); Building sourceBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, gateUID); - prepareCallable("SELECT * FROM `static_runegate_portals` WHERE `sourceBuilding` = ?;"); - setInt(1, gateUID); + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_runegate_portals` WHERE `sourceBuilding` = ?;")) { + + preparedStatement.setInt(1, gateUID); - try { - ResultSet rs = executeQuery(); + ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { int targetBuildingID = rs.getInt("targetBuilding"); @@ -63,9 +67,7 @@ public class dbRunegateHandler extends dbHandlerBase { } } catch (SQLException e) { - Logger.error("Exception while loading runegate portals: " + e); - } finally { - closeCallable(); + Logger.error(e); } return portalList; }