Browse Source

Duplicate key logic makes sense here.

combat-2
MagicBot 8 months ago
parent
commit
aa0afa533d
  1. 5
      src/engine/db/handlers/dbWarehouseHandler.java
  2. 2
      src/engine/objects/Warehouse.java

5
src/engine/db/handlers/dbWarehouseHandler.java

@ -87,10 +87,11 @@ public class dbWarehouseHandler extends dbHandlerBase {
JSONObject warehouseJSON = new JSONObject(warehouse.resources); JSONObject warehouseJSON = new JSONObject(warehouse.resources);
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_warehouse` SET `warehouse` = ? WHERE `cityUID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse` (`cityUUID`, `warehouse`) VALUES (?, ?) " +
"ON DUPLICATE KEY UPDATE `warehouse` = VALUES(`warehouse`)")) {
preparedStatement.setString(2, warehouseJSON.toString());
preparedStatement.setInt(1, warehouse.city.getObjectUUID()); preparedStatement.setInt(1, warehouse.city.getObjectUUID());
preparedStatement.setString(2, warehouseJSON.toString());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);

2
src/engine/objects/Warehouse.java

@ -46,7 +46,7 @@ public class Warehouse {
resources.put(resourceType, value); resources.put(resourceType, value);
} }
JSONArray lockedResources = (JSONArray) warehouse.get("locked"); JSONArray lockedResources = (JSONArray) warehouse.get("locks");
if (lockedResources.isEmpty() == false) if (lockedResources.isEmpty() == false)
for (Object o : lockedResources) for (Object o : lockedResources)

Loading…
Cancel
Save