Merge remote-tracking branch 'origin/develop' into develop
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -77,9 +77,12 @@ public class EmsCoreContext implements ApplicationListener<ContextRefreshedEvent
|
||||
logger.debug("Init");
|
||||
|
||||
try {
|
||||
|
||||
new Thread(() -> {
|
||||
emsCoreDBLoader.load(this::onPostDBLoaded);
|
||||
try {
|
||||
emsCoreDBLoader.load(this::onPostDBLoaded);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).start();
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.settings.SettingsController;
|
||||
import it.integry.ems.sync.MultiDBTransaction.AdvancedDataSource;
|
||||
import it.integry.ems.sync.MultiDBTransaction.BasicConnectionPool;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.user.service.UserCacheService;
|
||||
@@ -43,15 +44,23 @@ public class EmsCoreDBLoader {
|
||||
@Autowired
|
||||
private UserCacheService userCacheService;
|
||||
|
||||
@Autowired
|
||||
private BasicConnectionPool connectionPool;
|
||||
|
||||
@PostContextConstruct(priority = 10)
|
||||
public void init() {
|
||||
public void init() throws Exception {
|
||||
this.settingsController.addOnConfigUpdated(() -> {
|
||||
load(null);
|
||||
try {
|
||||
load(null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void load(final RunnableArgs<MultiDBTransactionManager> onComplete) {
|
||||
multiDBTransactionManager = new MultiDBTransactionManager();
|
||||
public void load(final RunnableArgs<MultiDBTransactionManager> onComplete) throws Exception {
|
||||
connectionPool.init();
|
||||
multiDBTransactionManager = new MultiDBTransactionManager(connectionPool);
|
||||
|
||||
try {
|
||||
discoverAllConnections();
|
||||
@@ -92,19 +101,15 @@ public class EmsCoreDBLoader {
|
||||
for (AvailableConnectionsModel model : settingsModel.getAvailableConnections()) {
|
||||
if (!model.getInternalDb())
|
||||
continue;
|
||||
|
||||
try {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(model.getProfileName());
|
||||
final DataSource ds = connectionPool.getConnection(model.getProfileName());
|
||||
|
||||
String dbDistributore = null;
|
||||
|
||||
boolean isInternalDb = model.getInternalDb();
|
||||
if (isInternalDb) {
|
||||
String sql = "SELECT db_distributore FROM azienda";
|
||||
dbDistributore = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(ds.getConnection(), sql);
|
||||
}
|
||||
String sql = "SELECT db_distributore FROM azienda";
|
||||
String dbDistributore = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(ds.getConnection(), sql);
|
||||
|
||||
multiDBTransactionManager.addConnection(model.getProfileName(), ds, model.getDbName().equalsIgnoreCase(dbDistributore));
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error(String.format("La connessione al DB \"%s\" non è valida. %s", model.getProfileName(), ex.getMessage()), ex);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class DataSource {
|
||||
private String profile;
|
||||
private Short sessionID;
|
||||
private Connection connection = null;
|
||||
private String applicationName;
|
||||
|
||||
public String getDbName() {
|
||||
return connectionModel.getDbName();
|
||||
@@ -41,13 +42,15 @@ public class DataSource {
|
||||
return connectionModel.getConnectionType();
|
||||
}
|
||||
|
||||
public String getApplicationName() {
|
||||
return applicationName;
|
||||
}
|
||||
|
||||
public int getSessionID() {
|
||||
return sessionID;
|
||||
}
|
||||
|
||||
public synchronized Connection getConnection() throws IOException, SQLException {
|
||||
if (connection == null || connection.isClosed())
|
||||
init();
|
||||
return connection;
|
||||
}
|
||||
|
||||
@@ -55,10 +58,11 @@ public class DataSource {
|
||||
return !(connection != null && !connection.isClosed());
|
||||
}
|
||||
|
||||
private void init() throws SQLException, IOException {
|
||||
private void init(String applicationName) throws SQLException, IOException {
|
||||
this.applicationName = applicationName;
|
||||
|
||||
connection = Connection.fromConnection(
|
||||
DriverManager.getConnection(connectionModel.getDbConnectionString(), connectionModel.getUsername(), connectionModel.getPasswordDecrypted())
|
||||
DriverManager.getConnection(connectionModel.getDbConnectionString(applicationName), connectionModel.getUsername(), connectionModel.getPasswordDecrypted())
|
||||
);
|
||||
connection.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_UNCOMMITTED);
|
||||
connection.setAutoCommit(false);
|
||||
@@ -112,7 +116,7 @@ public class DataSource {
|
||||
this.connectionModel = connectionModel;
|
||||
|
||||
if (autoOpenConnection) {
|
||||
init();
|
||||
init(connectionName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250109154212 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
dropColumn("gtb_porto", "flag_fattura_vettore");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package it.integry.ems.migration.model;
|
||||
|
||||
import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20250109161329 extends BaseMigration implements MigrationModelInterface {
|
||||
|
||||
@Override
|
||||
public void up() throws Exception {
|
||||
if (isHistoryDB())
|
||||
return;
|
||||
|
||||
executeStatement("ALTER TABLE azienda ADD cod_lucid VARCHAR(20)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class AvailableConnectionsModel {
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getDbConnectionString() throws IOException {
|
||||
public String getDbConnectionString(String applicationName) throws IOException {
|
||||
|
||||
if (UtilityString.isNullOrEmpty(host)) {
|
||||
throw new IOException(String.format("HOST di connessione al database non configurato correttamente (%s)", profileName));
|
||||
@@ -135,7 +135,7 @@ public class AvailableConnectionsModel {
|
||||
return String.format("jdbc:mysql://%s:3306/%s", host, dbName);
|
||||
|
||||
case MSSQL:
|
||||
return String.format("jdbc:sqlserver://%s;databaseName=%s;applicationName=%s", host, dbName, "EMS Connection");
|
||||
return String.format("jdbc:sqlserver://%s;databaseName=%s;applicationName=%s", host, dbName, applicationName);
|
||||
|
||||
case POSTGRES:
|
||||
return String.format("jdbc:postgresql://%s:5432/%s", host, dbName);
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package it.integry.ems.sync.MultiDBTransaction;
|
||||
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class BasicConnectionPool {
|
||||
|
||||
@Autowired
|
||||
private SettingsModel settingsModel;
|
||||
|
||||
private final HashMap<String, List<DataSource>> connectionPool = new HashMap<>();
|
||||
private final HashMap<String, List<DataSource>> usedConnections = new HashMap<>();
|
||||
|
||||
public synchronized void init() throws Exception {
|
||||
|
||||
int poolSize =
|
||||
UtilityDebug.isIntegryServerMaster() ? 1 :
|
||||
UtilityDebug.isIntegryServerDev() ? 2 :
|
||||
UtilityDebug.isDebugExecution() ? 0 :
|
||||
Runtime.getRuntime().availableProcessors();
|
||||
|
||||
poolSize = Math.min(poolSize, 8);
|
||||
|
||||
final List<AvailableConnectionsModel> availableConnections = settingsModel.getAvailableConnections(true);
|
||||
|
||||
for (final AvailableConnectionsModel availableConnectionsModel : availableConnections) {
|
||||
synchronized (connectionPool) {
|
||||
if (!connectionPool.containsKey(availableConnectionsModel.getProfileName()))
|
||||
connectionPool.put(availableConnectionsModel.getProfileName(), new ArrayList<>());
|
||||
|
||||
if (!usedConnections.containsKey(availableConnectionsModel.getProfileName()))
|
||||
usedConnections.put(availableConnectionsModel.getProfileName(), new ArrayList<>());
|
||||
|
||||
int createdConnections = connectionPool.get(availableConnectionsModel.getProfileName()).size() +
|
||||
usedConnections.get(availableConnectionsModel.getProfileName()).size();
|
||||
|
||||
for (int j = 0; j < poolSize - createdConnections; j++) {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(availableConnectionsModel.getProfileName(), "EMS Pool Connection #" + j, true);
|
||||
connectionPool.get(availableConnectionsModel.getProfileName()).add(ds);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public synchronized DataSource getConnection(String profileName) throws Exception {
|
||||
DataSource ds = null;
|
||||
|
||||
synchronized (connectionPool) {
|
||||
if (!connectionPool.containsKey(profileName) || connectionPool.get(profileName).isEmpty()) {
|
||||
ds = createExtraConnection(profileName);
|
||||
} else {
|
||||
ds = connectionPool.get(profileName)
|
||||
.remove(connectionPool.get(profileName).size() - 1);
|
||||
|
||||
if(ds.isClosed()) ds.initialize(profileName, ds.getApplicationName(), true);
|
||||
|
||||
usedConnections.get(profileName).add(ds);
|
||||
}
|
||||
}
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
public synchronized boolean releaseConnection(String profileName, DataSource ds) throws SQLException {
|
||||
if (ds.getApplicationName().equals("EMS Connection")) { //Extra connection
|
||||
ds.forceClose();
|
||||
return true;
|
||||
} else {
|
||||
synchronized (connectionPool) {
|
||||
connectionPool.get(profileName).add(ds);
|
||||
return usedConnections.get(profileName).remove(ds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DataSource createExtraConnection(String profileName) throws Exception {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(profileName, "EMS Connection", true);
|
||||
|
||||
return ds;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package it.integry.ems.sync.MultiDBTransaction;
|
||||
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class DBConnectionChecker {
|
||||
|
||||
private final int DELAY_CHECK = 5 * 1000;
|
||||
private final String applicationName = "EMS CHK_CONN";
|
||||
private Logger logger = LogManager.getLogger();
|
||||
private MultiDBTransactionManager mMultiDBTransactionManager;
|
||||
|
||||
private String mCheckSql = null;
|
||||
|
||||
private int mConnectionNumber = -1;
|
||||
|
||||
public void init(String profileDB) throws Exception {
|
||||
|
||||
mMultiDBTransactionManager = new MultiDBTransactionManager();
|
||||
mMultiDBTransactionManager.setPrimaryDs(profileDB, applicationName);
|
||||
|
||||
mCheckSql = "SELECT (COUNT(dbid) - 1) as NumberOfConnections "
|
||||
+ "FROM sys.sysprocesses WHERE dbid > 0 and DB_NAME(dbid) = " + UtilityDB.valueToString(mMultiDBTransactionManager.getPrimaryDatasource().getProfile())
|
||||
+ " and program_name <> " + UtilityDB.valueToString(applicationName);
|
||||
|
||||
}
|
||||
|
||||
public void startChecking() throws Exception {
|
||||
|
||||
if (mMultiDBTransactionManager != null) {
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
do {
|
||||
try {
|
||||
checkNow();
|
||||
Thread.sleep(DELAY_CHECK);
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("DBConnectionChecker", e);
|
||||
mConnectionNumber = -1;
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
}
|
||||
}).start();
|
||||
|
||||
} else throw new Exception("Prima di avviare il monitoring è necessario inizializzare il DBConnectionChecker");
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void checkNow() {
|
||||
try {
|
||||
mConnectionNumber = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(mMultiDBTransactionManager.getPrimaryConnection(), mCheckSql);
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getCurrentNumberOfConnections() {
|
||||
return mConnectionNumber;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -8,12 +8,12 @@ import it.integry.ems.javabeans.RequestDataDTO;
|
||||
import it.integry.ems.properties.EmsProperties;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
@@ -33,6 +33,9 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
private List<AdvancedDataSource> dbDatasources = new ArrayList<>();
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
private BasicConnectionPool connectionPool;
|
||||
|
||||
@Autowired
|
||||
private SettingsModel settingsModel;
|
||||
|
||||
@@ -43,6 +46,11 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
private boolean enableLog = true;
|
||||
|
||||
public MultiDBTransactionManager() {
|
||||
connectionPool = ContextLoader.getCurrentWebApplicationContext().getBean(BasicConnectionPool.class);
|
||||
}
|
||||
|
||||
public MultiDBTransactionManager(BasicConnectionPool connectionPool) throws Exception {
|
||||
this.connectionPool = connectionPool;
|
||||
}
|
||||
|
||||
public MultiDBTransactionManager(AvailableConnectionsModel connectionsModel) throws Exception {
|
||||
@@ -54,6 +62,7 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
}
|
||||
|
||||
public MultiDBTransactionManager(String profileDb, boolean enableLog) throws Exception {
|
||||
this();
|
||||
this.enableLog = enableLog;
|
||||
this.setPrimaryDs(profileDb);
|
||||
}
|
||||
@@ -78,7 +87,7 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
public void Destroy() throws Exception {
|
||||
this.commitAll();
|
||||
this.closeAll();
|
||||
this.dbDatasources = null;
|
||||
this.dbDatasources.clear();
|
||||
this.dbPrimary = null;
|
||||
}
|
||||
|
||||
@@ -87,14 +96,12 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
}
|
||||
|
||||
public void addConnection(String profileName) throws Exception {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(profileName);
|
||||
|
||||
this.addConnection(profileName, ds);
|
||||
this.addConnection(profileName, false);
|
||||
}
|
||||
|
||||
public void addConnection(String profileName, DataSource dataSource) {
|
||||
this.addConnection(profileName, dataSource, false);
|
||||
public void addConnection(String profileName, boolean isDistributore) throws Exception {
|
||||
DataSource ds = connectionPool.getConnection(profileName);
|
||||
this.addConnection(profileName, ds, isDistributore);
|
||||
}
|
||||
|
||||
public void addConnection(String profileName, DataSource dataSource, boolean isDistributore) {
|
||||
@@ -208,14 +215,6 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
return connection.prepareStatement(sql);
|
||||
}
|
||||
|
||||
/*public AdvancedDataSource getPrimaryDatasource()throws Exception {
|
||||
if(dbDatasources != null){
|
||||
return dbDatasources.get(PRIMARY_DB_KEY);
|
||||
} else {
|
||||
throw new Exception("Database not present in connections list");
|
||||
}
|
||||
}*/
|
||||
|
||||
public ArrayList<AdvancedDataSource> getActiveConnections() throws SQLException {
|
||||
ArrayList<AdvancedDataSource> activeConnections = new ArrayList<AdvancedDataSource>();
|
||||
|
||||
@@ -258,8 +257,10 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
logger.debug("Closing manually: " + advancedDataSource.getDataSource().getProfile() + " (#" + advancedDataSource.getDataSource().getSessionID() + ")");
|
||||
}
|
||||
advancedDataSource.commit();
|
||||
advancedDataSource.close();
|
||||
|
||||
}
|
||||
|
||||
connectionPool.releaseConnection(advancedDataSource.getProfileName(), advancedDataSource.getDataSource());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,19 +295,8 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
* @throws Exception
|
||||
*/
|
||||
|
||||
public void setPrimaryDs(String profileDb, String applicationName) throws Exception {
|
||||
if (dataSource == null) {
|
||||
dataSource = new DataSource();
|
||||
} else {
|
||||
dataSource.forceClose();
|
||||
}
|
||||
|
||||
if (UtilityString.isNullOrEmpty(applicationName)) {
|
||||
dataSource.initialize(profileDb);
|
||||
} else {
|
||||
dataSource.initialize(profileDb, applicationName, true);
|
||||
}
|
||||
|
||||
public void setPrimaryDs(String profileDb) throws Exception {
|
||||
dataSource = connectionPool.getConnection(profileDb);
|
||||
|
||||
java.util.Optional<AvailableConnectionsModel> availableConnectionsModel = SettingsModel.getInstance().getAvailableConnections().stream()
|
||||
.filter(x -> x.getProfileName().equalsIgnoreCase(profileDb))
|
||||
@@ -321,11 +311,7 @@ public class MultiDBTransactionManager implements AutoCloseable {
|
||||
this.dbPrimary = new AdvancedDataSource(dataSource.getProfile().toUpperCase(), dataSource, false, isInternalDb);
|
||||
|
||||
this.dbDatasources = new ArrayList<>();
|
||||
this.addConnection(dataSource.getProfile().toUpperCase(), dataSource);
|
||||
}
|
||||
|
||||
public void setPrimaryDs(String profileDb) throws Exception {
|
||||
this.setPrimaryDs(profileDb, null);
|
||||
this.addConnection(dataSource.getProfile().toUpperCase(), dataSource, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import it.integry.ems.json.ResponseJSONObjectMapper;
|
||||
import it.integry.ems.service.MailService;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EntityInterface;
|
||||
@@ -25,9 +26,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -190,9 +188,7 @@ public class SyncManager {
|
||||
}
|
||||
|
||||
if (!multiDBTransactionManager.containsDB(database)) {
|
||||
DataSource dsSync = new DataSource();
|
||||
dsSync.initialize(database);
|
||||
multiDBTransactionManager.addConnection(database, dsSync);
|
||||
multiDBTransactionManager.addConnection(database);
|
||||
}
|
||||
|
||||
Connection syncConnection = multiDBTransactionManager.getDatabaseDataSource(database).getConnection();
|
||||
|
||||
@@ -3,12 +3,12 @@ package it.integry.ems.user.service;
|
||||
import com.annimon.stream.Optional;
|
||||
import com.annimon.stream.Stream;
|
||||
import it.integry.annotations.PostContextConstruct;
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.expansion.RunnableThrowable;
|
||||
import it.integry.ems.looper.service.LooperService;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import it.integry.ems.sync.MultiDBTransaction.AdvancedDataSource;
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||
import it.integry.ems.user.dto.UserDTO;
|
||||
import it.integry.ems.utility.UtilityDebug;
|
||||
@@ -20,8 +20,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import it.integry.ems.sync.MultiDBTransaction.Connection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -57,11 +55,9 @@ public class UserCacheService {
|
||||
|
||||
try {
|
||||
for (AvailableConnectionsModel model : availableConnectionsModels) {
|
||||
DataSource ds = new DataSource();
|
||||
|
||||
try {
|
||||
ds.initialize(model.getProfileName());
|
||||
multiDBTransactionManager.addConnection(model.getProfileName(), ds);
|
||||
multiDBTransactionManager.addConnection(model.getProfileName());
|
||||
} catch (Exception ex) {
|
||||
logger.info(String.format("Cannot find %s database", model.getDbName()), ex);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package it.integry.ems.utility;
|
||||
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
import org.springframework.web.context.ContextLoader;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class UtilityDebug {
|
||||
@@ -10,7 +7,6 @@ public class UtilityDebug {
|
||||
private static final String INTEGRY_DOMAIN = "STUDIO-ML";
|
||||
|
||||
public static boolean isDebugExecution() {
|
||||
|
||||
//Controllo il dominio del PC attuale
|
||||
String domainName = System.getenv("USERDOMAIN");
|
||||
return INTEGRY_DOMAIN.equalsIgnoreCase(domainName);
|
||||
@@ -18,16 +14,17 @@ public class UtilityDebug {
|
||||
|
||||
|
||||
public static boolean isIntegryServer() {
|
||||
SettingsModel settingsModel = ContextLoader.getCurrentWebApplicationContext().getBean(SettingsModel.class);
|
||||
return isIntegryServerDev() || isIntegryServerMaster();
|
||||
}
|
||||
|
||||
return settingsModel.getDefaultProfile().equalsIgnoreCase("INTEGRY") ||
|
||||
settingsModel.getDefaultProfile().equalsIgnoreCase("STUDIO-ML");
|
||||
public static boolean isIntegryServerMaster() {
|
||||
String computerName = getComputerName();
|
||||
return computerName.equalsIgnoreCase("SERVERTOMCAT");
|
||||
}
|
||||
|
||||
public static boolean isIntegryServerDev() {
|
||||
String computerName = getComputerName();
|
||||
|
||||
return computerName.equalsIgnoreCase("SERVERDEV");
|
||||
return isDebugExecution() && computerName.equalsIgnoreCase("SERVERDEV");
|
||||
}
|
||||
|
||||
private static String getComputerName() {
|
||||
|
||||
@@ -44,9 +44,6 @@ public class GtbPorto extends EntityBase {
|
||||
@SqlField(value = "flag_attivo", nullable = false)
|
||||
private Boolean flagAttivo;
|
||||
|
||||
@SqlField(value = "flag_fattura_vettore", nullable = false)
|
||||
private Boolean flagFatturaVettore;
|
||||
|
||||
@SqlField(value = "flag_incoterms", nullable = false)
|
||||
private Boolean flagIncoterms;
|
||||
|
||||
@@ -114,15 +111,6 @@ public class GtbPorto extends EntityBase {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getFlagFatturaVettore() {
|
||||
return flagFatturaVettore;
|
||||
}
|
||||
|
||||
public GtbPorto setFlagFatturaVettore(Boolean flagFatturaVettore) {
|
||||
this.flagFatturaVettore = flagFatturaVettore;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Boolean getFlagIncoterms() {
|
||||
return flagIncoterms;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityString;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class DocumentExtEntityRules {
|
||||
|
||||
@@ -25,17 +26,34 @@ public class DocumentExtEntityRules {
|
||||
|
||||
if ( mtbColts != null && mtbColts.size() > 0) {
|
||||
for (MtbColt mtbColt : mtbColts) {
|
||||
|
||||
mtbColt.setCodDtip(EmsRestConstants.NULL)
|
||||
.setCodAnag(EmsRestConstants.NULL)
|
||||
.setDataDoc(EmsRestConstants.DATE_NULL)
|
||||
.setSerDoc(EmsRestConstants.NULL)
|
||||
.setNumDoc(EmsRestConstants.INTEGER_NULL)
|
||||
.setCodAnag(mtbColt.getFlagColloAnonimo().equalsIgnoreCase("S")?EmsRestConstants.NULL:mtbColt.getCodAnag())
|
||||
.setCodVdes(mtbColt.getFlagColloAnonimo().equalsIgnoreCase("S")?EmsRestConstants.NULL:mtbColt.getCodVdes());
|
||||
mtbColt.setOperation(OperationType.UPDATE);
|
||||
Optional<MtbColt> first = entity.getMtbColt()
|
||||
.stream()
|
||||
.filter(colt -> colt.getGestione().equalsIgnoreCase(mtbColt.getGestione()) &&
|
||||
colt.getDataCollo().equals(mtbColt.getDataCollo()) &&
|
||||
colt.getSerCollo().equalsIgnoreCase(mtbColt.getSerCollo()) &&
|
||||
colt.getNumCollo().equals(mtbColt.getNumCollo()))
|
||||
.findFirst();
|
||||
if (first.isPresent()) {
|
||||
first.get().setCodDtip(EmsRestConstants.NULL)
|
||||
.setCodAnag(EmsRestConstants.NULL)
|
||||
.setDataDoc(EmsRestConstants.DATE_NULL)
|
||||
.setSerDoc(EmsRestConstants.NULL)
|
||||
.setNumDoc(EmsRestConstants.INTEGER_NULL)
|
||||
.setCodAnag(mtbColt.getFlagColloAnonimo().equalsIgnoreCase("S")?EmsRestConstants.NULL:mtbColt.getCodAnag())
|
||||
.setCodVdes(mtbColt.getFlagColloAnonimo().equalsIgnoreCase("S")?EmsRestConstants.NULL:mtbColt.getCodVdes());
|
||||
first.get().setOperation(OperationType.UPDATE);
|
||||
} else {
|
||||
mtbColt.setCodDtip(EmsRestConstants.NULL)
|
||||
.setCodAnag(EmsRestConstants.NULL)
|
||||
.setDataDoc(EmsRestConstants.DATE_NULL)
|
||||
.setSerDoc(EmsRestConstants.NULL)
|
||||
.setNumDoc(EmsRestConstants.INTEGER_NULL)
|
||||
.setCodAnag(mtbColt.getFlagColloAnonimo().equalsIgnoreCase("S")?EmsRestConstants.NULL:mtbColt.getCodAnag())
|
||||
.setCodVdes(mtbColt.getFlagColloAnonimo().equalsIgnoreCase("S")?EmsRestConstants.NULL:mtbColt.getCodVdes());
|
||||
mtbColt.setOperation(OperationType.UPDATE);
|
||||
entity.getMtbColt().add(mtbColt);
|
||||
}
|
||||
}
|
||||
entity.getMtbColt().addAll(mtbColts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,11 +84,6 @@ public class SetupGest {
|
||||
}
|
||||
|
||||
private String getSetup(Connection connection, String gestName, String section, String keySection, String precode) throws SQLException {
|
||||
|
||||
PreparedStatement info;
|
||||
ResultSet res;
|
||||
String value = null;
|
||||
|
||||
if (!precode.isEmpty()) {
|
||||
gestName = precode + "_" + gestName;
|
||||
}
|
||||
@@ -97,15 +92,9 @@ public class SetupGest {
|
||||
+ " AND section = " + UtilityDB.valueToString(section)
|
||||
+ " AND key_section = " + UtilityDB.valueToString(keySection);
|
||||
|
||||
info = connection.prepareStatement(query);
|
||||
res = info.executeQuery();
|
||||
while (res.next()) {
|
||||
value = res.getString(1) == null ? "" : res.getString(1);
|
||||
}
|
||||
res.close();
|
||||
info.close();
|
||||
String value = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(connection, query);
|
||||
|
||||
return value;
|
||||
return UtilityString.isNull(value, "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package it.integry.security.cache;
|
||||
|
||||
import it.integry.annotations.PostContextConstruct;
|
||||
import it.integry.ems.datasource.DataSource;
|
||||
import it.integry.ems.looper.service.LooperService;
|
||||
import it.integry.ems.settings.Model.AvailableConnectionsModel;
|
||||
import it.integry.ems.settings.Model.SettingsModel;
|
||||
@@ -114,11 +113,8 @@ public class JwtTokenCacheComponent implements ApplicationListener {
|
||||
continue;
|
||||
|
||||
try {
|
||||
DataSource ds = new DataSource();
|
||||
ds.initialize(availableConnectionsModel.getProfileName());
|
||||
|
||||
multiDBTransactionManager.addConnection(
|
||||
availableConnectionsModel.getProfileName(), ds);
|
||||
availableConnectionsModel.getProfileName());
|
||||
} catch (Exception ex) {
|
||||
logger.error("Database connection error", ex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user