Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HYKFactory.java @ 2155:8c9c40459d8f
Respect rivers flow direction when looking for hyk-formations.
flys-artifacts/trunk@3738 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 20 Jan 2012 09:38:43 +0000 |
parents | 345a236f7075 |
children | 98a350bb91a9 |
comparison
equal
deleted
inserted
replaced
2154:ce9b15673f3f | 2155:8c9c40459d8f |
---|---|
13 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
14 | 14 |
15 import org.hibernate.Query; | 15 import org.hibernate.Query; |
16 import org.hibernate.Session; | 16 import org.hibernate.Session; |
17 | 17 |
18 import de.intevation.flys.model.HYK; | |
18 import de.intevation.flys.model.HYKFormation; | 19 import de.intevation.flys.model.HYKFormation; |
19 import de.intevation.flys.model.HYKFlowZone; | 20 import de.intevation.flys.model.HYKFlowZone; |
20 | 21 |
21 import de.intevation.flys.artifacts.cache.CacheFactory; | 22 import de.intevation.flys.artifacts.cache.CacheFactory; |
22 | 23 |
70 | 71 |
71 return zones; | 72 return zones; |
72 } | 73 } |
73 | 74 |
74 | 75 |
76 /** Return name for hyk with given id. */ | |
75 public static String getHykName(int hykid) { | 77 public static String getHykName(int hykid) { |
76 logger.debug("HYKFactory.getHykName " + hykid); | 78 logger.debug("HYKFactory.getHykName " + hykid); |
77 | 79 |
78 Session session = SessionHolder.HOLDER.get(); | 80 Session session = SessionHolder.HOLDER.get(); |
79 | 81 |
80 // TODO respect interval better. respect multiples (sort, limit), | |
81 // TODO respect flow direction of river. | |
82 Query query = session.createQuery( | 82 Query query = session.createQuery( |
83 "select description from HYK where id = :hykid "); | 83 "select description from HYK where id = :hykid "); |
84 query.setParameter("hykid", hykid); | 84 query.setParameter("hykid", hykid); |
85 | 85 |
86 return (String) query.uniqueResult(); | 86 return (String) query.uniqueResult(); |
87 } | 87 } |
88 | 88 |
89 | 89 |
90 /** | 90 /** |
91 * | 91 * Ask DB for hyk zones. |
92 * @param column the position columns value | 92 * @param hykid ID of the 'main' HYK to query. |
93 * @param wst_id database id of the wst | 93 * @param km for which to get the hyk-zones. |
94 * @return according WKms. | 94 * @return according zones. |
95 */ | 95 */ |
96 // TODO we also need to know the HYK-id to specify which set we are | |
97 // inspecting. | |
98 public static List<Zone> getZonesUncached(int hykid, double km) { | 96 public static List<Zone> getZonesUncached(int hykid, double km) { |
99 | 97 |
100 if (logger.isDebugEnabled()) { | 98 if (logger.isDebugEnabled()) { |
101 logger.debug("HYKFactory.getZoneUncached " + hykid + " km " + km); | 99 logger.debug("HYKFactory.getZoneUncached " + hykid + " km " + km); |
102 } | 100 } |
103 | 101 |
104 Session session = SessionHolder.HOLDER.get(); | 102 Session session = SessionHolder.HOLDER.get(); |
105 | 103 |
106 // TODO respect interval better. respect multiples (sort, limit), | 104 // Find out flow-direction of river. |
107 // TODO respect flow direction of river. | 105 // OPTIMIZE: 1) query kmUp directly 2) merge queries. |
106 Query rQuery = session.createQuery("from HYK where id = :hykid"); | |
107 rQuery.setParameter("hykid", hykid); | |
108 rQuery.setMaxResults(1); | |
109 HYK hyk = (HYK) rQuery.uniqueResult(); | |
110 BigDecimal flowDir = (hyk.getRiver().getKmUp()) ? new BigDecimal(1) : new BigDecimal(-1); | |
111 | |
112 // Query HYKFormations in range. | |
108 Query query = session.createQuery( | 113 Query query = session.createQuery( |
109 "from HYKFormation where entry.HYK.id = :hykid " + | 114 "from HYKFormation where entry.HYK.id = :hykid " + |
110 " and :km between entry.km - cast(distance_vl/1000.0 + 0.001 as big_decimal) and " + | 115 " and :km between entry.km and " + |
111 " entry.km + cast(distance_vl/1000.0 + 0.001 as big_decimal)" + | 116 " entry.km + :flowDir * "+ |
117 " cast(distance_vl/1000.0 + 0.001 as big_decimal)" + | |
112 " order by entry.km asc"); | 118 " order by entry.km asc"); |
113 query.setParameter("hykid", hykid); | 119 query.setParameter("hykid", hykid); |
114 query.setParameter("km", new BigDecimal(km)); | 120 query.setParameter("km", new BigDecimal(km)); |
121 query.setParameter("flowDir", flowDir); | |
122 query.setMaxResults(1); | |
115 | 123 |
116 List<HYKFormation> forms = query.list(); | 124 List<HYKFormation> forms = query.list(); |
117 | 125 |
118 List<Zone> zones = new ArrayList<Zone>(); | 126 List<Zone> zones = new ArrayList<Zone>(); |
119 // TODO limit query by one; sensible sorting. | 127 |
120 // Take the first one. | 128 // Take the first one. |
121 if (forms.size() >= 1) { | 129 if (forms.size() >= 1) { |
122 HYKFormation form = forms.get(0); | 130 HYKFormation form = forms.get(0); |
123 // Create respective zones. | 131 // Create respective zones. |
124 for (HYKFlowZone flowZone: form.getZones()) { | 132 for (HYKFlowZone flowZone: form.getZones()) { |