working on backend-side translations

This commit is contained in:
2025-12-15 21:17:45 +01:00
parent 0c909d6d7c
commit a275b5065d
4 changed files with 35 additions and 37 deletions

View File

@@ -516,18 +516,18 @@ public class SqliteDb extends BaseDb implements StockDb {
while (rs.next()){
var oldId = rs.getString(ID);
var parts = oldId.split(":");
if (parts.length != 3) throw databaseException("Expected old item id to be of the form ss:dd:dd, encountered {0}!",oldId);
if (parts.length != 3) throw databaseException(UNEXPECTED_ITEM_ID_FORMAT,oldId);
var owner = String.join(":",parts[0], parts[1]);
long ownerNumber;
try {
ownerNumber = Long.parseLong(parts[2]);
} catch (NumberFormatException e) {
throw databaseException("Expected old item id to be of the form ss:dd:dd, encountered {0}!",oldId);
throw databaseException(UNEXPECTED_ITEM_ID_FORMAT,oldId).causedBy(e);
}
var oldLocationId = rs.getString(LOCATION_ID);
var locationId = oldLocationIdsToNew.get(oldLocationId);
if (locationId == null) throw databaseException("Item {0} of {1} {2} refers to location {3}, which is unknown!",oldId,parts[0],parts[1],oldLocationId);
if (locationId == null) throw databaseException(UNKNOWN_ITEM_LOCATION,oldId,parts[0],parts[1],oldLocationId);
var rs2 = insert.values(owner, ownerNumber, locationId, rs.getString(CODE), rs.getString(NAME)).execute(db).getGeneratedKeys();
oldToNew.put(oldId,rs2.getLong(1));
rs2.close();
@@ -572,9 +572,7 @@ public class SqliteDb extends BaseDb implements StockDb {
while (rs.next()){
var oldItemId = rs.getString(ITEM_ID);
var itemId = oldItemIdsToNew.get(oldItemId);
if (itemId == null) {
throw databaseException("Old item id ({0}) has no new counterpart!",oldItemId);
}
if (itemId == null) throw databaseException(MISSING_NEW_ITEM_ID,oldItemId);
insert.values(itemId, rs.getLong(PROPERTY_ID), rs.getString(VALUE));
}
rs.close();
@@ -600,8 +598,7 @@ public class SqliteDb extends BaseDb implements StockDb {
db.rollback();
} catch (SQLException ignored) {
}
LOG.log(ERROR,"Failed to transform {0} table!",TABLE_LOCATIONS,e);
throw databaseException("Failed to transform {0} table!",TABLE_LOCATIONS);
throw databaseException(FAILED_TO_UPDATE_TABLE,TABLE_LOCATIONS).causedBy(e);
}
}
@@ -612,11 +609,7 @@ public class SqliteDb extends BaseDb implements StockDb {
var note = entry.getValue();
var oldEntityId = note.entityId();
var newEntityId = oldItemIdsToNew.get(oldEntityId);
if (newEntityId != null){
noteService.save(note.entityId(""+newEntityId));
}
if (newEntityId != null) noteService.save(note.entityId(""+newEntityId));
}
}
}