Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java @ 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 | 61f688a69a55 |
children | a94ed2755480 |
comparison
equal
deleted
inserted
replaced
630:a72ecacccc91 | 631:f4331a0df032 |
---|---|
10 import java.util.Iterator; | 10 import java.util.Iterator; |
11 import java.util.List; | 11 import java.util.List; |
12 import java.util.Locale; | 12 import java.util.Locale; |
13 | 13 |
14 import javax.xml.xpath.XPathConstants; | 14 import javax.xml.xpath.XPathConstants; |
15 | |
16 import net.sf.ehcache.Cache; | |
15 | 17 |
16 import org.apache.log4j.Logger; | 18 import org.apache.log4j.Logger; |
17 import org.w3c.dom.Document; | 19 import org.w3c.dom.Document; |
18 import org.w3c.dom.Element; | 20 import org.w3c.dom.Element; |
19 import org.w3c.dom.Node; | 21 import org.w3c.dom.Node; |
188 /** | 190 /** |
189 * @return | 191 * @return |
190 */ | 192 */ |
191 protected Object getChartResult(String uuid, CallContext callContext) { | 193 protected Object getChartResult(String uuid, CallContext callContext) { |
192 log.debug("OutputStateBase.getChartResult"); | 194 log.debug("OutputStateBase.getChartResult"); |
193 Object result = null; | 195 CacheFactory factory = CacheFactory.getInstance(); |
194 if (CacheFactory.getInstance().isInitialized()) { | 196 |
195 String key = "chart_" + getHash(); | 197 if (factory.isInitialized()) { |
196 log.debug("Hash for Queryelements: " + key); | 198 // we use a cache |
197 net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key); | 199 log.info("Using cache."); |
200 Cache cache = factory.getCache(); | |
201 String key = "chart_" + getHash(); | |
202 | |
203 net.sf.ehcache.Element value = cache.get(key); | |
198 if (value != null) { | 204 if (value != null) { |
199 result = value.getObjectValue(); | 205 log.debug("Found element in cache."); |
200 }else{ | 206 return value.getObjectValue(); |
201 result = this.getData(this.queryID); | 207 } |
202 if (CacheFactory.getInstance().isInitialized()) { | 208 else { |
203 CacheFactory.getInstance().getCache().put(new net.sf.ehcache.Element(key, result)); | 209 log.debug("Element not in cache, we need to ask the database"); |
204 } | 210 Object result = getData(queryID); |
205 | 211 cache.put(new net.sf.ehcache.Element(key, result)); |
206 } | 212 |
207 } | 213 return result; |
208 return result; | 214 } |
215 } | |
216 else { | |
217 // we don't use a cache, so we have to query the database every | |
218 // single time | |
219 log.info("Not using a cache."); | |
220 return getData(queryID); | |
221 } | |
209 } | 222 } |
210 | 223 |
211 protected Object getChartFromCache(String uuid, CallContext callContext) { | 224 protected Object getChartFromCache(String uuid, CallContext callContext) { |
212 log.debug("Fetch chart [" + uuid + "] from cache"); | 225 log.debug("Fetch chart [" + uuid + "] from cache"); |
213 CacheFactory cacheFactory = CacheFactory.getInstance(); | 226 CacheFactory cacheFactory = CacheFactory.getInstance(); |