annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/HYKFactory.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3278
diff changeset
9 package org.dive4elements.river.artifacts.model;
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3278
diff changeset
11 import org.dive4elements.river.artifacts.cache.CacheFactory;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3278
diff changeset
12 import org.dive4elements.river.backend.SessionHolder;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3278
diff changeset
13 import org.dive4elements.river.model.HYK;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3278
diff changeset
14 import org.dive4elements.river.model.HYKFlowZone;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3278
diff changeset
15 import org.dive4elements.river.model.HYKFormation;
3278
c27c4e06dd87 Re-add HYK rendering code to CrossSectionGenerator
Christian Lins <christian.lins@intevation.de>
parents: 2423
diff changeset
16
c27c4e06dd87 Re-add HYK rendering code to CrossSectionGenerator
Christian Lins <christian.lins@intevation.de>
parents: 2423
diff changeset
17 import java.io.Serializable;
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
18 import java.util.ArrayList;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
19 import java.util.List;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
20
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
21 import net.sf.ehcache.Cache;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
22 import net.sf.ehcache.Element;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
23
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
24 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
25 import org.apache.logging.log4j.LogManager;
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
26 import org.hibernate.Query;
3278
c27c4e06dd87 Re-add HYK rendering code to CrossSectionGenerator
Christian Lins <christian.lins@intevation.de>
parents: 2423
diff changeset
27 import org.hibernate.SQLQuery;
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
28 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
29 import org.hibernate.type.StandardBasicTypes;
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
30
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 /**
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
33 * Factory to access HYKs (hydrographic values).
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
34 */
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
35 public class HYKFactory
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36 {
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8202
diff changeset
37 private static Logger log = LogManager.getLogger(HYKFactory.class);
2131
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 public static String HYK_CACHE_NAME = "hykache";
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
40
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 /** Do not instantiate a HYKFactory. */
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
43 private HYKFactory() {
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
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47 /**
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
48 * Get List of Zones for given river and km.
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
49 */
2139
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
50 public static Object getHYKs(int hykid, double km) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
51 log.debug("HYKFactory.getHYKs");
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
52
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
53 Cache cache = CacheFactory.getCache(HYK_CACHE_NAME);
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
54
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
55 String cacheKey;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
56
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
57 if (cache != null) {
2139
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
58 cacheKey = "" + hykid + "_" + km;
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
59 Element element = cache.get(cacheKey);
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
60 if (element != null) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
61 log.debug("Got hyk from cache");
3278
c27c4e06dd87 Re-add HYK rendering code to CrossSectionGenerator
Christian Lins <christian.lins@intevation.de>
parents: 2423
diff changeset
62 return element.getValue();
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
63 }
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 else {
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
66 cacheKey = null;
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
2139
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
69 List<Zone> zones = getZonesUncached(hykid, km);
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
70
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
71 if (zones != null && cacheKey != null) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
72 log.debug("Store hykzones in cache.");
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
73 Element element = new Element(cacheKey, zones);
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
74 cache.put(element);
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 return zones;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
78 }
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
79
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
80
2155
8c9c40459d8f Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2148
diff changeset
81 /** 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
82 public static String getHykName(int hykid) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
83 log.debug("HYKFactory.getHykName " + hykid);
2139
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
84
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
85 Session session = SessionHolder.HOLDER.get();
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
86
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
87 Query query = session.createQuery(
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
88 "select description from HYK where id = :hykid ");
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
89 query.setParameter("hykid", hykid);
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 return (String) query.uniqueResult();
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
92 }
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
93
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
94
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
95 /**
2155
8c9c40459d8f Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2148
diff changeset
96 * 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
97 * @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
98 * @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
99 * @return according zones.
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
100 */
2139
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
101 public static List<Zone> getZonesUncached(int hykid, double km) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
102 if (log.isDebugEnabled()) {
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
103 log.debug("HYKFactory.getZoneUncached " + hykid + " km " + km);
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
104 }
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
105
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
106 Session session = SessionHolder.HOLDER.get();
2137
04b6b6a4564d Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2131
diff changeset
107
2155
8c9c40459d8f Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2148
diff changeset
108 // 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
109 // 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
110 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
111 rQuery.setParameter("hykid", hykid);
8c9c40459d8f Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2148
diff changeset
112 rQuery.setMaxResults(1);
8c9c40459d8f Respect rivers flow direction when looking for hyk-formations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2148
diff changeset
113 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
114
2419
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
115 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
116
2419
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
117 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
118 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
119
2139
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
120 // Take the first one.
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
121 if (forms.size() >= 1) {
923256599afe Somewhat improved hyk handling and rendering.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2137
diff changeset
122 HYKFormation form = forms.get(0);
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
123 // Create respective zones.
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
124 for (HYKFlowZone flowZone: form.getZones()) {
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
125 Zone z = new Zone(flowZone.getA().doubleValue(),
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
126 flowZone.getB().doubleValue(),
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
127 flowZone.getType().getName());
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
128 zones.add(z);
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
129 }
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
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
132 return zones;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
133 }
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
134
2419
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
135
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
136 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
137 int hykid,
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
138 double km,
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
139 double flowDir
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
140 ) {
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
141 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
142
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
143 String SQL = "SELECT " +
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
144 " f.id AS FID, " +
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
145 " 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
146 " 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
147 " e.km AS KM " +
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
148 " 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
149 " 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
150 " 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
151 " AND :km between " +
8030
fac1aa67931b Fix for flys/issue1735 (Versatz in den HYK-Dateien)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
152 " LEAST(e.km, e.km + :flowDir*(f.distance_vl/1000.0-0.001)) " +
2419
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
153 " AND " +
8030
fac1aa67931b Fix for flys/issue1735 (Versatz in den HYK-Dateien)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
154 " GREATEST(e.km, e.km + :flowDir*(f.distance_vl/1000.0-0.001))";
2419
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
155
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
156 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
157 .addScalar("FID", StandardBasicTypes.INTEGER)
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
158 .addScalar("DIST", StandardBasicTypes.DOUBLE)
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
159 .addScalar("HID", StandardBasicTypes.INTEGER)
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
160 .addScalar("KM", StandardBasicTypes.DOUBLE);
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
161
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
162 sqlQuery.setInteger("hykid", hykid);
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
163 sqlQuery.setDouble("flowDir", flowDir);
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
164 sqlQuery.setDouble("km", km);
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
165
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
166 boolean debug = log.isDebugEnabled();
8030
fac1aa67931b Fix for flys/issue1735 (Versatz in den HYK-Dateien)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
167
fac1aa67931b Fix for flys/issue1735 (Versatz in den HYK-Dateien)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
168 if (debug) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
169 log.debug("HYK SQL: " + sqlQuery.getQueryString());
8030
fac1aa67931b Fix for flys/issue1735 (Versatz in den HYK-Dateien)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
170 }
2419
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
171
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
172 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
173
8030
fac1aa67931b Fix for flys/issue1735 (Versatz in den HYK-Dateien)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
174 if (debug) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
175 log.debug("Found " + results.size() + " HYKFormation IDs in DB.");
8030
fac1aa67931b Fix for flys/issue1735 (Versatz in den HYK-Dateien)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
176 }
2419
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
177
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
178 if (results == null || results.isEmpty()) {
8030
fac1aa67931b Fix for flys/issue1735 (Versatz in den HYK-Dateien)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
179 if (debug) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8030
diff changeset
180 log.debug("No HYK found for ID " + hykid + " at km " + km);
8030
fac1aa67931b Fix for flys/issue1735 (Versatz in den HYK-Dateien)
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
181 }
2419
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
182 return new ArrayList<HYKFormation>();
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
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
185 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
186 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
187
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
188 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
189 query.setParameter("id", hykFormationId);
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
190 query.setMaxResults(1);
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
191
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
192 return query.list();
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
193 }
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
194
98a350bb91a9 Fixed broken HYKs in crosssection charts for river Mosel.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2155
diff changeset
195
3278
c27c4e06dd87 Re-add HYK rendering code to CrossSectionGenerator
Christian Lins <christian.lins@intevation.de>
parents: 2423
diff changeset
196 /** Labeled section. */
2148
345a236f7075 Made HYKFactory.Zone Serializable (and thus cachable).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2139
diff changeset
197 public static class Zone implements Serializable {
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
198 /** Lower end of segment. */
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
199 protected double from;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
200 /** Upper end of segment. */
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
201 protected double to;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
202 /** The label. */
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
203 protected String name;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
204
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
205 /** Constructor for labelled section. */
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
206 public Zone (double from, double to, String name) {
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
207 this.from = from;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
208 this.to = to;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
209 this.name = name;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
210 }
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
211
2137
04b6b6a4564d Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2131
diff changeset
212 /** Get upper value. */
04b6b6a4564d Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2131
diff changeset
213 public double getTo() {
04b6b6a4564d Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2131
diff changeset
214 return to;
04b6b6a4564d Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2131
diff changeset
215 }
04b6b6a4564d Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2131
diff changeset
216
04b6b6a4564d Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2131
diff changeset
217 /** Get lower value. */
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
218 public double getFrom() {
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
219 return from;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
220 }
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
221
2137
04b6b6a4564d Prepare improved hyk-handling.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2131
diff changeset
222 /** Get name (type). */
2131
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
223 public String getName() {
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
224 return name;
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
225 }
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
226 } // public static class Zone
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
227 }
e50a928187cd Added stubby hyk infrastructure.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
228 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org