diff --git a/src/main/java/org/gcube/dataaccess/databases/utils/ConnectionManager.java b/src/main/java/org/gcube/dataaccess/databases/utils/ConnectionManager.java index aaac1e8..9fd14db 100644 --- a/src/main/java/org/gcube/dataaccess/databases/utils/ConnectionManager.java +++ b/src/main/java/org/gcube/dataaccess/databases/utils/ConnectionManager.java @@ -37,23 +37,26 @@ public class ConnectionManager { SessionFactory dbHibConnection = null; try { if ((config != null) && (config.getConfigPath() != null)) { - String defaultDatabaseFile = config.getConfigPath() + AlgorithmConfiguration.defaultConnectionFile; + String defaultDatabaseFile = config.getConfigPath() + + AlgorithmConfiguration.defaultConnectionFile; config.setDatabaseDriver(config.getParam("DatabaseDriver")); config.setDatabaseUserName(config.getParam("DatabaseUserName")); config.setDatabasePassword(config.getParam("DatabasePassword")); config.setDatabaseURL(config.getParam("DatabaseURL")); - dbHibConnection = org.gcube.dataaccess.databases.utils.DatabaseFactory.initDBConnection(defaultDatabaseFile, config); + dbHibConnection = org.gcube.dataaccess.databases.utils.DatabaseFactory + .initDBConnection(defaultDatabaseFile, config); } } catch (Exception e) { - System.out.println("ERROR IN DB INITIALIZATION : " + e.getLocalizedMessage()); + System.out.println("ERROR IN DB INITIALIZATION : " + + e.getLocalizedMessage()); e.printStackTrace(); // AnalysisLogger.getLogger().trace(e); } return dbHibConnection; } - + // create the database's connection without using the configuration file but // using the data input public SessionFactory initDBConnection(AlgorithmConfiguration config) { @@ -125,8 +128,13 @@ public class ConnectionManager { try { ss = DBSessionFactory.getCurrentSession(); - ss.beginTransaction(); + //print check added to measure the timeout +// AnalysisLogger.getLogger().debug( +// "In ConnectionManager-> beginTransaction: "); + ss.beginTransaction(); + + Query qr = null; // statement to check if the query is a "show create table" @@ -211,23 +219,28 @@ public class ConnectionManager { // System.out.println(String.format("Error while executing query: %1$s %2$s", // query, e.getMessage())); - if (e.getClass().toString() - .contains("org.hibernate.MappingException")) { + if (e instanceof org.hibernate.MappingException) { // e.printStackTrace(); // System.out.println(e.getClass().toString()); - AnalysisLogger - .getLogger() - .debug("In ConnectionManager-> ERROR The query could not be executed: Error in retrieving a user defined type. Try to use a store procedure to convert the type"); - - throw new Exception( - "The query could not be executed: Error in retrieving a user defined type. Try to use a store procedure to convert the type"); +// AnalysisLogger +// .getLogger() +// .debug("In ConnectionManager-> ERROR The query could not be executed: Error in retrieving a user defined type. Try to use a store procedure to convert the type"); +// +// throw new Exception( +// "The query could not be executed: Error in retrieving a user defined type. Try to use a store procedure to convert the type"); + + AnalysisLogger.getLogger().debug( + "In ConnectionManager-> " + + e.getLocalizedMessage()); + + throw new Exception(e.getLocalizedMessage()); + } - if (e.getClass().toString() - .contains("org.hibernate.exception.SQLGrammarException")) { + if (e instanceof org.hibernate.exception.SQLGrammarException) { // System.out.println(e.getCause().getMessage()); @@ -236,10 +249,33 @@ public class ConnectionManager { // throw new // Exception("The query could not be executed: SQL grammar error in the query"); +// AnalysisLogger.getLogger().debug( +// "In ConnectionManager-> " +// + e.getCause().getLocalizedMessage()); +// +// throw new Exception(e.getCause().getMessage()); + AnalysisLogger.getLogger().debug( "In ConnectionManager-> " - + e.getCause().getLocalizedMessage()); - throw new Exception(e.getCause().getMessage()); + + e.getLocalizedMessage()); + + throw new Exception(e.getLocalizedMessage()); + + } + + if (e instanceof org.hibernate.exception.GenericJDBCException) { + +// AnalysisLogger.getLogger().debug( +// "In ConnectionManager-> " +// + e.getCause().toString()); + +// e.printStackTrace(); + + AnalysisLogger.getLogger().debug( + "In ConnectionManager-> " + + e.getLocalizedMessage()); + + throw new Exception(e.getLocalizedMessage()); } diff --git a/src/main/java/org/gcube/dataaccess/databases/utils/DatabaseFactory.java b/src/main/java/org/gcube/dataaccess/databases/utils/DatabaseFactory.java index 14b422a..df346ae 100644 --- a/src/main/java/org/gcube/dataaccess/databases/utils/DatabaseFactory.java +++ b/src/main/java/org/gcube/dataaccess/databases/utils/DatabaseFactory.java @@ -137,7 +137,7 @@ public class DatabaseFactory { */ if (element.equals("c3p0.checkoutTimeout")) { - currentnode.setText("" + (20000/4)); //added a timeout about 25-30 seconds + currentnode.setText("" + (20000)); //added a timeout about 30 seconds } // if (element.equals("c3p0.acquireRetryAttempts")) {