- the connection timeout of about 30 seconds has been managed with a GenericJDBCException.

- exceptions managed in a different way in method executeQuery of Class ConnectionManager

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-access/DatabasesResourcesManager@98992 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-07-25 13:49:09 +00:00
parent 5f795e85d0
commit 6769c97a2d
2 changed files with 54 additions and 18 deletions

View File

@ -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());
}

View File

@ -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")) {