diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java @ 1030:c07d9f9a738c

Removed bugs that existed in the caching mechanism (issue264, issue268). gnv-artifacts/trunk@1067 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 06 May 2010 08:32:56 +0000
parents c9996913ff4b
children 50a5ce7a47b7
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Tue May 04 14:24:23 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Thu May 06 08:32:56 2010 +0000
@@ -163,69 +163,73 @@
     @Override
     protected Object getChartResult(String uuid, CallContext callContext) {
         log.debug("HorizontalProfileMeshCrossOutputState.getChartResult");
-        Collection<Result> result = null;
-        if (CacheFactory.getInstance().isInitialized()) {
-            String key = uuid + super.getID();
-            log.debug("Hash for Queryelements: " + key);
-            net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
-            if (value != null) {
-                result = (Collection<Result>) (value.getObjectValue());
-            }else{
-
-                InputData meshLine = inputData.get("mesh_linestring");
-                InputData meshId   = inputData.get("meshid");
-
-                if (meshLine == null) {
-                    log.error("mesh_linestring is not defined");
-                    throw new IllegalStateException("missing mesh_linestring");
-                }
-
-                if (meshId == null) {
-                    log.error("meshid is not defined");
-                    throw new IllegalStateException("missing meshid");
-                }
-
-                Coordinate [] coords = WKTUtils.toCoordinates(
-                    meshLine.getValue());
-
-                if (coords == null) {
-                    throw new IllegalStateException("cannot read coordinates");
-                }
 
-                try {
-                    String additionWhere = USE_INDEX_BUFFER
-                        ? WKTUtils.worldCoordinatesToIndex(
-                            coords,
-                            result,
-                            meshId.getValue(),
-                            ijkQueryID)
-                        : WKTUtils.TRUE_EXPRESSION;
-
-                    String[] addedFilterValues = StringUtils.append(
-                        generateFilterValuesFromInputData(),
-                        additionWhere);
+        String key = getHash(uuid);
+        if (CacheFactory.getInstance().isInitialized()) {
+            log.debug("Using cache - key: " + key);
+            net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
 
-                    QueryExecutor queryExecutor = QueryExecutorFactory
-                        .getInstance()
-                        .getQueryExecutor();
-
-                    result = process(
-                        Arrays.asList(coords),
-						numSamples(callContext),
-                        queryExecutor.executeQuery(
-                        queryID,
-                        addedFilterValues));
-                }
-                catch (QueryException e) {
-                    log.error(e,e);
-                }
-
-                if (CacheFactory.getInstance().isInitialized()) {
-                    CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result));
-                }
-
+            if (value != null) {
+                log.debug("Found element in cache.");
+                return (Collection<Result>) (value.getObjectValue());
             }
         }
+
+        log.debug("Not using cache or element not found.");
+        Collection<Result> result = null;
+
+        InputData meshLine = inputData.get("mesh_linestring");
+        InputData meshId   = inputData.get("meshid");
+
+        if (meshLine == null) {
+            log.error("mesh_linestring is not defined");
+            throw new IllegalStateException("missing mesh_linestring");
+        }
+
+        if (meshId == null) {
+            log.error("meshid is not defined");
+            throw new IllegalStateException("missing meshid");
+        }
+
+        Coordinate [] coords = WKTUtils.toCoordinates(
+            meshLine.getValue());
+
+        if (coords == null) {
+            throw new IllegalStateException("cannot read coordinates");
+        }
+
+        try {
+            String additionWhere = USE_INDEX_BUFFER
+                ? WKTUtils.worldCoordinatesToIndex(
+                    coords,
+                    result,
+                    meshId.getValue(),
+                    ijkQueryID)
+                : WKTUtils.TRUE_EXPRESSION;
+
+            String[] addedFilterValues = StringUtils.append(
+                generateFilterValuesFromInputData(),
+                additionWhere);
+
+            QueryExecutor queryExecutor = QueryExecutorFactory
+                .getInstance()
+                .getQueryExecutor();
+
+            result = process(
+                Arrays.asList(coords),
+                numSamples(callContext),
+                queryExecutor.executeQuery(
+                queryID,
+                addedFilterValues));
+        }
+        catch (QueryException e) {
+            log.error(e,e);
+        }
+
+        if (CacheFactory.getInstance().isInitialized()) {
+            CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result));
+        }
+
         return result;
     }
 

http://dive4elements.wald.intevation.org