// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ // ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ // ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ // Magicbane Emulator Project © 2013 - 2026 // https://www.magicbane.com package engine.db.handlers; import engine.gameManager.DbManager; import engine.mbEnums; import engine.objects.AbstractGameObject; import engine.objects.BaseClass; import engine.objects.PromotionClass; import engine.objects.Race; import engine.objects.RuneBase; import org.pmw.tinylog.Logger; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; public class dbRuneBaseHandler extends dbHandlerBase { public dbRuneBaseHandler() { this.localClass = RuneBase.class; this.localObjectType = mbEnums.GameObjectType.valueOf(this.localClass.getSimpleName()); } // static_rune_lookup is generated for the DB views; a failed write must never stop the boot public static void WRITE_RUNE_LOOKUP() { int rowsWritten = 0; try (Connection connection = DbManager.getConnection(); PreparedStatement deleteStatement = connection.prepareStatement("DELETE FROM `static_rune_lookup`"); PreparedStatement insertStatement = connection.prepareStatement("INSERT INTO `static_rune_lookup` (`ID`, `type`, `name`) VALUES (?, ?, ?)")) { connection.setAutoCommit(false); try { deleteStatement.executeUpdate(); for (Race race : Race.getAllRaces()) { addRuneLookupRow(insertStatement, race.getRaceRuneID(), "RACE", race.getName()); rowsWritten++; } for (AbstractGameObject baseClass : DbManager.getMap(mbEnums.GameObjectType.BaseClass).values()) { addRuneLookupRow(insertStatement, baseClass.getObjectUUID(), "BASECLASS", ((BaseClass) baseClass).getName()); rowsWritten++; } for (AbstractGameObject promotionClass : DbManager.getMap(mbEnums.GameObjectType.PromotionClass).values()) { addRuneLookupRow(insertStatement, promotionClass.getObjectUUID(), "PROMOTION", ((PromotionClass) promotionClass).getName()); rowsWritten++; } insertStatement.executeBatch(); connection.commit(); } catch (SQLException | RuntimeException e) { // Roll back before setAutoCommit(true), which would otherwise commit the delete connection.rollback(); throw e; } finally { connection.setAutoCommit(true); } } catch (Exception e) { Logger.warn("static_rune_lookup not written; DB views keep their old names: " + e.getMessage()); return; } Logger.info("static_rune_lookup: wrote " + rowsWritten + " rows"); } private static void addRuneLookupRow(PreparedStatement insertStatement, int runeID, String type, String name) throws SQLException { insertStatement.setInt(1, runeID); insertStatement.setString(2, type); insertStatement.setString(3, name); insertStatement.addBatch(); } }