The object.parent foreign key (ref_parent, ON DELETE CASCADE) is dropped in World Boot Plan 2.4: static zones and buildings leave the DB, so rows under them get negative parents that no object row holds. deleteObjectTree deletes an object and every row below it by parent in one transaction, which is what the cascade did. Used by the building, guild, mob, NPC and zone delete paths (city destroy relies on it for the city, NPCs and mobs). Value changes: none; the same rows are deleted, and the FK is still in place until the 2.4 migration runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
3.4 KiB
Java
95 lines
3.4 KiB
Java
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
// Magicbane Emulator Project © 2013 - 2026
|
|
// https://www.magicbane.com
|
|
|
|
|
|
package engine.db.handlers;
|
|
|
|
import engine.gameManager.DbManager;
|
|
import engine.mbEnums;
|
|
import engine.objects.Zone;
|
|
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;
|
|
|
|
public class dbZoneHandler extends dbHandlerBase {
|
|
|
|
public dbZoneHandler() {
|
|
this.localClass = Zone.class;
|
|
this.localObjectType = mbEnums.GameObjectType.valueOf(this.localClass.getSimpleName());
|
|
}
|
|
|
|
public ArrayList<Zone> GET_ALL_ZONES() {
|
|
|
|
ArrayList<Zone> zoneList = new ArrayList<>();
|
|
|
|
try (Connection connection = DbManager.getConnection();
|
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` ORDER BY `object`.`UID` ASC;")) {
|
|
|
|
ResultSet rs = preparedStatement.executeQuery();
|
|
zoneList = getObjectsFromRs(rs, 2000);
|
|
|
|
} catch (SQLException e) {
|
|
Logger.error(e);
|
|
}
|
|
|
|
return zoneList;
|
|
}
|
|
|
|
public ArrayList<Zone> GET_PLAYER_CITY_ZONES() {
|
|
|
|
ArrayList<Zone> zoneList = new ArrayList<>();
|
|
|
|
try (Connection connection = DbManager.getConnection();
|
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `obj_zone`.`template` = 0 ORDER BY `object`.`UID` ASC;")) {
|
|
|
|
ResultSet rs = preparedStatement.executeQuery();
|
|
zoneList = getObjectsFromRs(rs, 200);
|
|
|
|
} catch (SQLException e) {
|
|
Logger.error(e);
|
|
}
|
|
|
|
return zoneList;
|
|
}
|
|
|
|
public Zone GET_BY_UID(long ID) {
|
|
|
|
Zone zone = (Zone) DbManager.getFromCache(mbEnums.GameObjectType.Zone, (int) ID);
|
|
|
|
if (zone != null)
|
|
return zone;
|
|
|
|
try (Connection connection = DbManager.getConnection();
|
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) {
|
|
|
|
preparedStatement.setLong(1, ID);
|
|
|
|
ResultSet rs = preparedStatement.executeQuery();
|
|
zone = (Zone) getObjectFromRs(rs);
|
|
|
|
} catch (SQLException e) {
|
|
Logger.error(e);
|
|
}
|
|
|
|
return zone;
|
|
}
|
|
|
|
public boolean DELETE_ZONE(final Zone zone) {
|
|
|
|
if (DbManager.refuseStaticWrite(zone))
|
|
return false;
|
|
|
|
return deleteObjectTree(zone.getObjectUUID(), "zone") > 0;
|
|
}
|
|
|
|
}
|