- exception management for SQLGrammarException adding a cause message

- method removeQueryExecution implemented and commented in class ConnectionManager

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-access/DatabasesResourcesManager@99191 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-08-01 15:21:17 +00:00
parent f790f715b7
commit a2ea87687d
1 changed files with 61 additions and 37 deletions

View File

@ -51,7 +51,7 @@ public class ConnectionManager {
} catch (Exception e) { } catch (Exception e) {
System.out.println("ERROR IN DB INITIALIZATION : " System.out.println("ERROR IN DB INITIALIZATION : "
+ e.getLocalizedMessage()); + e.getLocalizedMessage());
e.printStackTrace(); // e.printStackTrace();
// AnalysisLogger.getLogger().trace(e); // AnalysisLogger.getLogger().trace(e);
} }
return dbHibConnection; return dbHibConnection;
@ -128,13 +128,12 @@ public class ConnectionManager {
try { try {
ss = DBSessionFactory.getCurrentSession(); ss = DBSessionFactory.getCurrentSession();
//print check added to measure the timeout // print check added to measure the timeout
// AnalysisLogger.getLogger().debug( // AnalysisLogger.getLogger().debug(
// "In ConnectionManager-> beginTransaction: "); // "In ConnectionManager-> beginTransaction: ");
ss.beginTransaction(); ss.beginTransaction();
Query qr = null; Query qr = null;
// statement to check if the query is a "show create table" // statement to check if the query is a "show create table"
@ -176,6 +175,7 @@ public class ConnectionManager {
"In ConnectionManager-> executing query: " + query); "In ConnectionManager-> executing query: " + query);
qr = ss.createSQLQuery(query); qr = ss.createSQLQuery(query);
qr.setResultTransformer(AliasToEntityOrderedMapResultTransformer.INSTANCE); qr.setResultTransformer(AliasToEntityOrderedMapResultTransformer.INSTANCE);
@ -225,23 +225,28 @@ public class ConnectionManager {
// System.out.println(e.getClass().toString()); // System.out.println(e.getClass().toString());
// AnalysisLogger // AnalysisLogger
// .getLogger() // .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"); // .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( // 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"); // "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( AnalysisLogger.getLogger().debug(
"In ConnectionManager-> " "In ConnectionManager-> " + e.getLocalizedMessage());
+ e.getLocalizedMessage());
throw new Exception(e.getLocalizedMessage()); throw new Exception(e.getLocalizedMessage());
} }
if (e instanceof org.hibernate.exception.SQLGrammarException) { if (e instanceof org.hibernate.exception.SQLGrammarException) {
String cause = "";
if (e.getCause() != null) {
cause = e.getCause().getLocalizedMessage();
// System.out.println(e.getCause().getLocalizedMessage());
}
// System.out.println(e.getCause().getMessage()); // System.out.println(e.getCause().getMessage());
// AnalysisLogger.getLogger().debug("In ConnectionManager-> ERROR The query could not be executed: SQL grammar error in the query"); // AnalysisLogger.getLogger().debug("In ConnectionManager-> ERROR The query could not be executed: SQL grammar error in the query");
@ -249,32 +254,31 @@ public class ConnectionManager {
// throw new // throw new
// Exception("The query could not be executed: SQL grammar error in the query"); // Exception("The query could not be executed: SQL grammar error in the query");
// AnalysisLogger.getLogger().debug( // AnalysisLogger.getLogger().debug(
// "In ConnectionManager-> " // "In ConnectionManager-> "
// + e.getCause().getLocalizedMessage()); // + e.getCause().getLocalizedMessage());
// //
// throw new Exception(e.getCause().getMessage()); // throw new Exception(e.getCause().getMessage());
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
"In ConnectionManager-> " "In ConnectionManager-> " + e.getLocalizedMessage()
+ e.getLocalizedMessage()); + "." + cause);
throw new Exception(e.getLocalizedMessage()); throw new Exception(e.getLocalizedMessage() + "." + cause);
} }
if (e instanceof org.hibernate.exception.GenericJDBCException) { if (e instanceof org.hibernate.exception.GenericJDBCException) {
// AnalysisLogger.getLogger().debug( // AnalysisLogger.getLogger().debug(
// "In ConnectionManager-> " // "In ConnectionManager-> "
// + e.getCause().toString()); // + e.getCause().toString());
// e.printStackTrace(); // e.printStackTrace();
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
"In ConnectionManager-> " "In ConnectionManager-> " + e.getLocalizedMessage());
+ e.getLocalizedMessage());
throw new Exception(e.getLocalizedMessage()); throw new Exception(e.getLocalizedMessage());
} }
@ -291,6 +295,26 @@ public class ConnectionManager {
return obj; return obj;
} }
// //to cancel the execution of the current query
// public void removeQueryExecution(SessionFactory DBSessionFactory) throws Exception{
//
// try{
//
// Session ss = DBSessionFactory.getCurrentSession();
//
// ss.beginTransaction();
//
// ss.cancelQuery();
//
// ss.getTransaction().commit();
//
// }
// catch (Exception e) {
// throw e;
// }
//
// }
// /** Method that creates the connection */ // /** Method that creates the connection */
// public SessionFactory createConnection(AlgorithmConfiguration config) { // public SessionFactory createConnection(AlgorithmConfiguration config) {