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
|
||||
elementType = "database";
|
||||
String database = selectedItem.getName();
|
||||
//get the database type
|
||||
// String dbType = selectedItem.getDatabaseType();
|
||||
FileModel parent = store.getParent(selectedItem);
|
||||
String resource = parent.getName();
|
||||
|
||||
if (selectedItem.getDatabaseType()!=null && (selectedItem.getDatabaseType().equals(ConstantsPortlet.POSTGRES))){ //refresh schema list
|
||||
inputData.put("ResourceName", resource);
|
||||
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;
|
||||
|
|
|
@ -434,7 +434,7 @@ public class GxtToolbarFunctionality {
|
|||
// this tree level is a schema
|
||||
btnTablesList.enable();
|
||||
btnSubmitQuery.enable();
|
||||
btnRefresCachedData.disable();
|
||||
btnRefresCachedData.enable();
|
||||
// btnShowCreateTable.enable();
|
||||
btnShowCreateTable.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.Result;
|
||||
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.WsUtil;
|
||||
|
||||
|
@ -139,8 +140,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
.getSession());
|
||||
|
||||
// the result generated in the LoadTables method
|
||||
List<Result> result = new ArrayList<Result>();
|
||||
session.setAttribute("TablesResult", result);
|
||||
// List<Result> result = new ArrayList<Result>();
|
||||
// session.setAttribute("TablesResult", result);
|
||||
|
||||
// map that contains the submit query result and the related uid
|
||||
HashMap<String, List<Result>> submitQueryResult = new HashMap<String, List<Result>>();
|
||||
|
@ -152,16 +153,16 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
session.setAttribute("submitQueryResultParsed", submitQueryResultParsed);
|
||||
|
||||
// information about a database
|
||||
String currentDB = "";
|
||||
session.setAttribute("currentDB", currentDB);
|
||||
String previousDB = "";
|
||||
session.setAttribute("previousDB", previousDB);
|
||||
// String currentDB = "";
|
||||
// session.setAttribute("currentDB", currentDB);
|
||||
// String previousDB = "";
|
||||
// session.setAttribute("previousDB", previousDB);
|
||||
|
||||
// information about a schema
|
||||
String currentSchema = "";
|
||||
session.setAttribute("currentSchema", currentSchema);
|
||||
String previousSchema = "";
|
||||
session.setAttribute("previousSchema", previousSchema);
|
||||
// String currentSchema = "";
|
||||
// session.setAttribute("currentSchema", currentSchema);
|
||||
// String previousSchema = "";
|
||||
// session.setAttribute("previousSchema", previousSchema);
|
||||
|
||||
// Hashmap that contains computationId with a uid key
|
||||
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(2).setValue(scm);
|
||||
|
||||
|
||||
// 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);
|
||||
try{
|
||||
// get data from cache
|
||||
// check if data exist considering as key the input parameters
|
||||
String key = inputParameters.get(0).getValue()+inputParameters.get(1).getValue()+
|
||||
inputParameters.get(2).getValue();
|
||||
|
||||
// System.out.println("***KEY: " + key);
|
||||
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
||||
|
||||
Object value = null;
|
||||
if (dataFromCache != null) {
|
||||
value = dataFromCache.getObjectValue();
|
||||
// System.out.println("***GETTING DATA FROM CACHE");
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -531,37 +597,39 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
LinkedHashMap<String, String> dataInput, boolean SearchTable,
|
||||
String keyword) throws Exception {
|
||||
|
||||
ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
|
||||
.getSession());
|
||||
List<Result> result = (List<Result>) session
|
||||
.getAttribute("TablesResult");
|
||||
|
||||
// check on a database
|
||||
String currentDB = "";
|
||||
currentDB = dataInput.get("DatabaseName");
|
||||
String previousDB = (String) session.getAttribute("previousDB");
|
||||
|
||||
if (!currentDB.equals(previousDB)) {
|
||||
// result = null;
|
||||
result = new ArrayList<Result>();
|
||||
System.gc();
|
||||
}
|
||||
|
||||
previousDB = currentDB;
|
||||
session.setAttribute("previousDB", previousDB);
|
||||
|
||||
// check on a schema
|
||||
String currentSchema = "";
|
||||
currentSchema = dataInput.get("SchemaName");
|
||||
String previousSchema = (String) session.getAttribute("previousSchema");
|
||||
if (!currentSchema.equals(previousSchema)) {
|
||||
// result = null;
|
||||
result = new ArrayList<Result>();
|
||||
System.gc();
|
||||
}
|
||||
|
||||
previousSchema = currentSchema;
|
||||
session.setAttribute("previousSchema", previousSchema);
|
||||
//tables' list stored for a user session
|
||||
// ASLSession session = WsUtil.getAslSession(this.getThreadLocalRequest()
|
||||
// .getSession());
|
||||
// List<Result> result = (List<Result>) session
|
||||
// .getAttribute("TablesResult");
|
||||
// // check on a database
|
||||
// String currentDB = "";
|
||||
// currentDB = dataInput.get("DatabaseName");
|
||||
// String previousDB = (String) session.getAttribute("previousDB");
|
||||
//
|
||||
// if (!currentDB.equals(previousDB)) {
|
||||
// // result = null;
|
||||
// result = new ArrayList<Result>();
|
||||
// System.gc();
|
||||
// }
|
||||
//
|
||||
// previousDB = currentDB;
|
||||
// session.setAttribute("previousDB", previousDB);
|
||||
//
|
||||
// // check on a schema
|
||||
// String currentSchema = "";
|
||||
// currentSchema = dataInput.get("SchemaName");
|
||||
// String previousSchema = (String) session.getAttribute("previousSchema");
|
||||
// if (!currentSchema.equals(previousSchema)) {
|
||||
// // result = null;
|
||||
// result = new ArrayList<Result>();
|
||||
// System.gc();
|
||||
// }
|
||||
//
|
||||
// previousSchema = currentSchema;
|
||||
// session.setAttribute("previousSchema", previousSchema);
|
||||
|
||||
List<Result> result = new ArrayList<>();
|
||||
|
||||
// get tables
|
||||
// if (result == null)
|
||||
|
@ -620,7 +688,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
|
||||
loadResult = new BasePagingLoadResult<Result>(sublist,
|
||||
config.getOffset(), totalNumber);
|
||||
session.setAttribute("TablesResult", result);
|
||||
// session.setAttribute("TablesResult", result);
|
||||
return loadResult;
|
||||
}
|
||||
|
||||
|
@ -1684,8 +1752,21 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
key = inputData.get("ResourceName");
|
||||
break;
|
||||
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")
|
||||
+ inputData.get("DatabaseName");
|
||||
+ inputData.get("DatabaseName")
|
||||
+ inputData.get("SchemaName");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1713,10 +1794,21 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
|||
result = new GeneralOutputFromServlet(output2);
|
||||
break;
|
||||
case "database":
|
||||
resourceName = inputData.get("ResourceName");
|
||||
databaseName = inputData.get("DatabaseName");
|
||||
List<FileModel> output3 = getDBSchema(inputData);
|
||||
result = new GeneralOutputFromServlet(output3);
|
||||
if (element.getDatabaseType()!=null && (element.getDatabaseType().equals(ConstantsPortlet.POSTGRES))){ //refresh schema list
|
||||
List<FileModel> output3 = getDBSchema(inputData);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue