# HG changeset patch # User Ingo Weinzierl # Date 1317810414 0 # Node ID 19d0eb41e923c93332ef11f9b23a368fe688778a # Parent b5209452f6bb75406e07ec3fb6a9902caec6bb96 AnnotationArtifact: Bugfixes and enabled cache support. flys-artifacts/trunk@2892 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b5209452f6bb -r 19d0eb41e923 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Oct 04 16:36:19 2011 +0000 +++ b/flys-artifacts/ChangeLog Wed Oct 05 10:26:54 2011 +0000 @@ -1,3 +1,8 @@ +2011-10-05 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java: + Fixed bugs and make use of a cache for annotations now. + 2011-10-04 Sascha L. Teichmann Worked on flys/issue31 diff -r b5209452f6bb -r 19d0eb41e923 flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java Tue Oct 04 16:36:19 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/AnnotationArtifact.java Wed Oct 05 10:26:54 2011 +0000 @@ -8,7 +8,7 @@ import org.apache.log4j.Logger; -//import net.sf.ehcache.Cache; +import net.sf.ehcache.Cache; import de.intevation.artifacts.Artifact; import de.intevation.artifacts.ArtifactNamespaceContext; @@ -38,13 +38,13 @@ public class AnnotationArtifact extends StaticFLYSArtifact { /** The logger for this class. */ - private static Logger logger = Logger.getLogger(WINFOArtifact.class); + private static Logger logger = Logger.getLogger(AnnotationArtifact.class); /** The name of the artifact. */ public static final String ARTIFACT_NAME = "annotation"; /* Name of cache. */ - //public static final String CACHE_NAME = "annotations"; + public static final String CACHE_NAME = "annotations"; @Override protected void initialize(Artifact artifact, Object context, @@ -226,12 +226,33 @@ */ public List getAnnotations() { String river = FLYSUtils.getRiver(this).getName(); - logger.debug("Search annotations for river: " /*+ river*/); - //Cache cache = CacheFactory.getCache(CACHE_NAME); + logger.debug("Search annotations for river: " + river); - List annotations = new ArrayList(); + Cache cache = CacheFactory.getCache(CACHE_NAME); + String key = river; + Object old = null; - return getAnnotationsUncached(river); + if (cache != null) { + logger.debug("We are using a cache for annotations."); + + net.sf.ehcache.Element element = cache.get(key); + if (element != null) { + logger.info("Fetched annotations from cache."); + old = element.getValue(); + } + } + + if (old == null) { + old = getAnnotationsUncached(river); + } + + if (cache != null && old != null) { + cache.put(new net.sf.ehcache.Element(key, old)); + } + + return old != null + ? (List) old + : new ArrayList(); } /** @@ -241,6 +262,8 @@ * @see DistanceInfoService to access cached documents. */ protected List getAnnotationsUncached(String river) { + logger.info("Fetch annotations from database."); + List annotations = new ArrayList(); annotations = AnnotationsFactory.getPointAnnotations(river);