- GetTableDetails, ListSchemas, ListTables, RandomSample, SmartSample, Sample, SubmitQuery algorithms modified to close the connection through the mgt.closeconnection in the DatabaseManager class of DatabasesResourcesManager component.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-access/DatabasesResourcesManagerAlgorithms@100988 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-10-24 16:46:41 +00:00
parent cf08416252
commit 2788cd651b
7 changed files with 44 additions and 89 deletions

View File

@ -88,7 +88,7 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm {
List<String> Info = retrieveInfo(); List<String> Info = retrieveInfo();
// create the connection // create the connection
sf = getConnection(Info); getConnection(Info);
// get table's details // get table's details
@ -97,9 +97,6 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm {
map = getDetails(); map = getDetails();
// close the connection
sf.close();
} catch (HibernateException h) { } catch (HibernateException h) {
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
@ -146,11 +143,8 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm {
throw e4; throw e4;
} finally { } finally {
// close the connection
if (sf!=null && sf.isClosed() == false) { mgt.closeConnection();
mgt.closeConnection();
}
} }
} }
@ -188,7 +182,7 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm {
} }
// create the database's connection // create the database's connection
private SessionFactory getConnection(List<String> Info) throws IOException { private void getConnection(List<String> Info) throws IOException {
// create the connection // create the connection
Iterator<String> iterator = Info.iterator(); Iterator<String> iterator = Info.iterator();
@ -200,15 +194,12 @@ public class GetTableDetails extends StandardLocalExternalAlgorithm {
String DatabaseURL = iterator.next(); String DatabaseURL = iterator.next();
String DatabaseName = iterator.next(); String DatabaseName = iterator.next();
SessionFactory sf = mgt.createConnection(DatabaseUserName, mgt.createConnection(DatabaseUserName,
DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL,
DatabaseName); DatabaseName);
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
"In GetTableDetails->database " + DatabaseName + ": connected"); "In GetTableDetails->database " + DatabaseName + ": connected");
return sf;
} }
// Method that recover the info useful for the connection // Method that recover the info useful for the connection

View File

@ -82,7 +82,7 @@ public class ListSchemas extends StandardLocalExternalAlgorithm {
List<String> Info = retrieveInfo(); List<String> Info = retrieveInfo();
// create the connection // create the connection
sf = getConnection(Info); getConnection(Info);
// get the schema's list // get the schema's list
@ -112,8 +112,6 @@ public class ListSchemas extends StandardLocalExternalAlgorithm {
} }
sf.close();
} catch (HibernateException h) { } catch (HibernateException h) {
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
@ -163,13 +161,9 @@ public class ListSchemas extends StandardLocalExternalAlgorithm {
throw e4; throw e4;
} finally { } finally {
// close the connection
if (sf != null && sf.isClosed() == false) { mgt.closeConnection();
mgt.closeConnection();
}
} }
} }
@Override @Override
@ -223,13 +217,11 @@ public class ListSchemas extends StandardLocalExternalAlgorithm {
} }
finally { // finally {
// if (sf.isClosed() == false) {
if (sf.isClosed() == false) { // mgt.closeConnection();
mgt.closeConnection(); // }
} // }
}
return listSchemas; return listSchemas;
@ -418,7 +410,7 @@ public class ListSchemas extends StandardLocalExternalAlgorithm {
} }
// method that allows to create the connection // method that allows to create the connection
private SessionFactory getConnection(List<String> Info) throws IOException { private void getConnection(List<String> Info) throws IOException {
// create the connection // create the connection
Iterator<String> iterator = Info.iterator(); Iterator<String> iterator = Info.iterator();
@ -430,7 +422,7 @@ public class ListSchemas extends StandardLocalExternalAlgorithm {
String DatabaseURL = iterator.next(); String DatabaseURL = iterator.next();
String DatabaseName = iterator.next(); String DatabaseName = iterator.next();
SessionFactory sf = mgt.createConnection(DatabaseUserName, mgt.createConnection(DatabaseUserName,
DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL,
DatabaseName); DatabaseName);
@ -439,9 +431,6 @@ public class ListSchemas extends StandardLocalExternalAlgorithm {
// AnalysisLogger.getLogger().debug("In ListSchemas->database "+DatabaseName+": connected"); // AnalysisLogger.getLogger().debug("In ListSchemas->database "+DatabaseName+": connected");
// } // }
return sf;
} }
private void normalizeDBInfo(DBResource resource) throws Exception { private void normalizeDBInfo(DBResource resource) throws Exception {

View File

@ -83,7 +83,7 @@ public class ListTables extends StandardLocalExternalAlgorithm {
List<String> Info = retrieveInfo(); List<String> Info = retrieveInfo();
// create the connection // create the connection
sf = getConnection(Info); getConnection(Info);
// get the table' list // get the table' list
@ -154,9 +154,6 @@ public class ListTables extends StandardLocalExternalAlgorithm {
} }
} }
// close the connection
sf.close();
} catch (HibernateException h) { } catch (HibernateException h) {
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
@ -203,13 +200,9 @@ public class ListTables extends StandardLocalExternalAlgorithm {
throw e4; throw e4;
} finally { } finally {
// close the connection
if (sf != null && sf.isClosed() == false) { mgt.closeConnection();
mgt.closeConnection();
}
} }
} }
@Override @Override
@ -408,7 +401,7 @@ public class ListTables extends StandardLocalExternalAlgorithm {
} }
private SessionFactory getConnection(List<String> Info) throws IOException { private void getConnection(List<String> Info) throws IOException {
// create the connection // create the connection
Iterator<String> iterator = Info.iterator(); Iterator<String> iterator = Info.iterator();
@ -420,15 +413,12 @@ public class ListTables extends StandardLocalExternalAlgorithm {
String DatabaseURL = iterator.next(); String DatabaseURL = iterator.next();
String DatabaseName = iterator.next(); String DatabaseName = iterator.next();
SessionFactory sf = mgt.createConnection(DatabaseUserName, mgt.createConnection(DatabaseUserName,
DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL,
DatabaseName); DatabaseName);
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
"In ListTables->database " + DatabaseName + ": connected"); "In ListTables->database " + DatabaseName + ": connected");
return sf;
} }
private void normalizeDBInfo(DBResource resource) throws Exception { private void normalizeDBInfo(DBResource resource) throws Exception {

View File

@ -101,13 +101,11 @@ public class RandomSampleOnTable extends StandardLocalExternalAlgorithm {
} }
// create the connection // create the connection
sf = getConnection(Info); getConnection(Info);
// smart sample operation on table // smart sample operation on table
map = randomSampleOnTable(); map = randomSampleOnTable();
// close the connection
sf.close();
} catch (HibernateException h) { } catch (HibernateException h) {
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
"In RandomSmartSampleOnTable-> ERROR " + h.getMessage()); "In RandomSmartSampleOnTable-> ERROR " + h.getMessage());
@ -148,9 +146,7 @@ public class RandomSampleOnTable extends StandardLocalExternalAlgorithm {
} finally { } finally {
// close the connection // 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 // create the database's connection
private SessionFactory getConnection(List<String> Info) throws IOException { private void getConnection(List<String> Info) throws IOException {
// create the connection // create the connection
Iterator<String> iterator = Info.iterator(); Iterator<String> iterator = Info.iterator();
@ -326,7 +322,7 @@ public class RandomSampleOnTable extends StandardLocalExternalAlgorithm {
String DatabaseURL = iterator.next(); String DatabaseURL = iterator.next();
String DatabaseName = iterator.next(); String DatabaseName = iterator.next();
SessionFactory sf = mgt.createConnection(DatabaseUserName, mgt.createConnection(DatabaseUserName,
DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL,
DatabaseName); DatabaseName);
@ -334,8 +330,6 @@ public class RandomSampleOnTable extends StandardLocalExternalAlgorithm {
"In RandomSampleOnTable->database " + DatabaseName "In RandomSampleOnTable->database " + DatabaseName
+ ": connected"); + ": connected");
return sf;
} }
// to perform the sample operation on the table randomly // to perform the sample operation on the table randomly

View File

@ -99,14 +99,11 @@ public class SampleOnTable extends StandardLocalExternalAlgorithm {
} }
// create the connection // create the connection
sf = getConnection(Info); getConnection(Info);
// sample operation on table // sample operation on table
map = sampleOnTable(); map = sampleOnTable();
// close the connection
sf.close();
} catch (HibernateException h) { } catch (HibernateException h) {
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
"In SampleOnTable-> ERROR " + h.getMessage()); "In SampleOnTable-> ERROR " + h.getMessage());
@ -146,9 +143,7 @@ public class SampleOnTable extends StandardLocalExternalAlgorithm {
} finally { } finally {
// close the connection // 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 // create the database's connection
private SessionFactory getConnection(List<String> Info) throws IOException { private void getConnection(List<String> Info) throws IOException {
// create the connection // create the connection
Iterator<String> iterator = Info.iterator(); Iterator<String> iterator = Info.iterator();
@ -326,14 +321,12 @@ public class SampleOnTable extends StandardLocalExternalAlgorithm {
String DatabaseURL = iterator.next(); String DatabaseURL = iterator.next();
String DatabaseName = iterator.next(); String DatabaseName = iterator.next();
SessionFactory sf = mgt.createConnection(DatabaseUserName, mgt.createConnection(DatabaseUserName,
DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL,
DatabaseName); DatabaseName);
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
"In SampleOnTable->database " + DatabaseName + ": connected"); "In SampleOnTable->database " + DatabaseName + ": connected");
return sf;
} }
// to perform the sample operation on the table // to perform the sample operation on the table

