Migrate dbWarehouseHandler.java from JodaTime to java.time.*
Completed migration of JodaTime references in dbWarehouseHandler.java:
This commit is contained in:
@@ -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
|
||||||
@@ -16,7 +16,7 @@ import engine.gameManager.DbManager;
|
|||||||
import engine.math.Vector3fImmutable;
|
import engine.math.Vector3fImmutable;
|
||||||
import engine.objects.*;
|
import engine.objects.*;
|
||||||
import engine.server.MBServerStatics;
|
import engine.server.MBServerStatics;
|
||||||
import org.joda.time.DateTime;
|
import java.time.Instant;
|
||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -55,7 +55,7 @@ public class dbWarehouseHandler extends dbHandlerBase {
|
|||||||
public ArrayList<AbstractGameObject> CREATE_WAREHOUSE(int parentZoneID, int OwnerUUID, String name, int meshUUID,
|
public ArrayList<AbstractGameObject> CREATE_WAREHOUSE(int parentZoneID, int OwnerUUID, String name, int meshUUID,
|
||||||
Vector3fImmutable location, float meshScale, int currentHP,
|
Vector3fImmutable location, float meshScale, int currentHP,
|
||||||
ProtectionState protectionState, int currentGold, int rank,
|
ProtectionState protectionState, int currentGold, int rank,
|
||||||
DateTime upgradeDate, int blueprintUUID, float w, float rotY) {
|
Instant upgradeDate, int blueprintUUID, float w, float rotY) {
|
||||||
|
|
||||||
ArrayList<AbstractGameObject> warehouseList = new ArrayList<>();
|
ArrayList<AbstractGameObject> warehouseList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class dbWarehouseHandler extends dbHandlerBase {
|
|||||||
preparedStatement.setInt(12, rank);
|
preparedStatement.setInt(12, rank);
|
||||||
|
|
||||||
if (upgradeDate != null)
|
if (upgradeDate != null)
|
||||||
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.getMillis()));
|
preparedStatement.setTimestamp(13, new java.sql.Timestamp(upgradeDate.toEpochMilli()));
|
||||||
else
|
else
|
||||||
preparedStatement.setNull(13, java.sql.Types.DATE);
|
preparedStatement.setNull(13, java.sql.Types.DATE);
|
||||||
|
|
||||||
@@ -487,7 +487,7 @@ public class dbWarehouseHandler extends dbHandlerBase {
|
|||||||
return false;
|
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();
|
try (Connection connection = DbManager.getConnection();
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO `dyn_warehouse_transactions` (`warehouseUID`, `targetType`,`targetUID`, `type`,`resource`,`amount`,`date` ) VALUES (?,?,?,?,?,?,?)")) {
|
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(4, transactionType.name());
|
||||||
preparedStatement.setString(5, resource.name());
|
preparedStatement.setString(5, resource.name());
|
||||||
preparedStatement.setInt(6, amount);
|
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);
|
return (preparedStatement.executeUpdate() > 0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user