Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/BedloadOverviewFactory.java @ 4357:11cf29eb002c
FacetTypes: New type: exreme_wq_curve_base (for the Stuetz-Q-Poits).
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 02 Nov 2012 11:58:11 +0100 |
parents | ae598cf50682 |
children |
rev | line source |
---|---|
3751
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model.minfo; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
2 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
3 import net.sf.ehcache.Cache; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
4 import net.sf.ehcache.Element; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
5 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
6 import org.apache.log4j.Logger; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
7 import org.hibernate.Session; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
8 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.flys.artifacts.cache.CacheFactory; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.flys.backend.SedDBSessionHolder; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 public class BedloadOverviewFactory { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 private static Logger log = Logger.getLogger(BedloadOverviewFactory.class); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 public static final String CACHE_NAME = "sq-overviews"; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 private BedloadOverviewFactory() { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 public static BedloadOverview getOverview(String river) { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
24 boolean debug = log.isDebugEnabled(); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 if (debug) { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 log.debug( |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 "Looking for bedload overview for river '" + river + "'"); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 Cache cache = CacheFactory.getCache(CACHE_NAME); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
32 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 if (cache == null) { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 if (debug) { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 log.debug("Cache not configured."); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 return getUncached(river); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 String key = "bedload-over-" + river; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
41 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
42 Element element = cache.get(key); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
43 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
44 if (element != null) { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
45 if (debug) { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
46 log.debug("Overview found in cache"); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
47 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
48 return (BedloadOverview)element.getValue(); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
49 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
50 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
51 BedloadOverview overview = getUncached(river); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
52 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
53 if (overview != null) { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
54 if (debug) { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
55 log.debug("Store overview in cache."); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 cache.put(new Element(key, overview)); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
58 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
59 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
60 return overview; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
61 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
63 public static BedloadOverview getUncached(String river) { |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 BedloadOverview overview = new BedloadOverview(river); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 Session session = SedDBSessionHolder.HOLDER.get(); |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
67 |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
68 return overview.load(session) ? overview : null; |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 } |
ae598cf50682
Added new services to render overview charts in minfo bed quality calculation
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 } |