// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.db.handlers ;
import engine.Enum ;
import engine.gameManager.DbManager ;
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 = Enum . 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 Zone GET_BY_UID ( long ID ) {
Zone zone = ( Zone ) DbManager . getFromCache ( Enum . 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 ) {
try ( Connection connection = DbManager . getConnection ( ) ;
PreparedStatement preparedStatement = connection . prepareStatement ( "DELETE FROM `object` WHERE `UID` = ? AND `type` = 'zone'" ) ) {
preparedStatement . setInt ( 1 , zone . getObjectUUID ( ) ) ;
return ( preparedStatement . executeUpdate ( ) > 0 ) ;
} catch ( SQLException e ) {
Logger . error ( e ) ;
}
return false ;
}
}