elimintati thread
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good

This commit is contained in:
2025-10-10 09:57:13 +02:00
parent d43345c5fc
commit 4120f20c5a

View File

@@ -303,7 +303,7 @@ public class GiacenzaService {
}
});
saveEntity(carelliGiacenzaProgs);
saveEntity(carelliGiacenzaProgs, false);
//List<EntityBase> entityRet = entityProcessor.processEntityList(carelliGiacenzaProgs, false, true, false);
//UtilityEntity.throwEntitiesException(entityRet);
@@ -424,7 +424,7 @@ public class GiacenzaService {
entityBases.addAll(giacDaInv);
}
saveEntity(entityBases);
saveEntity(entityBases, false);
}
@@ -469,7 +469,7 @@ public class GiacenzaService {
}
carelliGiacenzaProgs.add(c);
}
saveEntity(carelliGiacenzaProgs);
saveEntity(carelliGiacenzaProgs, false);
sql =
Query.format(
@@ -496,32 +496,40 @@ public class GiacenzaService {
}
}
private void saveEntity(List<? extends EntityBase> entityBases) throws SQLException, IOException {
private void saveEntity(List<? extends EntityBase> entityBases, boolean useThread) throws SQLException, IOException {
if (entityBases.isEmpty()) return;
try {
AtomicInteger counter = new AtomicInteger();
List<? extends List<? extends EntityBase>> list = Stream.of(entityBases).chunkBy(x -> counter.getAndIncrement() / 50).toList();
if (useThread) {
AtomicInteger counter = new AtomicInteger();
List<? extends List<? extends EntityBase>> list = Stream.of(entityBases).chunkBy(x -> counter.getAndIncrement() / 50).toList();
List<RunnableThrowable> calls = new ArrayList<>();
for (List<? extends EntityBase> entityList : list) {
calls.add(() -> {
try {
for (EntityBase entityBase : entityList) {
entityProcessor.processEntity(entityBase, false, true, "", multiDBTransactionManager, RequestDataDTO.systemMockupData(), false, false);
List<RunnableThrowable> calls = new ArrayList<>();
for (List<? extends EntityBase> entityList : list) {
calls.add(() -> {
try {
for (EntityBase entityBase : entityList) {
entityProcessor.processEntity(entityBase, false, true, "", multiDBTransactionManager, RequestDataDTO.systemMockupData(), false, false);
}
} catch (Exception ex) {
logger.error(GiacenzaService.class + " " + ex.getMessage(), ex);
}
});
}
} catch (Exception ex) {
logger.error(GiacenzaService.class + " " + ex.getMessage(), ex);
}
});
UtilityThread.executeParallel(calls);
} else {
for (EntityBase entityBase : entityBases) {
entityProcessor.processEntity(entityBase, false, true, "", multiDBTransactionManager, RequestDataDTO.systemMockupData(), false, false);
}
}
UtilityThread.executeParallel(calls);
multiDBTransactionManager.commitAll();
} catch (Exception e) {
multiDBTransactionManager.rollbackAll();
}
}
public void consolidaGiacenza() throws Exception {
@@ -566,7 +574,7 @@ public class GiacenzaService {
carelliGiacenzaProg.setOperation(OperationType.UPDATE);
}
saveEntity(carelliGiacenzaProgs);
saveEntity(carelliGiacenzaProgs, false);
}
}
}
@@ -812,17 +820,17 @@ public class GiacenzaService {
boolean saveBackup = setupGest.getSetupDepoBoolean("DATI_AZIENDA", "GIACENZA_DA_INV", "ATTIVA_LOG", codMdep);
if ( saveBackup &&
listGiacenza.stream().anyMatch(x->x.getQtaInv().compareTo(BigDecimal.ZERO) < 0)) {
if (saveBackup &&
listGiacenza.stream().anyMatch(x -> x.getQtaInv().compareTo(BigDecimal.ZERO) < 0)) {
List<String> elencoArticoli =
listGiacenza.stream()
.filter(x -> x.getQtaInv().compareTo(BigDecimal.ZERO) < 0).map(GiacenzaDTO::getCodMart).collect(Collectors.toList());
multiDBTransactionManager.prepareStatement(
"INSERT INTO carelli_giacenza_prog_bck " +
"SELECT getDate(), * " +
"FROM carelli_giacenza_prog " +
"WHERE cod_mdep = " + UtilityDB.valueToString(codMdep) + " AND " +
"INSERT INTO carelli_giacenza_prog_bck " +
"SELECT getDate(), * " +
"FROM carelli_giacenza_prog " +
"WHERE cod_mdep = " + UtilityDB.valueToString(codMdep) + " AND " +
"cod_mart in (" + UtilityDB.listValueToString(elencoArticoli) + ")").execute();
}