added the refresh for samplings (sampling e smartSampling) and submitQuery operations. The cached data related to these operations are removed from cache.

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@100342 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Loredana Liccardo 2014-10-02 09:57:21 +00:00
parent 8ffb77cfee
commit 0e03e6ad86
3 changed files with 87 additions and 8 deletions

View File

@ -874,18 +874,18 @@ public class GxtTreePanel extends LayoutContainer {
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 if (selectedItem.getDatabaseType()!=null && (selectedItem.getDatabaseType().equals(ConstantsPortlet.POSTGRES))){ //refresh schema list and query executed
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 if (selectedItem.getDatabaseType()!=null && (selectedItem.getDatabaseType().equals(ConstantsPortlet.MYSQL))){ //refresh tables list, query executed and samplings
inputData.put("ResourceName", resource); inputData.put("ResourceName", resource);
inputData.put("DatabaseName", database); inputData.put("DatabaseName", database);
inputData.put("SchemaName", ""); inputData.put("SchemaName", "");
} }
} else if (Depth == 4) { //schema } else if (Depth == 4) { // Schema. Refresh tables list, query executed and samplings
elementType = "schema"; elementType = "schema";
String schema = selectedItem.getName(); String schema = selectedItem.getName();
FileModel db = store.getParent(selectedItem); FileModel db = store.getParent(selectedItem);

View File

@ -24,6 +24,11 @@ public class ConstantsPortlet {
public static final String DATABASE="Database"; public static final String DATABASE="Database";
public static final String SCHEMA="Schema"; public static final String SCHEMA="Schema";
public static final String ALGID_SUBMITQUERY="SUBMITQUERY";
public static final String ALGID_SAMPLEONTABLE="SAMPLEONTABLE";
public static final String ALGID_SMARTSAMPLEONTABLE="SMARTSAMPLEONTABLE";
// public static final String ALGID_RANDOMSAMPLEONTABLE="RANDOMSAMPLEONTABLE";

View File

@ -987,13 +987,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// parse the query in order to remove spaces // parse the query in order to remove spaces
String queryParsed = parseQuery(inputParameters.get(5).getValue()); String queryParsed = parseQuery(inputParameters.get(5).getValue());
// get data sent to client calling the submitQuery // get data sent to client calling the submitQuery
String keyData = inputParameters.get(0).getValue() String keyData = algorithmId + inputParameters.get(0).getValue()
+ inputParameters.get(1).getValue() + inputParameters.get(1).getValue()
+ inputParameters.get(2).getValue() + inputParameters.get(2).getValue()
+ inputParameters.get(3).getValue() + inputParameters.get(3).getValue()
+ inputParameters.get(4).getValue() + queryParsed; + inputParameters.get(4).getValue() + queryParsed;
// System.out.println("KEY:" + keyData); // System.out.println("submitQuery KEY:" + keyData);
// System.out.println("UID:" + UID); // System.out.println("UID:" + UID);
// store key // store key
// updateListKeyData(UID, keyData); // updateListKeyData(UID, keyData);
@ -1259,6 +1259,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
+ inputParameters.get(2).getValue() + inputParameters.get(2).getValue()
+ inputParameters.get(3).getValue(); + inputParameters.get(3).getValue();
// System.out.println("sampling KEY: " + key);
net.sf.ehcache.Element dataFromCache = getDataFromCache(key); net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
Object value = null; Object value = null;
@ -2425,8 +2427,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
Boolean value = checkSubmitQueryUIDCachedData(uidSubmitQuery); Boolean value = checkSubmitQueryUIDCachedData(uidSubmitQuery);
if (value != null) { if (value != null) {
// System.out.println("For uid " + uidSubmitQuery // System.out.println("For uid " + uidSubmitQuery
// + " data are cached? " + value.booleanValue()); // + " data are cached? " + value.booleanValue());
if (!value.booleanValue()) { if (!value.booleanValue()) {
// remove computation // remove computation
String computationId = null; String computationId = null;
@ -2512,7 +2514,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// removeResult(submitQueryUID); // removeResult(submitQueryUID);
// removeSubmitQueryUIDCachedData(submitQueryUID); // removeSubmitQueryUIDCachedData(submitQueryUID);
removeKeySubmitQueryResult(submitQueryUID); removeKeySubmitQueryResult(submitQueryUID);
// System.out.println("data refreshed on server"); // System.out.println("data refreshed on server");
} }
} }
@ -2547,6 +2549,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
if (inputData != null && inputData.size() != 0) { if (inputData != null && inputData.size() != 0) {
// System.out.println("server-> input size not null"); // System.out.println("server-> input size not null");
String key = ""; String key = "";
String keyUsedForQueryRefresh = "";
String keyUsedForSamplingsRefresh = "";
String keyUsedForSmartSamplingRefresh = "";
String keyUsedForRandomSamplingRefresh = "";
if (!ElementType.equals("")) { if (!ElementType.equals("")) {
// System.out.println("server-> element type not null"); // System.out.println("server-> element type not null");
@ -2563,6 +2569,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// list // list
key = inputData.get("ResourceName") key = inputData.get("ResourceName")
+ inputData.get("DatabaseName"); + inputData.get("DatabaseName");
// refresh submitted queries
keyUsedForQueryRefresh = ConstantsPortlet.ALGID_SUBMITQUERY
+ key;
refreshSubmittedQueryInCache(keyUsedForQueryRefresh);
} }
if (element.getDatabaseType().equals( if (element.getDatabaseType().equals(
ConstantsPortlet.MYSQL)) { // refresh table ConstantsPortlet.MYSQL)) { // refresh table
@ -2570,6 +2583,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
key = inputData.get("ResourceName") key = inputData.get("ResourceName")
+ inputData.get("DatabaseName") + inputData.get("DatabaseName")
+ inputData.get("SchemaName"); + inputData.get("SchemaName");
keyUsedForQueryRefresh = ConstantsPortlet.ALGID_SUBMITQUERY
+ key;
refreshSubmittedQueryInCache(keyUsedForQueryRefresh);
keyUsedForSamplingsRefresh = ConstantsPortlet.ALGID_SAMPLEONTABLE
+ key;
keyUsedForSmartSamplingRefresh = ConstantsPortlet.ALGID_SMARTSAMPLEONTABLE
+ key;
refreshSamplingsInCache(keyUsedForSamplingsRefresh, keyUsedForSmartSamplingRefresh);
} }
break; break;
@ -2577,6 +2602,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
key = inputData.get("ResourceName") key = inputData.get("ResourceName")
+ inputData.get("DatabaseName") + inputData.get("DatabaseName")
+ inputData.get("SchemaName"); + inputData.get("SchemaName");
// refresh submitted query and samplings
keyUsedForQueryRefresh = ConstantsPortlet.ALGID_SUBMITQUERY
+ key;
refreshSubmittedQueryInCache(keyUsedForQueryRefresh);
keyUsedForSamplingsRefresh = ConstantsPortlet.ALGID_SAMPLEONTABLE
+ key;
keyUsedForSmartSamplingRefresh = ConstantsPortlet.ALGID_SMARTSAMPLEONTABLE
+ key;
refreshSamplingsInCache(keyUsedForSamplingsRefresh, keyUsedForSmartSamplingRefresh);
break; break;
} }
} }
@ -2659,6 +2696,43 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
// } // }
} }
private synchronized void refreshSubmittedQueryInCache(String key)
throws Exception {
List<String> keysInCache = employeeCache.getKeys();
int listSize = keysInCache.size();
List<String> keysToBeRemoved = new ArrayList<>();
// recover keys list that match the key
for (int i = 0; i < listSize; i++) {
if (keysInCache.get(i).startsWith(key)) {
keysToBeRemoved.add(keysInCache.get(i));
}
}
//remove keys
employeeCache.removeAll(keysToBeRemoved);
// System.out.println("SubmittedQuery refreshed with key: " + key);
}
private synchronized void refreshSamplingsInCache(String keyUsedForSamplingsRefresh, String keyUsedForSmartSamplingRefresh)
throws Exception {
List<String> keysInCache = employeeCache.getKeys();
int listSize = keysInCache.size();
List<String> keysToBeRemoved = new ArrayList<>();
// recover keys list that match the key
for (int i = 0; i < listSize; i++) {
if ((keysInCache.get(i).startsWith(keyUsedForSamplingsRefresh)) || (keysInCache.get(i).startsWith(keyUsedForSmartSamplingRefresh))) {
keysToBeRemoved.add(keysInCache.get(i));
}
}
//remove keys
employeeCache.removeAll(keysToBeRemoved);
// System.out.println("Samplings refreshed with keys: "+keyUsedForSamplingsRefresh+" "+keyUsedForSmartSamplingRefresh);
}
private String storeResultIntoCSVFile(List<Result> result, String n) private String storeResultIntoCSVFile(List<Result> result, String n)
throws Exception { throws Exception {