- 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();
// 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<String> Info) throws IOException {
private void getConnection(List<String> Info) throws IOException {
// create the connection
Iterator<String> 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

View File

@ -82,7 +82,7 @@ public class ListSchemas extends StandardLocalExternalAlgorithm {
List<String> 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<String> Info) throws IOException {
private void getConnection(List<String> Info) throws IOException {
// create the connection
Iterator<String> 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 {

View File

@ -83,7 +83,7 @@ public class ListTables extends StandardLocalExternalAlgorithm {
List<String> 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<String> Info) throws IOException {
private void getConnection(List<String> Info) throws IOException {
// create the connection
Iterator<String> 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 {

View File

@ -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<String> Info) throws IOException {
private void getConnection(List<String> Info) throws IOException {
// create the connection
Iterator<String> 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

View File

@ -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<String> Info) throws IOException {
private void getConnection(List<String> Info) throws IOException {
// create the connection
Iterator<String> 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

View File

@ -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<String> Info) throws IOException {
private void getConnection(List<String> Info) throws IOException {
// create the connection
Iterator<String> 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<String, StatisticalType> smartSampleOnTable()

View File

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