Aggiunta cache su MtbDepo
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good

This commit is contained in:
2025-11-20 11:53:20 +01:00
parent 562116cb54
commit b88f0a3c7d
5 changed files with 53 additions and 38 deletions

View File

@@ -9,14 +9,12 @@ import it.integry.ems.migration._base.IntegryCustomerDB;
import it.integry.ems.sync.MultiDBTransaction.Connection;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems_model.entity.*;
import it.integry.ems_model.exception.DataConverterNotFoundException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@@ -32,6 +30,7 @@ public class DbmsChangeTrackerComponent {
add(MtbAart.ENTITY);
add(MtbAartBarCode.ENTITY);
add(MtbUntMis.ENTITY);
add(MtbDepo.ENTITY);
add(StbEditLimit.ENTITY);
add(StbGestSetup.ENTITY);
add(StbGestSetupDepo.ENTITY);
@@ -60,37 +59,42 @@ public class DbmsChangeTrackerComponent {
}
private void enableAllChangeTracking() throws SQLException, DataConverterNotFoundException, InstantiationException, IllegalAccessException {
private void enableAllChangeTracking() throws Exception {
for (Map.Entry<IntegryCustomerDB, DbmsChangeTracker> entrySet : activeChangeTrackers.entrySet()) {
IntegryCustomerDB customerDB = entrySet.getKey();
DbmsChangeTracker dbmsChangeTracker = entrySet.getValue();
dbmsChangeTracker.enableTrackerInDbms();
try {
for (String tableName : trackedTables) {
dbmsChangeTracker.enableTrackerOnTable(tableName);
dbmsChangeTracker.enableTrackerInDbms();
for (String tableName : trackedTables) {
dbmsChangeTracker.enableTrackerOnTable(tableName);
}
dbmsChangeTracker.disableTrackerOnNotUsedTables(trackedTables);
dbmsChangeTracker.setEventListener(new DbmsChangeTracker.Listener() {
@Override
public void onInsertDetected(String tableName, HashMap<String, Object> primaryKey) {
onItemInserted(customerDB, tableName, primaryKey);
}
@Override
public void onUpdateDetected(String tableName, HashMap<String, Object> primaryKey) {
onItemUpdated(customerDB, tableName, primaryKey);
}
@Override
public void onDeleteDetected(String tableName, HashMap<String, Object> primaryKey) {
onItemDeleted(customerDB, tableName, primaryKey);
}
});
dbmsChangeTracker.startTracking();
} catch (Exception e) {
throw new Exception("Errore durante l'abilitazione del DbmsChangeTracker per il customer: " + customerDB.getValue(), e);
}
dbmsChangeTracker.disableTrackerOnNotUsedTables(trackedTables);
dbmsChangeTracker.setEventListener(new DbmsChangeTracker.Listener() {
@Override
public void onInsertDetected(String tableName, HashMap<String, Object> primaryKey) {
onItemInserted(customerDB, tableName, primaryKey);
}
@Override
public void onUpdateDetected(String tableName, HashMap<String, Object> primaryKey) {
onItemUpdated(customerDB, tableName, primaryKey);
}
@Override
public void onDeleteDetected(String tableName, HashMap<String, Object> primaryKey) {
onItemDeleted(customerDB, tableName, primaryKey);
}
});
dbmsChangeTracker.startTracking();
}
}

View File

@@ -47,6 +47,7 @@ public class EntityCacheComponent implements ApplicationListener {
put(MtbAart.ENTITY, MtbAart.class);
put(MtbAartBarCode.ENTITY, MtbAartBarCode.class);
put(MtbUntMis.ENTITY, MtbUntMis.class);
put(MtbDepo.ENTITY, MtbDepo.class);
put(StbEditLimit.ENTITY, StbEditLimit.class);
put(StbGestSetup.ENTITY, StbGestSetup.class);
put(StbGestSetupDepo.ENTITY, StbGestSetupDepo.class);

View File

@@ -32,7 +32,8 @@ public class UserSession {
try {
currentUser = UtilityUser.getCurrentUser(multiDBTransactionManager, requestDataDTO);
if(currentUser != null) currentUserDepo = UtilityUser.getDefaultUserDepo(multiDBTransactionManager, currentUser);
if (currentUser != null)
currentUserDepo = UtilityUser.getDefaultUserDepo(multiDBTransactionManager.getPrimaryConnection().getIntegryCustomerDB(), currentUser);
} catch (Exception ex) {
//logger.trace(UserSession.class.getName() + ": errore durante l'inizializzazione", ex);
}

View File

@@ -2,8 +2,10 @@ package it.integry.ems.user;
import it.integry.ems._context.ApplicationContextProvider;
import it.integry.ems.dto.EntityPermissionsDTO;
import it.integry.ems.dynamic_cache.EntityCacheComponent;
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
import it.integry.ems.javabeans.RequestDataDTO;
import it.integry.ems.migration._base.IntegryCustomerDB;
import it.integry.ems.service.EntityProcessor;
import it.integry.ems.sync.MultiDBTransaction.Connection;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
@@ -69,23 +71,30 @@ public class UtilityUser {
}
public static MtbDepo getDefaultUserDepo(MultiDBTransactionManager multiDBTransactionManager, UserDTO userDTO) throws SQLException, IOException, PrimaryDatabaseNotPresentException, DataConverterNotFoundException, InstantiationException, IllegalAccessException, InvalidUserException {
public static MtbDepo getDefaultUserDepo(IntegryCustomerDB integryCustomerDB, UserDTO userDTO) throws SQLException, IOException, PrimaryDatabaseNotPresentException, DataConverterNotFoundException, InstantiationException, IllegalAccessException, InvalidUserException {
if (userDTO == null) throw new InvalidUserException();
String sql = "SELECT md.* FROM " + MtbDepo.ENTITY + " md " +
" INNER JOIN " + WtbDepo.ENTITY + " wd " +
" ON md.cod_mdep = wd.cod_mdep" +
" WHERE wd.user_name = " + UtilityDB.valueToString(userDTO.getUsername()) +
" order by wd.default_depo desc";
final EntityCacheComponent entityCacheComponent = ApplicationContextProvider.getApplicationContext().getBean(EntityCacheComponent.class);
List<MtbDepo> depos = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, MtbDepo.class);
MtbDepo defaultDepo = entityCacheComponent.<MtbDepo>getCachedEntitiesStream(integryCustomerDB, MtbDepo.ENTITY,
x -> x.getCodMdep().equalsIgnoreCase(userDTO.getCodMdep()))
.findFirst()
.orElse(null);
if (depos == null || depos.isEmpty()) {
// String sql = "SELECT md.* FROM " + MtbDepo.ENTITY + " md " +
// " INNER JOIN " + WtbDepo.ENTITY + " wd " +
// " ON md.cod_mdep = wd.cod_mdep" +
// " WHERE wd.user_name = " + UtilityDB.valueToString(userDTO.getUsername()) +
// " order by wd.default_depo desc";
// List<MtbDepo> depos = UtilityDB.executeSimpleQueryDTO(multiDBTransactionManager.getPrimaryConnection(), sql, MtbDepo.class);
if (defaultDepo == null) {
logger.trace("Nessun deposito trovato per l'utente " + userDTO.getUsername());
return null;
}
return depos.get(0);
return defaultDepo;
}

View File

@@ -166,7 +166,7 @@ public class RefreshTokenService {
HashMap<String, AuthTokenProfileDetails> profilesData = new HashMap<>();
try {
MtbDepo defaultUserDepo = UtilityUser.getDefaultUserDepo(multiDBTransactionManager, user);
MtbDepo defaultUserDepo = UtilityUser.getDefaultUserDepo(multiDBTransactionManager.getPrimaryConnection().getIntegryCustomerDB(), user);
if (defaultUserDepo != null) {
AuthTokenProfileDetails authTokenProfileDetails = new AuthTokenProfileDetails(AuthTokenDepoDetails.fromMtbDepo(defaultUserDepo));