diff flys-backend/src/main/java/de/intevation/flys/model/River.java @ 764:e09f00ecb915

river model: Added method to find gauge by a position lying in its range. flys-backend/trunk@2160 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 18 Jun 2011 20:13:31 +0000
parents c19d4c643526
children 5572d051347e
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/model/River.java	Wed Jun 15 09:22:00 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java	Sat Jun 18 20:13:31 2011 +0000
@@ -116,6 +116,17 @@
         return query.list();
     }
 
+    public Gauge determineGaugeByPosition(double p) {
+        Session session = SessionHolder.HOLDER.get();
+        Query query = session.createQuery(
+            "from Gauge where river=:river " +
+            "and :p between range.a and range.b");
+        query.setParameter("river", this);
+        query.setParameter("p", new BigDecimal(p));
+        List<Gauge> gauges = query.list();
+        return gauges.isEmpty() ? null : gauges.get(0);
+    }
+
     public Gauge determineGaugeByStation(double a, double b) {
 
         if (a > b) { double t = a; a = b; b = t; }

http://dive4elements.wald.intevation.org