View File

@ -101,13 +101,11 @@ public class SmartSampleOnTable extends StandardLocalExternalAlgorithm {
} }
// create the connection // create the connection
sf = getConnection(Info); getConnection(Info);
// smart sample operation on table // smart sample operation on table
map = smartSampleOnTable(); map = smartSampleOnTable();
// close the connection
sf.close();
} catch (HibernateException h) { } catch (HibernateException h) {
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
"In SmartSampleOnTable-> ERROR " + h.getMessage()); "In SmartSampleOnTable-> ERROR " + h.getMessage());
@ -146,10 +144,7 @@ public class SmartSampleOnTable extends StandardLocalExternalAlgorithm {
throw e4; throw e4;
} finally { } finally {
// close the connection mgt.closeConnection();
if (sf!=null && sf.isClosed() == false) {
mgt.closeConnection();
}
} }
} }
@ -315,7 +310,7 @@ public class SmartSampleOnTable extends StandardLocalExternalAlgorithm {
} }
// create the database's connection // create the database's connection
private SessionFactory getConnection(List<String> Info) throws IOException { private void getConnection(List<String> Info) throws IOException {
// create the connection // create the connection
Iterator<String> iterator = Info.iterator(); Iterator<String> iterator = Info.iterator();
@ -327,15 +322,14 @@ public class SmartSampleOnTable extends StandardLocalExternalAlgorithm {
String DatabaseURL = iterator.next(); String DatabaseURL = iterator.next();
String DatabaseName = iterator.next(); String DatabaseName = iterator.next();
SessionFactory sf = mgt.createConnection(DatabaseUserName, mgt.createConnection(DatabaseUserName,
DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL, DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL,
DatabaseName); DatabaseName);
AnalysisLogger.getLogger().debug( AnalysisLogger.getLogger().debug(
"In SmartSampleOnTable->database " + DatabaseName "In SmartSampleOnTable->database " + DatabaseName
+ ": connected"); + ": connected");
return sf; }
}
// to perform the sample operation on the table // to perform the sample operation on the table
private LinkedHashMap<String, StatisticalType> smartSampleOnTable() private LinkedHashMap<String, StatisticalType> smartSampleOnTable()

View File

@ -122,8 +122,8 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
// submit a query // submit a query
map = submitQuery(); map = submitQuery();
// close the connection // // close the connection
dbconnection.close(); // dbconnection.close();
} catch (HibernateException h) { } catch (HibernateException h) {
@ -181,8 +181,10 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
throw e4; throw e4;
} finally { } finally {
if (dbconnection!=null && dbconnection.isClosed() == false) { if (dbconnection!=null) {
dbconnection.close(); dbconnection.close();
AnalysisLogger.getLogger().debug("In SubmitQuery-> Connection closed");
dbconnection=null;
} }
//remove the timer if the execution query has already terminated //remove the timer if the execution query has already terminated
if (stopper!=null){ if (stopper!=null){
@ -295,8 +297,10 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
AnalysisLogger.getLogger().debug("In SubmitQuery->Shutdown"); AnalysisLogger.getLogger().debug("In SubmitQuery->Shutdown");
try{ try{
if (dbconnection!=null && dbconnection.isClosed() == false) { if (dbconnection!=null) {
dbconnection.close(); dbconnection.close();
AnalysisLogger.getLogger().debug("In SubmitQuery-> Connection closed");
dbconnection=null;
} }
}catch(Exception e){ }catch(Exception e){
AnalysisLogger.getLogger().debug("In SubmitQuery->Unable to close connection "+e.getMessage()); AnalysisLogger.getLogger().debug("In SubmitQuery->Unable to close connection "+e.getMessage());