From 98237cd53ee398a185350dd343833b72677bd5fa Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 23 May 2023 08:33:14 -0400 Subject: [PATCH] Refactor to remove abstraction. --- .../db/handlers/dbVendorDialogHandler.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/engine/db/handlers/dbVendorDialogHandler.java b/src/engine/db/handlers/dbVendorDialogHandler.java index def139f2..eb6a1c92 100644 --- a/src/engine/db/handlers/dbVendorDialogHandler.java +++ b/src/engine/db/handlers/dbVendorDialogHandler.java @@ -12,6 +12,12 @@ package engine.db.handlers; import engine.Enum; import engine.gameManager.DbManager; import engine.objects.VendorDialog; +import org.pmw.tinylog.Logger; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; public class dbVendorDialogHandler extends dbHandlerBase { @@ -21,11 +27,24 @@ public class dbVendorDialogHandler extends dbHandlerBase { } public VendorDialog GET_VENDORDIALOG(final int objectUUID) { - VendorDialog vd = (VendorDialog) DbManager.getFromCache(Enum.GameObjectType.VendorDialog, objectUUID); - if (vd != null) - return vd; - prepareCallable("SELECT * FROM `static_npc_vendordialog` WHERE `ID`=?"); - setInt(1, objectUUID); - return (VendorDialog) getObjectSingle(objectUUID); + + VendorDialog vendorDialog = (VendorDialog) DbManager.getFromCache(Enum.GameObjectType.VendorDialog, objectUUID); + + if (vendorDialog != null) + return vendorDialog; + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_npc_vendordialog` WHERE `ID`=?")) { + + preparedStatement.setInt(1, objectUUID); + + ResultSet rs = preparedStatement.executeQuery(); + vendorDialog = (VendorDialog) getObjectFromRs(rs); + + } catch (SQLException e) { + Logger.error(e); + } + + return vendorDialog; } }