added plenty of logging, updateed tools.jdbc

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2025-12-02 11:23:04 +01:00
parent a3bcc66b73
commit e887a13bbb
2 changed files with 13 additions and 2 deletions

View File

@@ -11,7 +11,9 @@ import static de.srsoftware.umbrella.core.ModuleRegistry.companyService;
import static de.srsoftware.umbrella.core.ModuleRegistry.translator;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.stock.Constants.TABLE_ITEMS;
import static java.lang.System.Logger.Level.DEBUG;
import de.srsoftware.tools.ColorLogger;
import de.srsoftware.tools.Tuple;
import de.srsoftware.umbrella.core.ModuleRegistry;
import de.srsoftware.umbrella.core.model.*;
@@ -31,8 +33,10 @@ public class ItemDb {
public void migrateTo(StockDb stockDb) {
try {
ColorLogger.setLogLevel("Query",DEBUG);
var companyLocations = new HashMap<Long,Location>();
var companyInfo = new HashMap<Long, Tuple<Company,String>>(); // map from companyId → (company, language)
LOG.log(DEBUG,"Reading items:\nid: code / name / unit / price / tax rate");
var rs = select(ALL).from(TABLE_ITEMS).exec(db);
while (rs.next()){
var id = rs.getLong(ID);
@@ -44,13 +48,17 @@ public class ItemDb {
var unitPrice = rs.getLong(UNIT_PRICE);
var tax = rs.getLong(TAX);
var tuple = companyInfo.get(companyId);
LOG.log(DEBUG," - read item {0}: {1} / {2} / {3} / {4} / {5} %",id,companyId,code,name,unit,unitPrice,tax);
String lang = null;
Company company;
if (tuple == null){
LOG.log(DEBUG, " loading company {0}:",companyId);
company = companyService().get(companyId);
LOG.log(DEBUG, " → {0}",company.name());
for (var member : companyService().getMembers(companyId)){
lang = member.language();
if (lang != null){
LOG.log(DEBUG, " → language = {0}",lang);
tuple = Tuple.of(company,lang);
companyInfo.put(companyId,tuple);
break;
@@ -59,12 +67,15 @@ public class ItemDb {
} else {
company = tuple.a;
lang = tuple.b;
LOG.log(DEBUG, " using company: {0} ({1})",company.name(),lang);
}
var location = companyLocations.get(companyId);
if (location == null) {
location = stockDb.save(new DbLocation(0,company,null,"virtual items",null));
companyLocations.put(companyId,location);
}
LOG.log(DEBUG, " using location: {0}",location.resolve().name());
var stockItem = new Item(0,company,0,location,code,name,description);
var props = stockItem.properties();
var keyUnitPrice = translator().translate(lang,UNIT_PRICE);
@@ -75,12 +86,12 @@ public class ItemDb {
props.add(new Property(0,keyUnit,unit,null));
props.add(new Property(0,keyTax,tax,"%"));
props.add(new Property(0,keyLegacyId,id,null));
LOG.log(DEBUG," saving item {0}:",stockItem);
stockDb.save(stockItem);
}
rs.close();
} catch (SQLException e) {
throw databaseException("Failed to migrate items from itemDB to stockDB!");
}
LOG.log(System.Logger.Level.WARNING,"migrateTo({0}) not implemented", stockDb);
}
}