diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java @ 632:62ea2a7b1067

'Profilschnitte' are working without cache as well, now. gnv-artifacts/trunk@711 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 25 Feb 2010 09:06:36 +0000
parents 78e0e239a0b9
children 987584605a60
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Thu Feb 25 08:23:46 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Thu Feb 25 09:06:36 2010 +0000
@@ -76,6 +76,7 @@
 import java.util.Locale;
 import java.util.Map;
 
+import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
 
 import org.apache.log4j.Logger;
@@ -171,17 +172,34 @@
     @Override
     protected Object getChartResult(String uuid, CallContext callContext) {
         log.debug("VerticalCrossSectionOutputState.getChartResult");
-        Collection<Result> result = null;
         String key = uuid + super.getID();
 
-        Element element = CacheFactory.getInstance().getCache().get(key);
-        if (element != null)
-            return element.getObjectValue();
+        CacheFactory factory = CacheFactory.getInstance();
+        if (factory.isInitialized()) {
+            log.info("Using a cachce.");
+            Cache cache = factory.getCache();
 
-        log.debug("No results in cache yet.");
+            Element element = cache.get(key);
+            if (element != null)
+                return element.getObjectValue();
 
-        InputData meshLine = inputData.get("mesh_linestring");
-        InputData meshId   = inputData.get("meshid");
+            log.debug("No results in cache yet.");
+            Object obj = getData(uuid, callContext);
+            cache.put(new Element(key, obj));
+
+            return obj;
+        }
+        else {
+            log.info("Not using a cache.");
+            return getData(uuid, callContext);
+        }
+    }
+
+
+    protected Object getData(String uuid, CallContext callContext) {
+        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");
@@ -228,8 +246,6 @@
             preProcess(result),
             callContext);
 
-        CacheFactory.getInstance().getCache().put(new Element(key, obj));
-
         return obj;
     }
 

http://dive4elements.wald.intevation.org