From 0e03e6ad86c17c51f9647832ea321dc638b99442 Mon Sep 17 00:00:00 2001 From: Loredana Liccardo Date: Thu, 2 Oct 2014 09:57:21 +0000 Subject: [PATCH] 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 --- .../client/panels/GxtTreePanel.java | 6 +- .../client/utils/ConstantsPortlet.java | 5 ++ .../server/GWTdbManagerServiceImpl.java | 84 +++++++++++++++++-- 3 files changed, 87 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java index e3a0be5..d7254db 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/panels/GxtTreePanel.java @@ -874,18 +874,18 @@ public class GxtTreePanel extends LayoutContainer { FileModel parent = store.getParent(selectedItem); 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("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("DatabaseName", database); inputData.put("SchemaName", ""); } - } else if (Depth == 4) { //schema + } else if (Depth == 4) { // Schema. Refresh tables list, query executed and samplings elementType = "schema"; String schema = selectedItem.getName(); FileModel db = store.getParent(selectedItem); diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/client/utils/ConstantsPortlet.java b/src/main/java/org/gcube/portlets/user/databasesmanager/client/utils/ConstantsPortlet.java index 804de1e..823d10c 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/client/utils/ConstantsPortlet.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/client/utils/ConstantsPortlet.java @@ -24,6 +24,11 @@ public class ConstantsPortlet { public static final String DATABASE="Database"; 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"; + diff --git a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java index b9e6ba7..96f7d2c 100644 --- a/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/databasesmanager/server/GWTdbManagerServiceImpl.java @@ -987,13 +987,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // parse the query in order to remove spaces String queryParsed = parseQuery(inputParameters.get(5).getValue()); // 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(2).getValue() + inputParameters.get(3).getValue() + inputParameters.get(4).getValue() + queryParsed; - // System.out.println("KEY:" + keyData); +// System.out.println("submitQuery KEY:" + keyData); // System.out.println("UID:" + UID); // store key // updateListKeyData(UID, keyData); @@ -1259,6 +1259,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements + inputParameters.get(2).getValue() + inputParameters.get(3).getValue(); +// System.out.println("sampling KEY: " + key); + net.sf.ehcache.Element dataFromCache = getDataFromCache(key); Object value = null; @@ -2425,8 +2427,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements Boolean value = checkSubmitQueryUIDCachedData(uidSubmitQuery); if (value != null) { -// System.out.println("For uid " + uidSubmitQuery -// + " data are cached? " + value.booleanValue()); + // System.out.println("For uid " + uidSubmitQuery + // + " data are cached? " + value.booleanValue()); if (!value.booleanValue()) { // remove computation String computationId = null; @@ -2512,7 +2514,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // removeResult(submitQueryUID); // removeSubmitQueryUIDCachedData(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) { // System.out.println("server-> input size not null"); String key = ""; + String keyUsedForQueryRefresh = ""; + String keyUsedForSamplingsRefresh = ""; + String keyUsedForSmartSamplingRefresh = ""; + String keyUsedForRandomSamplingRefresh = ""; if (!ElementType.equals("")) { // System.out.println("server-> element type not null"); @@ -2563,6 +2569,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // list key = inputData.get("ResourceName") + inputData.get("DatabaseName"); + + // refresh submitted queries + keyUsedForQueryRefresh = ConstantsPortlet.ALGID_SUBMITQUERY + + key; + + refreshSubmittedQueryInCache(keyUsedForQueryRefresh); + } if (element.getDatabaseType().equals( ConstantsPortlet.MYSQL)) { // refresh table @@ -2570,6 +2583,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements key = inputData.get("ResourceName") + inputData.get("DatabaseName") + inputData.get("SchemaName"); + + keyUsedForQueryRefresh = ConstantsPortlet.ALGID_SUBMITQUERY + + key; + refreshSubmittedQueryInCache(keyUsedForQueryRefresh); + + keyUsedForSamplingsRefresh = ConstantsPortlet.ALGID_SAMPLEONTABLE + + key; + keyUsedForSmartSamplingRefresh = ConstantsPortlet.ALGID_SMARTSAMPLEONTABLE + + key; + + refreshSamplingsInCache(keyUsedForSamplingsRefresh, keyUsedForSmartSamplingRefresh); + } break; @@ -2577,6 +2602,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements key = inputData.get("ResourceName") + inputData.get("DatabaseName") + 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; } } @@ -2659,6 +2696,43 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements // } } + private synchronized void refreshSubmittedQueryInCache(String key) + throws Exception { + + List keysInCache = employeeCache.getKeys(); + int listSize = keysInCache.size(); + List 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 keysInCache = employeeCache.getKeys(); + int listSize = keysInCache.size(); + List 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, String n) throws Exception {