diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FastCrossSectionLineFactory.java @ 2119:dc28ea60b53d

Added cached/chunked access to cross section lines. TODO: Use the FastCrossSectionLines. flys-artifacts/trunk@3689 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 16 Jan 2012 15:51:46 +0000
parents
children d626ae185305
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FastCrossSectionLineFactory.java	Mon Jan 16 15:51:46 2012 +0000
@@ -0,0 +1,52 @@
+package de.intevation.flys.artifacts.model;
+
+import de.intevation.flys.artifacts.cache.CacheFactory;
+
+import de.intevation.flys.model.CrossSection;
+import de.intevation.flys.model.CrossSectionLine;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.Element;
+
+import java.util.List;
+
+
+public class FastCrossSectionLineFactory
+{
+    public static final String CACHE_NAME = "fast-cross-section-lines";
+
+    private FastCrossSectionLineFactory() {
+    }
+
+    public static FastCrossSectionLine getCrossSectionLine(
+        CrossSection cs,
+        double       km
+    ) {
+        Cache cache = CacheFactory.getCache(CACHE_NAME);
+
+        if (cache == null) {
+            List<CrossSectionLine> lines = cs.getLines(km, km);
+            return lines.isEmpty()
+                ? null
+                : new FastCrossSectionLine(lines.get(0));
+        }
+
+        String cacheKey = FastCrossSectionChunk.createHashKey(cs, km);
+
+        Element element = cache.get(cacheKey);
+
+        FastCrossSectionChunk fcsc;
+
+        if (element != null) {
+            fcsc = (FastCrossSectionChunk)element.getValue();
+        }
+        else {
+            fcsc = new FastCrossSectionChunk(cs, km);
+            element = new Element(cacheKey, fcsc);
+            cache.put(element);
+        }
+
+        return fcsc.getCrossSectionLine(km);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org