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

@@ -41,7 +41,7 @@ subprojects {
testImplementation(platform("org.junit:junit-bom:5.10.0")) testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter") testImplementation("org.junit.jupiter:junit-jupiter")
implementation("de.srsoftware:configuration.api:1.0.2") implementation("de.srsoftware:configuration.api:1.0.2")
implementation("de.srsoftware:tools.jdbc:2.0.4") implementation("de.srsoftware:tools.jdbc:2.0.7")
implementation("de.srsoftware:tools.http:6.0.5") implementation("de.srsoftware:tools.http:6.0.5")
implementation("de.srsoftware:tools.mime:1.1.3") implementation("de.srsoftware:tools.mime:1.1.3")
implementation("de.srsoftware:tools.logging:1.3.2") implementation("de.srsoftware:tools.logging:1.3.2")

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