Mercurial > dive4elements > gnv-client
changeset 631:f4331a0df032
Chart and histogram output are working without using a cache.
gnv-artifacts/trunk@710 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 25 Feb 2010 08:23:46 +0000 |
parents | a72ecacccc91 |
children | 62ea2a7b1067 |
files | gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java |
diffstat | 1 files changed, 26 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java Thu Feb 25 07:25:21 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java Thu Feb 25 08:23:46 2010 +0000 @@ -13,6 +13,8 @@ import javax.xml.xpath.XPathConstants; +import net.sf.ehcache.Cache; + import org.apache.log4j.Logger; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -190,22 +192,33 @@ */ protected Object getChartResult(String uuid, CallContext callContext) { log.debug("OutputStateBase.getChartResult"); - Object result = null; - if (CacheFactory.getInstance().isInitialized()) { - String key = "chart_" + getHash(); - log.debug("Hash for Queryelements: " + key); - net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); + CacheFactory factory = CacheFactory.getInstance(); + + if (factory.isInitialized()) { + // we use a cache + log.info("Using cache."); + Cache cache = factory.getCache(); + String key = "chart_" + getHash(); + + net.sf.ehcache.Element value = cache.get(key); if (value != null) { - result = value.getObjectValue(); - }else{ - result = this.getData(this.queryID); - if (CacheFactory.getInstance().isInitialized()) { - CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); - } - + log.debug("Found element in cache."); + return value.getObjectValue(); + } + else { + log.debug("Element not in cache, we need to ask the database"); + Object result = getData(queryID); + cache.put(new net.sf.ehcache.Element(key, result)); + + return result; } } - return result; + else { + // we don't use a cache, so we have to query the database every + // single time + log.info("Not using a cache."); + return getData(queryID); + } } protected Object getChartFromCache(String uuid, CallContext callContext) {