From 8d6457b91c4932a66cdcc6f9ed18180c616a2e14 Mon Sep 17 00:00:00 2001 From: Mike Tinkers Date: Fri, 2 Oct 2026 22:03:34 -0500 Subject: [PATCH] Migrate dbWarehouseHandler.java from JodaTime to java.time.* Completed migration of JodaTime references in dbWarehouseHandler.java: --- JodaTime_Migration_Plan_dbWarehouseHandler.md | 86 +++++++++++++++++++ .../db/handlers/dbWarehouseHandler.java | 10 +-- 2 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 JodaTime_Migration_Plan_dbWarehouseHandler.md diff --git a/JodaTime_Migration_Plan_dbWarehouseHandler.md b/JodaTime_Migration_Plan_dbWarehouseHandler.md new file mode 100644 index 00000000..c689dab6 --- /dev/null +++ b/JodaTime_Migration_Plan_dbWarehouseHandler.md @@ -0,0 +1,86 @@ +# JodaTime to java.time.* Migration Plan: dbWarehouseHandler.java + +## Overview +This document outlines the migration of JodaTime references in `dbWarehouseHandler.java` from `org.joda.time.DateTime` to `java.time.Instant`. + +## Files to be Modified +- `src/engine/db/handlers/dbWarehouseHandler.java` + +## JodaTime References Found +1. Import statement: `import org.joda.time.DateTime;` +2. Method parameter: `DateTime upgradeDate` in method signature (line 58) +3. Method parameter: `DateTime date` in method signature (line 490) +4. Usage of getMillis() method: `upgradeDate.getMillis()` (line 79) +5. Usage of getMillis() method: `date.getMillis()` (line 501) + +## Migration Strategy + +### Step 1: Update Import Statement +Replace: +```java +import org.joda.time.DateTime; +``` +With: +```java +import java.time.Instant; +``` + +### Step 2: Update Method Signatures +Replace: +```java +DateTime upgradeDate +``` +With: +```java +Instant upgradeDate +``` + +Replace: +```java +DateTime date +``` +With: +```java +Instant date +``` + +### Step 3: Update Method Calls +Replace: +```java +upgradeDate.getMillis() +``` +With: +```java +upgradeDate.toEpochMilli() +``` + +Replace: +```java +date.getMillis() +``` +With: +```java +date.toEpochMilli() +``` + +### Step 4: Database Timestamp Handling +The database timestamp handling remains the same as `java.sql.Timestamp` constructor accepts long values (milliseconds since epoch), which can be obtained from `Instant.toEpochMilli()`. + +## Implementation Plan + +1. Update import statement from `org.joda.time.DateTime` to `java.time.Instant` +2. Update method signature for `upgradeDate` parameter from `DateTime` to `Instant` +3. Update method signature for `date` parameter from `DateTime` to `Instant` +4. Replace `upgradeDate.getMillis()` with `upgradeDate.toEpochMilli()` +5. Replace `date.getMillis()` with `date.toEpochMilli()` + +## Testing Considerations +- Ensure the network packet serialization format remains unchanged +- Verify database operations work correctly with Instant values +- Test warehouse creation and transaction creation functionality +- Confirm that all existing functionality continues to work as expected + +## Compatibility Notes +- The migration maintains backward compatibility with database operations since `java.sql.Timestamp` constructor accepts milliseconds +- Network packet structure remains the same (no serialization changes needed) +- Thread safety improvements from using java.time.* classes \ No newline at end of file diff --git a/src/engine/db/handlers/dbWarehouseHandler.java b/src/engine/db/handlers/dbWarehouseHandler.java index 677e67eb..16c11fea 100644 --- a/src/engine/db/handlers/dbWarehouseHandler.java +++ b/src/engine/db/handlers/dbWarehouseHandler.java @@ -16,7 +16,7 @@ import engine.gameManager.DbManager; import engine.math.Vector3fImmutable; import engine.objects.*; import engine.server.MBServerStatics; -import org.joda.time.DateTime; +import java.time.Instant; import org.pmw.tinylog.Logger; import java.sql.Connection; @@ -55,7 +55,7 @@ public class dbWarehouseHandler extends dbHandlerBase { public ArrayList CREATE_WAREHOUSE(int parentZoneID, int OwnerUUID, String name, int meshUUID, Vector3fImmutable location, float meshScale, int currentHP, ProtectionState protectionState, int currentGold, int rank, - DateTime upgradeDate, int blueprintUUID, float w, float rotY) { + Instant upgradeDate, int blueprintUUID, float w, float rotY) { ArrayList warehouseList = new ArrayList<>(); @@ -76,7 +76,7 @@ public class dbWarehouseHandler extends dbHandlerBase { preparedStatement.setInt(12, rank); if (upgradeDate != null) - preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis())); + preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.toEpochMilli())); else preparedStatement.setNull(13, java.sql.Types.DATE); @@ -487,7 +487,7 @@ public class dbWarehouseHandler extends dbHandlerBase { return false; } - public boolean CREATE_TRANSACTION(int warehouseBuildingID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount, DateTime date) { + public boolean CREATE_TRANSACTION(int warehouseBuildingID, GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount, Instant date) { try (Connection connection = DbManager.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse_transactions` (`warehouseUID`, `targetType`,`targetUID`, `type`,`resource`,`amount`,`date` ) VALUES (?,?,?,?,?,?,?)")) { @@ -498,7 +498,7 @@ public class dbWarehouseHandler extends dbHandlerBase { preparedStatement.setString(4, transactionType.name()); preparedStatement.setString(5, resource.name()); preparedStatement.setInt(6, amount); - preparedStatement.setTimestamp(7, new java.sql.Timestamp(date.getMillis())); + preparedStatement.setTimestamp(7, new java.sql.Timestamp(date.toEpochMilli())); return (preparedStatement.executeUpdate() > 0);