|
|
@ -13,7 +13,12 @@ import engine.gameManager.DbManager; |
|
|
|
import engine.objects.Mine; |
|
|
|
import engine.objects.Mine; |
|
|
|
import engine.objects.MineProduction; |
|
|
|
import engine.objects.MineProduction; |
|
|
|
import engine.objects.Resource; |
|
|
|
import engine.objects.Resource; |
|
|
|
|
|
|
|
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; |
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
|
|
|
|
public class dbMineHandler extends dbHandlerBase { |
|
|
|
public class dbMineHandler extends dbHandlerBase { |
|
|
@ -29,68 +34,103 @@ public class dbMineHandler extends dbHandlerBase { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
Mine mine = (Mine) DbManager.getFromCache(Enum.GameObjectType.Mine, id); |
|
|
|
Mine mine = (Mine) DbManager.getFromCache(Enum.GameObjectType.Mine, id); |
|
|
|
|
|
|
|
|
|
|
|
if (mine != null) |
|
|
|
if (mine != null) |
|
|
|
return mine; |
|
|
|
return mine; |
|
|
|
|
|
|
|
|
|
|
|
prepareCallable("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;"); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_building`.*, `object`.`parent` FROM `object` INNER JOIN `obj_building` ON `obj_building`.`UID` = `object`.`UID` WHERE `object`.`UID` = ?;")) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.setLong(1, id); |
|
|
|
|
|
|
|
|
|
|
|
setLong(1, (long) id); |
|
|
|
ResultSet rs = preparedStatement.executeQuery(); |
|
|
|
return (Mine) getObjectSingle(id); |
|
|
|
mine = (Mine) getObjectFromRs(rs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return mine; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<Mine> GET_ALL_MINES_FOR_SERVER() { |
|
|
|
public ArrayList<Mine> GET_ALL_MINES_FOR_SERVER() { |
|
|
|
prepareCallable("SELECT `obj_mine`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mine` ON `obj_mine`.`UID` = `object`.`UID`"); |
|
|
|
|
|
|
|
return getObjectList(); |
|
|
|
ArrayList<Mine> mines = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("SELECT `obj_mine`.*, `object`.`parent` FROM `object` INNER JOIN `obj_mine` ON `obj_mine`.`UID` = `object`.`UID`")) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResultSet rs = preparedStatement.executeQuery(); |
|
|
|
|
|
|
|
mines = getObjectsFromRs(rs, 1000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return mines; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean CHANGE_OWNER(Mine mine, int playerUID) { |
|
|
|
public boolean CHANGE_OWNER(Mine mine, int playerUID) { |
|
|
|
prepareCallable("UPDATE `obj_mine` SET `mine_ownerUID`=? WHERE `UID`=?"); |
|
|
|
|
|
|
|
setInt(1, playerUID); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
setLong(2, (long) mine.getObjectUUID()); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_ownerUID`=? WHERE `UID`=?")) { |
|
|
|
return (executeUpdate() > 0); |
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.setInt(1, playerUID); |
|
|
|
|
|
|
|
preparedStatement.setLong(2, mine.getObjectUUID()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (preparedStatement.executeUpdate() > 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean CHANGE_RESOURCE(Mine mine, Resource resource) { |
|
|
|
public boolean CHANGE_RESOURCE(Mine mine, Resource resource) { |
|
|
|
prepareCallable("UPDATE `obj_mine` SET `mine_resource`=? WHERE `UID`=?"); |
|
|
|
|
|
|
|
setString(1, resource.name()); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
setLong(2, (long) mine.getObjectUUID()); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_resource`=? WHERE `UID`=?")) { |
|
|
|
return (executeUpdate() > 0); |
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.setString(1, resource.name()); |
|
|
|
|
|
|
|
preparedStatement.setLong(2, mine.getObjectUUID()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (preparedStatement.executeUpdate() > 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean CHANGE_TYPE(Mine mine, MineProduction productionType) { |
|
|
|
public boolean CHANGE_TYPE(Mine mine, MineProduction productionType) { |
|
|
|
prepareCallable("UPDATE `obj_mine` SET `mine_type`=? WHERE `UID`=?"); |
|
|
|
|
|
|
|
setString(1, productionType.name()); |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
setLong(2, (long) mine.getObjectUUID()); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `mine_type`=? WHERE `UID`=?")) { |
|
|
|
return (executeUpdate() > 0); |
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.setString(1, productionType.name()); |
|
|
|
|
|
|
|
preparedStatement.setLong(2, mine.getObjectUUID()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (preparedStatement.executeUpdate() > 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
Logger.error(e); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean SET_FLAGS(Mine mine, int newFlags) { |
|
|
|
public boolean SET_FLAGS(Mine mine, int newFlags) { |
|
|
|
prepareCallable("UPDATE `obj_mine` SET `flags`=? WHERE `UID`=?"); |
|
|
|
|
|
|
|
setInt(1, newFlags); |
|
|
|
|
|
|
|
setLong(2, (long) mine.getObjectUUID()); |
|
|
|
|
|
|
|
return (executeUpdate() > 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String SET_PROPERTY(final Mine m, String name, Object new_value) { |
|
|
|
try (Connection connection = DbManager.getConnection(); |
|
|
|
prepareCallable("CALL mine_SETPROP(?,?,?)"); |
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_mine` SET `flags`=? WHERE `UID`=?")) { |
|
|
|
setLong(1, (long) m.getObjectUUID()); |
|
|
|
|
|
|
|
setString(2, name); |
|
|
|
preparedStatement.setInt(1, newFlags); |
|
|
|
setString(3, String.valueOf(new_value)); |
|
|
|
preparedStatement.setLong(2, mine.getObjectUUID()); |
|
|
|
return getResult(); |
|
|
|
|
|
|
|
} |
|
|
|
return (preparedStatement.executeUpdate() > 0); |
|
|
|
|
|
|
|
|
|
|
|
// Advance all the mine windows respective to the current day
|
|
|
|
} catch (SQLException e) { |
|
|
|
// at boot time. This ensures that mines always go live
|
|
|
|
Logger.error(e); |
|
|
|
// no matter what date in the database
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
public String SET_PROPERTY(final Mine m, String name, Object new_value, Object old_value) { |
|
|
|
|
|
|
|
prepareCallable("CALL mine_GETSETPROP(?,?,?,?)"); |
|
|
|
|
|
|
|
setLong(1, (long) m.getObjectUUID()); |
|
|
|
|
|
|
|
setString(2, name); |
|
|
|
|
|
|
|
setString(3, String.valueOf(new_value)); |
|
|
|
|
|
|
|
setString(4, String.valueOf(old_value)); |
|
|
|
|
|
|
|
return getResult(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|