tables' list caching added (further, in loadTables method storing mechanism of tables removed for a user session).classes GxtTReePanel, GxtToolbarFunctionality, GWTdbManagerServiceImpl
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@99871 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1fa882c62d
commit
a460e30453
|
@ -841,11 +841,34 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
} else if (Depth == 3) { // database
|
} else if (Depth == 3) { // database
|
||||||
elementType = "database";
|
elementType = "database";
|
||||||
String database = selectedItem.getName();
|
String database = selectedItem.getName();
|
||||||
|
//get the database type
|
||||||
|
// String dbType = selectedItem.getDatabaseType();
|
||||||
FileModel parent = store.getParent(selectedItem);
|
FileModel parent = store.getParent(selectedItem);
|
||||||
String resource = parent.getName();
|
String resource = parent.getName();
|
||||||
|
|
||||||
|
if (selectedItem.getDatabaseType()!=null && (selectedItem.getDatabaseType().equals(ConstantsPortlet.POSTGRES))){ //refresh schema list
|
||||||
inputData.put("ResourceName", resource);
|
inputData.put("ResourceName", resource);
|
||||||
inputData.put("DatabaseName", database);
|
inputData.put("DatabaseName", database);
|
||||||
|
}
|
||||||
|
if (selectedItem.getDatabaseType()!=null && (selectedItem.getDatabaseType().equals(ConstantsPortlet.MYSQL))){ //refresh tables list
|
||||||
|
inputData.put("ResourceName", resource);
|
||||||
|
inputData.put("DatabaseName", database);
|
||||||
|
inputData.put("SchemaName", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else if (Depth == 4) { //schema
|
||||||
|
elementType = "schema";
|
||||||
|
String schema = selectedItem.getName();
|
||||||
|
FileModel db = store.getParent(selectedItem);
|
||||||
|
String database = db.getName();
|
||||||
|
FileModel rs = store.getParent(db);
|
||||||
|
String resource = rs.getName();
|
||||||
|
|
||||||
|
inputData.put("ResourceName", resource);
|
||||||
|
inputData.put("DatabaseName", database);
|
||||||
|
inputData.put("SchemaName", schema);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String elemType = elementType;
|
final String elemType = elementType;
|
||||||
|
|
|
@ -434,7 +434,7 @@ public class GxtToolbarFunctionality {
|
||||||
// this tree level is a schema
|
// this tree level is a schema
|
||||||
btnTablesList.enable();
|
btnTablesList.enable();
|
||||||
btnSubmitQuery.enable();
|
btnSubmitQuery.enable();
|
||||||
btnRefresCachedData.disable();
|
btnRefresCachedData.enable();
|
||||||
// btnShowCreateTable.enable();
|
// btnShowCreateTable.enable();
|
||||||
btnShowCreateTable.disable();
|
btnShowCreateTable.disable();
|
||||||
btnSimpleSample.disable();
|
btnSimpleSample.disable();
|
||||||
|
|
|
@ -53,6 +53,7 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.GeneralOutputFr
|
||||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.Parameter;
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.Parameter;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.Result;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
|
||||||
|
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
|
||||||
import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
|
import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
|
||||||
import org.gcube.portlets.user.databasesmanager.server.util.WsUtil;
|
import org.gcube.portlets.user.databasesmanager.server.util.WsUtil;
|
||||||
|
|
||||||
|
@ -139,8 +140,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
.getSession());
|
.getSession());
|
||||||
|
|
||||||
// the result generated in the LoadTables method
|
// the result generated in the LoadTables method
|
||||||
List<Result> result = new ArrayList<Result>();
|
// List<Result> result = new ArrayList<Result>();
|
||||||
session.setAttribute("TablesResult", result);
|
// session.setAttribute("TablesResult", result);
|
||||||
|
|
||||||
// map that contains the submit query result and the related uid
|
// map that contains the submit query result and the related uid
|
||||||
HashMap<String, List<Result>> submitQueryResult = new HashMap<String, List<Result>>();
|
HashMap<String, List<Result>> submitQueryResult = new HashMap<String, List<Result>>();
|
||||||
|
@ -152,16 +153,16 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
session.setAttribute("submitQueryResultParsed", submitQueryResultParsed);
|
session.setAttribute("submitQueryResultParsed", submitQueryResultParsed);
|
||||||
|
|
||||||
// information about a database
|
// information about a database
|
||||||
String currentDB = "";
|
// String currentDB = "";
|
||||||
session.setAttribute("currentDB", currentDB);
|
// session.setAttribute("currentDB", currentDB);
|
||||||
String previousDB = "";
|
// String previousDB = "";
|
||||||
session.setAttribute("previousDB", previousDB);
|
// session.setAttribute("previousDB", previousDB);
|
||||||
|
|
||||||
// information about a schema
|
// information about a schema
|
||||||
String currentSchema = "";
|
// String currentSchema = "";
|
||||||
session.setAttribute("currentSchema", currentSchema);
|
// session.setAttribute("currentSchema", currentSchema);
|
||||||
String previousSchema = "";
|
// String previousSchema = "";
|
||||||
session.setAttribute("previousSchema", previousSchema);
|
// session.setAttribute("previousSchema", previousSchema);
|
||||||
|
|
||||||
// Hashmap that contains computationId with a uid key
|
// Hashmap that contains computationId with a uid key
|
||||||
HashMap<String, String> computationIDMap = new HashMap<String, String>();
|
HashMap<String, String> computationIDMap = new HashMap<String, String>();
|
||||||
|
@ -498,29 +499,94 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
inputParameters.get(1).setValue(db);
|
inputParameters.get(1).setValue(db);
|
||||||
inputParameters.get(2).setValue(scm);
|
inputParameters.get(2).setValue(scm);
|
||||||
|
|
||||||
|
try{
|
||||||
// create data structure
|
// get data from cache
|
||||||
ComputationOutput outputData = new ComputationOutput();
|
// check if data exist considering as key the input parameters
|
||||||
// computation id
|
String key = inputParameters.get(0).getValue()+inputParameters.get(1).getValue()+
|
||||||
String computationId = startComputation(algorithmId, inputParameters,
|
inputParameters.get(2).getValue();
|
||||||
outputData);
|
|
||||||
|
// System.out.println("***KEY: " + key);
|
||||||
// print check on retrieving data
|
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
||||||
// logger.info("output data retrieved");
|
|
||||||
|
Object value = null;
|
||||||
// data output values
|
if (dataFromCache != null) {
|
||||||
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
|
value = dataFromCache.getObjectValue();
|
||||||
// data output keys
|
// System.out.println("***GETTING DATA FROM CACHE");
|
||||||
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
|
|
||||||
|
|
||||||
mapValues = outputData.getMapValues();
|
|
||||||
mapKeys = outputData.getmapKeys();
|
|
||||||
|
|
||||||
for (int i = 0; i < mapValues.size(); i++) {
|
|
||||||
Result row = new Result(String.valueOf(i), mapValues.get(String
|
|
||||||
.valueOf(i)));
|
|
||||||
outputParameters.add(row);
|
|
||||||
}
|
}
|
||||||
|
if (value != null) {
|
||||||
|
outputParameters = (List<Result>) value;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
//start computation
|
||||||
|
// create data structure
|
||||||
|
ComputationOutput outputData = new ComputationOutput();
|
||||||
|
// computation id
|
||||||
|
String computationId = startComputation(algorithmId, inputParameters,
|
||||||
|
outputData);
|
||||||
|
|
||||||
|
// print check on retrieving data
|
||||||
|
// logger.info("output data retrieved");
|
||||||
|
|
||||||
|
// data output values
|
||||||
|
LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
|
||||||
|
// data output keys
|
||||||
|
LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
|
||||||
|
|
||||||
|
mapValues = outputData.getMapValues();
|
||||||
|
mapKeys = outputData.getmapKeys();
|
||||||
|
|
||||||
|
for (int i = 0; i < mapValues.size(); i++) {
|
||||||
|
Result row = new Result(String.valueOf(i), mapValues.get(String
|
||||||
|
.valueOf(i)));
|
||||||
|
outputParameters.add(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
// write data in cache
|
||||||
|
if (outputParameters != null
|
||||||
|
&& outputParameters.size() != 0) {
|
||||||
|
// put data in cache
|
||||||
|
net.sf.ehcache.Element dataToCache = new net.sf.ehcache.Element(
|
||||||
|
inputParameters.get(0).getValue()
|
||||||
|
+ inputParameters.get(1).getValue()+inputParameters.get(2).getValue(),
|
||||||
|
outputParameters);
|
||||||
|
|
||||||
|
insertDataIntoCache(dataToCache);
|
||||||
|
// employeeCache.put(dataToCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
throw new Exception("Failed to load data. " + e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// // create data structure
|
||||||
|
// ComputationOutput outputData = new ComputationOutput();
|
||||||
|
// // computation id
|
||||||
|
// String computationId = startComputation(algorithmId, inputParameters,
|
||||||
|
// outputData);
|
||||||
|
//
|
||||||
|
// // print check on retrieving data
|
||||||
|
// // logger.info("output data retrieved");
|
||||||
|
//
|
||||||
|
// // data output values
|
||||||
|
// LinkedHashMap<String, String> mapValues = new LinkedHashMap<String, String>();
|
||||||
|
// // data output keys
|
||||||
|
// LinkedHashMap<String, String> mapKeys = new LinkedHashMap<String, String>();
|
||||||
|
//
|
||||||
|
// mapValues = outputData.getMapValues();
|
||||||
|
// mapKeys = outputData.getmapKeys();
|
||||||
|
//
|
||||||
|
// for (int i = 0; i < mapValues.size(); i++) {
|
||||||
|
// Result row = new Result(String.valueOf(i), mapValues.get(String
|
||||||
|
// .valueOf(i)));
|
||||||
|
// outputParameters.add(row);
|
||||||
|
// }
|
||||||
|
|
||||||
return outputParameters;
|
return outputParameters;
|
||||||
}
|
}
|
||||||
|
@ -531,37 +597,39 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
LinkedHashMap<String, String> dataInput, boolean SearchTable,
|
LinkedHashMap<String, String> dataInput, boolean SearchTable,
|
||||||
String keyword) throws Exception {
|
String keyword) throws Exception {
|
||||||
|
|
||||||
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
|
//tables' list stored for a user session
|
||||||
.getSession());
|
// ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
|
||||||
List<Result> result = (List<Result>) session
|
// .getSession());
|
||||||
.getAttribute("TablesResult");
|
// List<Result> result = (List<Result>) session
|
||||||
|
// .getAttribute("TablesResult");
|
||||||
// check on a database
|
// // check on a database
|
||||||
String currentDB = "";
|
// String currentDB = "";
|
||||||
currentDB = dataInput.get("DatabaseName");
|
// currentDB = dataInput.get("DatabaseName");
|
||||||
String previousDB = (String) session.getAttribute("previousDB");
|
// String previousDB = (String) session.getAttribute("previousDB");
|
||||||
|
//
|
||||||
if (!currentDB.equals(previousDB)) {
|
// if (!currentDB.equals(previousDB)) {
|
||||||
// result = null;
|
// // result = null;
|
||||||
result = new ArrayList<Result>();
|
// result = new ArrayList<Result>();
|
||||||
System.gc();
|
// System.gc();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
previousDB = currentDB;
|
// previousDB = currentDB;
|
||||||
session.setAttribute("previousDB", previousDB);
|
// session.setAttribute("previousDB", previousDB);
|
||||||
|
//
|
||||||
// check on a schema
|
// // check on a schema
|
||||||
String currentSchema = "";
|
// String currentSchema = "";
|
||||||
currentSchema = dataInput.get("SchemaName");
|
// currentSchema = dataInput.get("SchemaName");
|
||||||
String previousSchema = (String) session.getAttribute("previousSchema");
|
// String previousSchema = (String) session.getAttribute("previousSchema");
|
||||||
if (!currentSchema.equals(previousSchema)) {
|
// if (!currentSchema.equals(previousSchema)) {
|
||||||
// result = null;
|
// // result = null;
|
||||||
result = new ArrayList<Result>();
|
// result = new ArrayList<Result>();
|
||||||
System.gc();
|
// System.gc();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
previousSchema = currentSchema;
|
// previousSchema = currentSchema;
|
||||||
session.setAttribute("previousSchema", previousSchema);
|
// session.setAttribute("previousSchema", previousSchema);
|
||||||
|
|
||||||
|
List<Result> result = new ArrayList<>();
|
||||||
|
|
||||||
// get tables
|
// get tables
|
||||||
// if (result == null)
|
// if (result == null)
|
||||||
|
@ -620,7 +688,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
loadResult = new BasePagingLoadResult<Result>(sublist,
|
loadResult = new BasePagingLoadResult<Result>(sublist,
|
||||||
config.getOffset(), totalNumber);
|
config.getOffset(), totalNumber);
|
||||||
session.setAttribute("TablesResult", result);
|
// session.setAttribute("TablesResult", result);
|
||||||
return loadResult;
|
return loadResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1684,8 +1752,21 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
key = inputData.get("ResourceName");
|
key = inputData.get("ResourceName");
|
||||||
break;
|
break;
|
||||||
case "database":
|
case "database":
|
||||||
|
if (element.getDatabaseType().equals(ConstantsPortlet.POSTGRES)){ //refresh schema list
|
||||||
|
key = inputData.get("ResourceName")
|
||||||
|
+ inputData.get("DatabaseName");
|
||||||
|
}
|
||||||
|
if (element.getDatabaseType().equals(ConstantsPortlet.MYSQL)){ //refresh table list
|
||||||
|
key = inputData.get("ResourceName")
|
||||||
|
+ inputData.get("DatabaseName")
|
||||||
|
+ inputData.get("SchemaName");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "schema":
|
||||||
key = inputData.get("ResourceName")
|
key = inputData.get("ResourceName")
|
||||||
+ inputData.get("DatabaseName");
|
+ inputData.get("DatabaseName")
|
||||||
|
+ inputData.get("SchemaName");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1713,10 +1794,21 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
result = new GeneralOutputFromServlet(output2);
|
result = new GeneralOutputFromServlet(output2);
|
||||||
break;
|
break;
|
||||||
case "database":
|
case "database":
|
||||||
resourceName = inputData.get("ResourceName");
|
if (element.getDatabaseType()!=null && (element.getDatabaseType().equals(ConstantsPortlet.POSTGRES))){ //refresh schema list
|
||||||
databaseName = inputData.get("DatabaseName");
|
List<FileModel> output3 = getDBSchema(inputData);
|
||||||
List<FileModel> output3 = getDBSchema(inputData);
|
result = new GeneralOutputFromServlet(output3);
|
||||||
result = new GeneralOutputFromServlet(output3);
|
}
|
||||||
|
if (element.getDatabaseType()!=null && element.getDatabaseType().equals(ConstantsPortlet.MYSQL)){ //refresh table list
|
||||||
|
getTables(inputData);
|
||||||
|
|
||||||
|
}
|
||||||
|
// resourceName = inputData.get("ResourceName");
|
||||||
|
// databaseName = inputData.get("DatabaseName");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "schema":
|
||||||
|
getTables(inputData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue