|
|
|
@ -12,8 +12,12 @@ package engine.db.handlers;
@@ -12,8 +12,12 @@ 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 { |
|
|
|
@ -47,47 +51,73 @@ public class dbZoneHandler extends dbHandlerBase {
@@ -47,47 +51,73 @@ public class dbZoneHandler extends dbHandlerBase {
|
|
|
|
|
public Zone GET_BY_UID(long ID) { |
|
|
|
|
|
|
|
|
|
Zone zone = (Zone) DbManager.getFromCache(Enum.GameObjectType.Zone, (int) ID); |
|
|
|
|
|
|
|
|
|
if (zone != null) |
|
|
|
|
return zone; |
|
|
|
|
prepareCallable("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;"); |
|
|
|
|
setLong(1, ID); |
|
|
|
|
return (Zone) getObjectSingle((int) ID); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ArrayList<Zone> GET_MAP_NODES(final int objectUUID) { |
|
|
|
|
prepareCallable("SELECT `obj_zone`.*, `object`.`parent` FROM `object` INNER JOIN `obj_zone` ON `obj_zone`.`UID` = `object`.`UID` WHERE `object`.`parent` = ?;"); |
|
|
|
|
setLong(1, (long) objectUUID); |
|
|
|
|
return getObjectList(); |
|
|
|
|
return zone; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ResultSet GET_ZONE_EXTENTS(final int loadNum) { |
|
|
|
|
prepareCallable("SELECT * FROM `static_zone_size` WHERE `loadNum`=?;"); |
|
|
|
|
setInt(1, loadNum); |
|
|
|
|
return executeQuery(); |
|
|
|
|
public ArrayList<Zone> GET_MAP_NODES(final int objectUUID) { |
|
|
|
|
|
|
|
|
|
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 `object`.`parent` = ?;")) { |
|
|
|
|
|
|
|
|
|
preparedStatement.setLong(1, (long) objectUUID); |
|
|
|
|
|
|
|
|
|
ResultSet rs = preparedStatement.executeQuery(); |
|
|
|
|
zoneList = getObjectsFromRs(rs, 2000); |
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
Logger.error(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String SET_PROPERTY(final Zone z, String name, Object new_value) { |
|
|
|
|
prepareCallable("CALL zone_SETPROP(?,?,?)"); |
|
|
|
|
setLong(1, (long) z.getObjectUUID()); |
|
|
|
|
setString(2, name); |
|
|
|
|
setString(3, String.valueOf(new_value)); |
|
|
|
|
return getResult(); |
|
|
|
|
return zoneList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String SET_PROPERTY(final Zone z, String name, Object new_value, Object old_value) { |
|
|
|
|
prepareCallable("CALL zone_GETSETPROP(?,?,?,?)"); |
|
|
|
|
setLong(1, (long) z.getObjectUUID()); |
|
|
|
|
setString(2, name); |
|
|
|
|
setString(3, String.valueOf(new_value)); |
|
|
|
|
setString(4, String.valueOf(old_value)); |
|
|
|
|
return getResult(); |
|
|
|
|
public ResultSet GET_ZONE_EXTENTS(final int loadNum) { |
|
|
|
|
|
|
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_zone_size` WHERE `loadNum`=?;")) { |
|
|
|
|
|
|
|
|
|
preparedStatement.setInt(1, loadNum); |
|
|
|
|
|
|
|
|
|
return preparedStatement.executeQuery(); |
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
Logger.error(e); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public boolean DELETE_ZONE(final Zone zone) { |
|
|
|
|
|
|
|
|
|
prepareCallable("DELETE FROM `object` WHERE `UID` = ? AND `type` = 'zone'"); |
|
|
|
|
setInt(1, zone.getObjectUUID()); |
|
|
|
|
return (executeUpdate() != 0); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|