Files
prestonbane/src/engine/db/handlers/dbZoneHandler.java
T

86 lines
3.0 KiB
Java
Raw Normal View History

2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.db.handlers;
import engine.Enum;
import engine.gameManager.DbManager;
import engine.objects.Zone;
2023-05-23 09:57:17 -04:00
import org.pmw.tinylog.Logger;
2022-04-30 09:41:17 -04:00
2023-05-23 09:57:17 -04:00
import java.sql.Connection;
import java.sql.PreparedStatement;
2022-04-30 09:41:17 -04:00
import java.sql.ResultSet;
2023-05-23 09:57:17 -04:00
import java.sql.SQLException;
2022-04-30 09:41:17 -04:00
import java.util.ArrayList;
public class dbZoneHandler extends dbHandlerBase {
2023-07-15 09:23:48 -04:00
public dbZoneHandler() {
this.localClass = Zone.class;
this.localObjectType = Enum.GameObjectType.valueOf(this.localClass.getSimpleName());
}
2022-04-30 09:41:17 -04:00
2023-10-17 08:45:33 -04:00
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;
}
2023-07-15 09:23:48 -04:00
public Zone GET_BY_UID(long ID) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Zone zone = (Zone) DbManager.getFromCache(Enum.GameObjectType.Zone, (int) ID);
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
if (zone != null)
return zone;
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
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` = ?;")) {
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
preparedStatement.setLong(1, ID);
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
ResultSet rs = preparedStatement.executeQuery();
zone = (Zone) getObjectFromRs(rs);
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
return zone;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public boolean DELETE_ZONE(final Zone zone) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("DELETE FROM `object` WHERE `UID` = ? AND `type` = 'zone'")) {
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
preparedStatement.setInt(1, zone.getObjectUUID());
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
return (preparedStatement.executeUpdate() > 0);
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
} catch (SQLException e) {
Logger.error(e);
}
2023-05-23 09:57:17 -04:00
2023-07-15 09:23:48 -04:00
return false;
}
2022-04-30 09:41:17 -04:00
}