Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HYKFactory.java @ 2419:98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
flys-artifacts/trunk@4053 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 16 Feb 2012 06:47:46 +0000 |
parents | 8c9c40459d8f |
children | ac528b883b47 |
rev | line source |
---|---|
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.model; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
2 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
3 import java.util.ArrayList; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
5 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
6 import java.math.BigDecimal; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
7 |
2148
345a236f7075
Made HYKFactory.Zone Serializable (and thus cachable).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2139
diff
changeset
|
8 import java.io.Serializable; |
345a236f7075
Made HYKFactory.Zone Serializable (and thus cachable).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2139
diff
changeset
|
9 |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
10 import net.sf.ehcache.Cache; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 import net.sf.ehcache.Element; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
12 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
13 import org.apache.log4j.Logger; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
14 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 import org.hibernate.Query; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
16 import org.hibernate.Session; |
2419
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
17 import org.hibernate.SQLQuery; |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
18 import org.hibernate.type.StandardBasicTypes; |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 |
2155
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
20 import de.intevation.flys.model.HYK; |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 import de.intevation.flys.model.HYKFormation; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
22 import de.intevation.flys.model.HYKFlowZone; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 import de.intevation.flys.artifacts.cache.CacheFactory; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
26 import de.intevation.flys.backend.SessionHolder; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
27 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
28 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
29 /** |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 * Factory to access HYKs (hydrographic values). |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 */ |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 public class HYKFactory |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 { |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 private static Logger logger = Logger.getLogger(HYKFactory.class); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
36 public static String HYK_CACHE_NAME = "hykache"; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
37 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
38 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
39 /** Do not instantiate a HYKFactory. */ |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 private HYKFactory() { |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
41 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
42 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
43 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
44 /** |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
45 * Get List of Zones for given river and km. |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
46 */ |
2139
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
47 public static Object getHYKs(int hykid, double km) { |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
48 logger.debug("HYKFactory.getHYKs"); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
49 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
50 Cache cache = CacheFactory.getCache(HYK_CACHE_NAME); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
51 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
52 String cacheKey; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
53 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
54 if (cache != null) { |
2139
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
55 cacheKey = "" + hykid + "_" + km; |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
56 Element element = cache.get(cacheKey); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
57 if (element != null) { |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
58 logger.debug("Got hyk from cache"); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
59 return (List<Zone>)element.getValue(); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
60 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
61 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
62 else { |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
63 cacheKey = null; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
64 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
65 |
2139
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
66 List<Zone> zones = getZonesUncached(hykid, km); |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
67 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
68 if (zones != null && cacheKey != null) { |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
69 logger.debug("Store hykzones in cache."); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
70 Element element = new Element(cacheKey, zones); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
71 cache.put(element); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
72 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
73 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
74 return zones; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
75 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
76 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
77 |
2155
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
78 /** Return name for hyk with given id. */ |
2139
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
79 public static String getHykName(int hykid) { |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
80 logger.debug("HYKFactory.getHykName " + hykid); |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
81 |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
82 Session session = SessionHolder.HOLDER.get(); |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
83 |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
84 Query query = session.createQuery( |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
85 "select description from HYK where id = :hykid "); |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
86 query.setParameter("hykid", hykid); |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
87 |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
88 return (String) query.uniqueResult(); |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
89 } |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
90 |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
91 |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
92 /** |
2155
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
93 * Ask DB for hyk zones. |
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
94 * @param hykid ID of the 'main' HYK to query. |
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
95 * @param km for which to get the hyk-zones. |
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
96 * @return according zones. |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
97 */ |
2139
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
98 public static List<Zone> getZonesUncached(int hykid, double km) { |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
99 if (logger.isDebugEnabled()) { |
2139
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
100 logger.debug("HYKFactory.getZoneUncached " + hykid + " km " + km); |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
101 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
102 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
103 Session session = SessionHolder.HOLDER.get(); |
2137
04b6b6a4564d
Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2131
diff
changeset
|
104 |
2155
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
105 // Find out flow-direction of river. |
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
106 // OPTIMIZE: 1) query kmUp directly 2) merge queries. |
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
107 Query rQuery = session.createQuery("from HYK where id = :hykid"); |
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
108 rQuery.setParameter("hykid", hykid); |
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
109 rQuery.setMaxResults(1); |
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
110 HYK hyk = (HYK) rQuery.uniqueResult(); |
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
111 |
2419
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
112 double flowDir = hyk.getRiver().getKmUp() ? 1 : -1; |
2148
345a236f7075
Made HYKFactory.Zone Serializable (and thus cachable).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2139
diff
changeset
|
113 |
2419
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
114 List<HYKFormation> forms = getHYKFormations(hykid, km, flowDir); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
115 List<Zone> zones = new ArrayList<Zone>(); |
2155
8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2148
diff
changeset
|
116 |
2139
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
117 // Take the first one. |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
118 if (forms.size() >= 1) { |
923256599afe
Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2137
diff
changeset
|
119 HYKFormation form = forms.get(0); |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
120 // Create respective zones. |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
121 for (HYKFlowZone flowZone: form.getZones()) { |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
122 Zone z = new Zone(flowZone.getA().doubleValue(), |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
123 flowZone.getB().doubleValue(), |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
124 flowZone.getType().getName()); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
125 zones.add(z); |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
126 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
127 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
128 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
129 return zones; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
130 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
131 |
2419
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
132 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
133 protected static List<HYKFormation> getHYKFormations( |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
134 int hykid, |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
135 double km, |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
136 double flowDir |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
137 ) { |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
138 Session session = SessionHolder.HOLDER.get(); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
139 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
140 String SQL = "SELECT " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
141 " f.id AS FID, " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
142 " f.distance_vl AS DIST, " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
143 " e.hyk_id AS HID, " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
144 " e.km AS KM " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
145 " FROM hyk_formations f INNER JOIN hyk_entries e " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
146 " ON e.id = f.hyk_entry_id " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
147 " WHERE e.hyk_id = :hykid " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
148 " AND :km between " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
149 " LEAST(e.km, e.km + :flowDir*(f.distance_vl/1000.0+0.001)) " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
150 " AND " + |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
151 " GREATEST(e.km, e.km + :flowDir*(f.distance_vl/1000.0+0.001))"; |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
152 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
153 SQLQuery sqlQuery = session.createSQLQuery(SQL) |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
154 .addScalar("FID", StandardBasicTypes.INTEGER) |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
155 .addScalar("DIST", StandardBasicTypes.DOUBLE) |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
156 .addScalar("HID", StandardBasicTypes.INTEGER) |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
157 .addScalar("KM", StandardBasicTypes.DOUBLE); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
158 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
159 sqlQuery.setInteger("hykid", hykid); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
160 sqlQuery.setDouble("flowDir", flowDir); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
161 sqlQuery.setDouble("km", km); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
162 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
163 logger.debug("HYK SQL: " + sqlQuery.getQueryString()); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
164 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
165 List<Object[]> results = sqlQuery.list(); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
166 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
167 logger.debug("Found " + results.size() + " HYKFormation IDs in DB."); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
168 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
169 if (results == null || results.isEmpty()) { |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
170 logger.debug("No HYK found for ID " + hykid + " at km " + km); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
171 return new ArrayList<HYKFormation>(); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
172 } |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
173 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
174 Object[] resultSet = results.get(0); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
175 Integer hykFormationId = (Integer) resultSet[0]; |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
176 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
177 Query query = session.createQuery("from HYKFormation where id = :id"); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
178 query.setParameter("id", hykFormationId); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
179 query.setMaxResults(1); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
180 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
181 return query.list(); |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
182 } |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
183 |
98a350bb91a9
Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2155
diff
changeset
|
184 |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
185 /** Labelled section. */ |
2148
345a236f7075
Made HYKFactory.Zone Serializable (and thus cachable).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2139
diff
changeset
|
186 public static class Zone implements Serializable { |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
187 /** Lower end of segment. */ |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
188 protected double from; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
189 /** Upper end of segment. */ |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
190 protected double to; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
191 /** The label. */ |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
192 protected String name; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
193 |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
194 /** Constructor for labelled section. */ |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
195 public Zone (double from, double to, String name) { |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
196 this.from = from; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
197 this.to = to; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
198 this.name = name; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
199 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
200 |
2137
04b6b6a4564d
Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2131
diff
changeset
|
201 /** Get upper value. */ |
04b6b6a4564d
Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2131
diff
changeset
|
202 public double getTo() { |
04b6b6a4564d
Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2131
diff
changeset
|
203 return to; |
04b6b6a4564d
Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2131
diff
changeset
|
204 } |
04b6b6a4564d
Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2131
diff
changeset
|
205 |
04b6b6a4564d
Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2131
diff
changeset
|
206 /** Get lower value. */ |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
207 public double getFrom() { |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
208 return from; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
209 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
210 |
2137
04b6b6a4564d
Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2131
diff
changeset
|
211 /** Get name (type). */ |
2131
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
212 public String getName() { |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
213 return name; |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
214 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
215 } // public static class Zone |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
216 } |
e50a928187cd
Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
217 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |