- hibernate bug fixed and related to a join tables that have some columns with identical name. Bug resolved using JDBC. GetConnection method changed in the SubmitQuery algorithm to create the connection with JDBC.
- timer added in the SubmitQuery algorithm that stops the query execution after 30 minutes. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-access/DatabasesResourcesManagerAlgorithms@99396 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f1a7326084
commit
235b900984
|
@ -2,13 +2,18 @@ package org.gcube.dataaccess.algorithms.drmalgorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
||||||
import org.gcube.dataaccess.databases.access.DatabasesDiscoverer;
|
import org.gcube.dataaccess.databases.access.DatabasesDiscoverer;
|
||||||
|
@ -33,14 +38,15 @@ import com.adventnet.swissqlapi.sql.parser.ParseException;
|
||||||
* map.
|
* map.
|
||||||
*/
|
*/
|
||||||
public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
||||||
|
|
||||||
|
static long maximum_execution_time = 30*60*1000; //time to stop execution query
|
||||||
private LinkedHashMap<String, StatisticalType> map = new LinkedHashMap<String, StatisticalType>();
|
private LinkedHashMap<String, StatisticalType> map = new LinkedHashMap<String, StatisticalType>();
|
||||||
// object that allows to manage some operations on a database
|
// object that allows to manage some operations on a database
|
||||||
private DatabaseManagement mgt;
|
private DatabaseManagement mgt;
|
||||||
// variable that keeps track of the database's type
|
// variable that keeps track of the database's type
|
||||||
private String driverInfo;
|
private String driverInfo;
|
||||||
|
|
||||||
private SessionFactory sf;
|
private Connection dbconnection;
|
||||||
// database's parameters specified by the user
|
// database's parameters specified by the user
|
||||||
private String resourceName = null;
|
private String resourceName = null;
|
||||||
private String databaseName = null;
|
private String databaseName = null;
|
||||||
|
@ -59,6 +65,16 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
||||||
// variable used to filter the disallowed queries
|
// variable used to filter the disallowed queries
|
||||||
private boolean NotAllowedQuery = false;
|
private boolean NotAllowedQuery = false;
|
||||||
|
|
||||||
|
//class for the timer to stop execution query
|
||||||
|
private class ExecutionStopper extends TimerTask {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
AnalysisLogger.getLogger().debug("ExecutionStopper: Stopping execution");
|
||||||
|
shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
|
|
||||||
|
@ -92,19 +108,22 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
||||||
HibernateException {
|
HibernateException {
|
||||||
|
|
||||||
AnalysisLogger.getLogger().debug("In SubmitQuery->Processing");
|
AnalysisLogger.getLogger().debug("In SubmitQuery->Processing");
|
||||||
|
|
||||||
|
Timer stopper = new Timer();
|
||||||
|
stopper.schedule(new ExecutionStopper(),maximum_execution_time);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// retrieve information
|
// retrieve information
|
||||||
List<String> Info = retrieveInfo();
|
List<String> Info = retrieveInfo();
|
||||||
|
|
||||||
// create the connection
|
// create the connection
|
||||||
sf = getConnection(Info);
|
dbconnection = getConnection(Info);
|
||||||
|
|
||||||
// submit a query
|
// submit a query
|
||||||
map = submitQuery();
|
map = submitQuery();
|
||||||
|
|
||||||
// close the connection
|
// close the connection
|
||||||
sf.close();
|
dbconnection.close();
|
||||||
|
|
||||||
} catch (HibernateException h) {
|
} catch (HibernateException h) {
|
||||||
|
|
||||||
|
@ -162,8 +181,18 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
||||||
throw e4;
|
throw e4;
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
if (sf.isClosed() == false) {
|
if (dbconnection!=null && dbconnection.isClosed() == false) {
|
||||||
mgt.closeConnection();
|
dbconnection.close();
|
||||||
|
}
|
||||||
|
//remove the timer if the execution query has already terminated
|
||||||
|
if (stopper!=null){
|
||||||
|
try{
|
||||||
|
stopper.cancel();
|
||||||
|
stopper.purge();
|
||||||
|
AnalysisLogger.getLogger().debug("In SubmitQuery-> Execution stopper terminated");
|
||||||
|
}catch(Exception e){
|
||||||
|
AnalysisLogger.getLogger().debug("In SubmitQuery-> Could not stop execution stopper "+e.getMessage() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,9 +294,12 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
|
||||||
AnalysisLogger.getLogger().debug("In SubmitQuery->Shutdown");
|
AnalysisLogger.getLogger().debug("In SubmitQuery->Shutdown");
|
||||||
|
try{
|
||||||
if (sf.isClosed() == false) {
|
if (dbconnection!=null && dbconnection.isClosed() == false) {
|
||||||
mgt.closeConnection();
|
dbconnection.close();
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
AnalysisLogger.getLogger().debug("In SubmitQuery->Unable to close connection "+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +395,7 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the database's connection
|
// create the database's connection
|
||||||
private SessionFactory getConnection(List<String> Info) throws IOException {
|
private Connection getConnection(List<String> Info) throws Exception {
|
||||||
|
|
||||||
// create the connection
|
// create the connection
|
||||||
Iterator<String> iterator = Info.iterator();
|
Iterator<String> iterator = Info.iterator();
|
||||||
|
@ -375,12 +407,15 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
||||||
String DatabaseURL = iterator.next();
|
String DatabaseURL = iterator.next();
|
||||||
String DatabaseName = iterator.next();
|
String DatabaseName = iterator.next();
|
||||||
|
|
||||||
SessionFactory sf = mgt.createConnection(DatabaseUserName,
|
// Load the database driver
|
||||||
DatabasePassword, DatabaseDriver, DatabaseDialect, DatabaseURL,
|
Class.forName(DatabaseDriver) ;
|
||||||
DatabaseName);
|
// Get a connection to the database
|
||||||
AnalysisLogger.getLogger().debug(
|
Connection conn = DriverManager.getConnection(DatabaseURL,DatabaseUserName,DatabasePassword) ;
|
||||||
"In SubmitQuery->database " + DatabaseName + ": connected");
|
if (conn!=null){
|
||||||
return sf;
|
AnalysisLogger.getLogger().debug(
|
||||||
|
"In SubmitQuery->database " + DatabaseName + ": connected");
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method that allows to submit a query
|
// Method that allows to submit a query
|
||||||
|
@ -504,7 +539,7 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
||||||
// sf, config.getPersistencePath());
|
// sf, config.getPersistencePath());
|
||||||
|
|
||||||
result = mgt
|
result = mgt
|
||||||
.submitQuery(query, sf, config.getPersistencePath());
|
.submitQuery(query, dbconnection, config.getPersistencePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (driverInfo.toLowerCase().contains("mysql")) {
|
if (driverInfo.toLowerCase().contains("mysql")) {
|
||||||
|
@ -515,7 +550,7 @@ public class SubmitQuery extends StandardLocalExternalAlgorithm {
|
||||||
// sf, config.getPersistencePath());
|
// sf, config.getPersistencePath());
|
||||||
|
|
||||||
result = mgt
|
result = mgt
|
||||||
.submitQuery(query, sf, config.getPersistencePath());
|
.submitQuery(query, dbconnection, config.getPersistencePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
|
Loading…
Reference in New Issue