diff --git a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/GetTableDetails.java b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/GetTableDetails.java index 02ec87f..91eda20 100644 --- a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/GetTableDetails.java +++ b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/GetTableDetails.java @@ -88,7 +88,7 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm { List Info = retrieveInfo(); // create the connection - sf = getConnection(Info); + getConnection(Info); // get table's details @@ -97,9 +97,6 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm { map = getDetails(); - // close the connection - sf.close(); - } catch (HibernateException h) { AnalysisLogger.getLogger().debug( @@ -146,11 +143,8 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm { throw e4; } finally { - - if (sf!=null && sf.isClosed() == false) { - mgt.closeConnection(); - } - + // close the connection + mgt.closeConnection(); } } @@ -188,7 +182,7 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm { } // create the database's connection - private SessionFactory getConnection(List Info) throws IOException { + private void getConnection(List Info) throws IOException { // create the connection Iterator iterator = Info.iterator(); @@ -200,15 +194,12 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm { String DatabaseURL = iterator.next(); String DatabaseName = iterator.next(); - SessionFactory sf = mgt.createConnection(DatabaseUserName, + mgt.createConnection(DatabaseUserName, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabaseName); AnalysisLogger.getLogger().debug( "In GetTableDetails->database " + DatabaseName + ": connected"); - - return sf; - } // Method that recover the info useful for the connection diff --git a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/ListSchemas.java b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/ListSchemas.java index 439ddc8..3ab6410 100644 --- a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/ListSchemas.java +++ b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/ListSchemas.java @@ -82,7 +82,7 @@ public class ListSchemas extends StandardLocalExternalAlgorithm { List Info = retrieveInfo(); // create the connection - sf = getConnection(Info); + getConnection(Info); // get the schema's list @@ -112,8 +112,6 @@ public class ListSchemas extends StandardLocalExternalAlgorithm { } - sf.close(); - } catch (HibernateException h) { AnalysisLogger.getLogger().debug( @@ -163,13 +161,9 @@ public class ListSchemas extends StandardLocalExternalAlgorithm { throw e4; } finally { - - if (sf != null && sf.isClosed() == false) { - mgt.closeConnection(); - } - + // close the connection + mgt.closeConnection(); } - } @Override @@ -223,13 +217,11 @@ public class ListSchemas extends StandardLocalExternalAlgorithm { } - finally { - - if (sf.isClosed() == false) { - mgt.closeConnection(); - } - - } +// finally { +// if (sf.isClosed() == false) { +// mgt.closeConnection(); +// } +// } return listSchemas; @@ -418,7 +410,7 @@ public class ListSchemas extends StandardLocalExternalAlgorithm { } // method that allows to create the connection - private SessionFactory getConnection(List Info) throws IOException { + private void getConnection(List Info) throws IOException { // create the connection Iterator iterator = Info.iterator(); @@ -430,7 +422,7 @@ public class ListSchemas extends StandardLocalExternalAlgorithm { String DatabaseURL = iterator.next(); String DatabaseName = iterator.next(); - SessionFactory sf = mgt.createConnection(DatabaseUserName, + mgt.createConnection(DatabaseUserName, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabaseName); @@ -439,9 +431,6 @@ public class ListSchemas extends StandardLocalExternalAlgorithm { // AnalysisLogger.getLogger().debug("In ListSchemas->database "+DatabaseName+": connected"); // } - - return sf; - } private void normalizeDBInfo(DBResource resource) throws Exception { diff --git a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/ListTables.java b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/ListTables.java index 99c0908..cc46fd6 100644 --- a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/ListTables.java +++ b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/ListTables.java @@ -83,7 +83,7 @@ public class ListTables extends StandardLocalExternalAlgorithm { List Info = retrieveInfo(); // create the connection - sf = getConnection(Info); + getConnection(Info); // get the table' list @@ -154,9 +154,6 @@ public class ListTables extends StandardLocalExternalAlgorithm { } } - // close the connection - sf.close(); - } catch (HibernateException h) { AnalysisLogger.getLogger().debug( @@ -203,13 +200,9 @@ public class ListTables extends StandardLocalExternalAlgorithm { throw e4; } finally { - - if (sf != null && sf.isClosed() == false) { - mgt.closeConnection(); - } - + // close the connection + mgt.closeConnection(); } - } @Override @@ -408,7 +401,7 @@ public class ListTables extends StandardLocalExternalAlgorithm { } - private SessionFactory getConnection(List Info) throws IOException { + private void getConnection(List Info) throws IOException { // create the connection Iterator iterator = Info.iterator(); @@ -420,15 +413,12 @@ public class ListTables extends StandardLocalExternalAlgorithm { String DatabaseURL = iterator.next(); String DatabaseName = iterator.next(); - SessionFactory sf = mgt.createConnection(DatabaseUserName, + mgt.createConnection(DatabaseUserName, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabaseName); AnalysisLogger.getLogger().debug( "In ListTables->database " + DatabaseName + ": connected"); - - return sf; - } private void normalizeDBInfo(DBResource resource) throws Exception { diff --git a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/RandomSampleOnTable.java b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/RandomSampleOnTable.java index eae9e44..c229ace 100644 --- a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/RandomSampleOnTable.java +++ b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/RandomSampleOnTable.java @@ -101,13 +101,11 @@ public class RandomSampleOnTable extends StandardLocalExternalAlgorithm { } // create the connection - sf = getConnection(Info); + getConnection(Info); // smart sample operation on table map = randomSampleOnTable(); - - // close the connection - sf.close(); + } catch (HibernateException h) { AnalysisLogger.getLogger().debug( "In RandomSmartSampleOnTable-> ERROR " + h.getMessage()); @@ -148,9 +146,7 @@ public class RandomSampleOnTable extends StandardLocalExternalAlgorithm { } finally { // close the connection - if (sf != null && sf.isClosed() == false) { - mgt.closeConnection(); - } + mgt.closeConnection(); } } @@ -314,7 +310,7 @@ public class RandomSampleOnTable extends StandardLocalExternalAlgorithm { } // create the database's connection - private SessionFactory getConnection(List Info) throws IOException { + private void getConnection(List Info) throws IOException { // create the connection Iterator iterator = Info.iterator(); @@ -326,7 +322,7 @@ public class RandomSampleOnTable extends StandardLocalExternalAlgorithm { String DatabaseURL = iterator.next(); String DatabaseName = iterator.next(); - SessionFactory sf = mgt.createConnection(DatabaseUserName, + mgt.createConnection(DatabaseUserName, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabaseName); @@ -334,8 +330,6 @@ public class RandomSampleOnTable extends StandardLocalExternalAlgorithm { "In RandomSampleOnTable->database " + DatabaseName + ": connected"); - return sf; - } // to perform the sample operation on the table randomly diff --git a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SampleOnTable.java b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SampleOnTable.java index 937ef2d..8c0052e 100644 --- a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SampleOnTable.java +++ b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SampleOnTable.java @@ -99,14 +99,11 @@ public class SampleOnTable extends StandardLocalExternalAlgorithm { } // create the connection - sf = getConnection(Info); + getConnection(Info); // sample operation on table map = sampleOnTable(); - - // close the connection - sf.close(); - + } catch (HibernateException h) { AnalysisLogger.getLogger().debug( "In SampleOnTable-> ERROR " + h.getMessage()); @@ -146,9 +143,7 @@ public class SampleOnTable extends StandardLocalExternalAlgorithm { } finally { // close the connection - if (sf!=null && sf.isClosed() == false) { - mgt.closeConnection(); - } + mgt.closeConnection(); } } @@ -314,7 +309,7 @@ public class SampleOnTable extends StandardLocalExternalAlgorithm { } // create the database's connection - private SessionFactory getConnection(List Info) throws IOException { + private void getConnection(List Info) throws IOException { // create the connection Iterator iterator = Info.iterator(); @@ -326,14 +321,12 @@ public class SampleOnTable extends StandardLocalExternalAlgorithm { String DatabaseURL = iterator.next(); String DatabaseName = iterator.next(); - SessionFactory sf = mgt.createConnection(DatabaseUserName, + mgt.createConnection(DatabaseUserName, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabaseName); AnalysisLogger.getLogger().debug( "In SampleOnTable->database " + DatabaseName + ": connected"); - - return sf; } // to perform the sample operation on the table diff --git a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SmartSampleOnTable.java b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SmartSampleOnTable.java index a8513a9..e70f2b2 100644 --- a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SmartSampleOnTable.java +++ b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SmartSampleOnTable.java @@ -101,13 +101,11 @@ public class SmartSampleOnTable extends StandardLocalExternalAlgorithm { } // create the connection - sf = getConnection(Info); + getConnection(Info); // smart sample operation on table map = smartSampleOnTable(); - - // close the connection - sf.close(); + } catch (HibernateException h) { AnalysisLogger.getLogger().debug( "In SmartSampleOnTable-> ERROR " + h.getMessage()); @@ -146,10 +144,7 @@ public class SmartSampleOnTable extends StandardLocalExternalAlgorithm { throw e4; } finally { - // close the connection - if (sf!=null && sf.isClosed() == false) { - mgt.closeConnection(); - } + mgt.closeConnection(); } } @@ -315,7 +310,7 @@ public class SmartSampleOnTable extends StandardLocalExternalAlgorithm { } // create the database's connection - private SessionFactory getConnection(List Info) throws IOException { + private void getConnection(List Info) throws IOException { // create the connection Iterator iterator = Info.iterator(); @@ -327,15 +322,14 @@ public class SmartSampleOnTable extends StandardLocalExternalAlgorithm { String DatabaseURL = iterator.next(); String DatabaseName = iterator.next(); - SessionFactory sf = mgt.createConnection(DatabaseUserName, + mgt.createConnection(DatabaseUserName, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabaseName); AnalysisLogger.getLogger().debug( "In SmartSampleOnTable->database " + DatabaseName + ": connected"); - return sf; - } + } // to perform the sample operation on the table private LinkedHashMap smartSampleOnTable() diff --git a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SubmitQuery.java b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SubmitQuery.java index 6695145..6e0ded8 100644 --- a/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SubmitQuery.java +++ b/src/main/java/org/gcube/dataaccess/algorithms/drmalgorithms/SubmitQuery.java @@ -122,8 +122,8 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm { // submit a query map = submitQuery(); - // close the connection - dbconnection.close(); +// // close the connection +// dbconnection.close(); } catch (HibernateException h) { @@ -181,8 +181,10 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm { throw e4; } finally { - if (dbconnection!=null && dbconnection.isClosed() == false) { + if (dbconnection!=null) { dbconnection.close(); + AnalysisLogger.getLogger().debug("In SubmitQuery-> Connection closed"); + dbconnection=null; } //remove the timer if the execution query has already terminated if (stopper!=null){ @@ -295,8 +297,10 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm { AnalysisLogger.getLogger().debug("In SubmitQuery->Shutdown"); try{ - if (dbconnection!=null && dbconnection.isClosed() == false) { + if (dbconnection!=null) { dbconnection.close(); + AnalysisLogger.getLogger().debug("In SubmitQuery-> Connection closed"); + dbconnection=null; } }catch(Exception e){ AnalysisLogger.getLogger().debug("In SubmitQuery->Unable to close connection "+e.getMessage());