Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/model/BedHeight.java @ 9218:13b764afb536
Bed height queries extended by km range condition
author | mschaefer |
---|---|
date | Wed, 04 Jul 2018 10:36:54 +0200 |
parents | aca5a7a57a3a |
children | 8642a76f22be |
comparison
equal
deleted
inserted
replaced
9217:4e6111f87dda | 9218:13b764afb536 |
---|---|
206 } | 206 } |
207 | 207 |
208 public static List<BedHeight> getBedHeights(final River river, final double kmLo, final double kmHi) { | 208 public static List<BedHeight> getBedHeights(final River river, final double kmLo, final double kmHi) { |
209 final Session session = SessionHolder.HOLDER.get(); | 209 final Session session = SessionHolder.HOLDER.get(); |
210 | 210 |
211 final Query query = session.createQuery("from BedHeight where river=:river"); | 211 final Query query = session.createQuery("from BedHeight" |
212 + " where river=:river" | |
213 + " and id in (select bedHeight.id from BedHeightValue" | |
214 + " where station between :kmfrom and :kmto" | |
215 + " group by bedHeight.id)"); | |
212 | 216 |
213 query.setParameter("river", river); | 217 query.setParameter("river", river); |
214 | 218 query.setParameter("kmfrom", kmLo); |
215 // TODO Do km range filtering in SQL statement | 219 query.setParameter("kmto", kmHi); |
216 | 220 |
217 final List<BedHeight> singles = query.list(); | 221 final List<BedHeight> singles = query.list(); |
218 final List<BedHeight> good = new ArrayList<>(); | 222 final List<BedHeight> good = new ArrayList<>(); |
219 | 223 |
220 for (final BedHeight s : singles) { | 224 for (final BedHeight s : singles) { |
241 final List<BedHeight> singles = query.list(); | 245 final List<BedHeight> singles = query.list(); |
242 | 246 |
243 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; | 247 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; |
244 } | 248 } |
245 | 249 |
246 // TODO Do km range filtering in SQL statement | |
247 public static BedHeight getBedHeightByDescription(final River river, final String description, final double startKm, final double endKm) { | 250 public static BedHeight getBedHeightByDescription(final River river, final String description, final double startKm, final double endKm) { |
248 | 251 |
249 final Session session = SessionHolder.HOLDER.get(); | 252 final Session session = SessionHolder.HOLDER.get(); |
250 | 253 |
251 final Query query = session.createQuery("FROM BedHeight WHERE (trim(description)=:description) AND river=:river"); | 254 final Query query = session.createQuery("FROM BedHeight" |
255 + " WHERE (TRIM(description)=:description) AND river=:river" | |
256 + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" | |
257 + " WHERE station BETWEEN :kmfrom AND :kmto" | |
258 + " GROUP BY bedHeight.id)"); | |
252 query.setParameter("river", river); | 259 query.setParameter("river", river); |
253 query.setParameter("description", description); | 260 query.setParameter("description", description); |
261 query.setParameter("kmfrom", startKm); | |
262 query.setParameter("kmto", endKm); | |
254 | 263 |
255 final List<BedHeight> singles = query.list(); | 264 final List<BedHeight> singles = query.list(); |
256 | 265 |
257 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; | 266 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; |
258 } | 267 } |