Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/model/River.java @ 472:1e196c75563b
Added a new method to determine the selected gauge of a river based on a start and end point.
flys-backend/trunk@1711 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 18 Apr 2011 07:29:05 +0000 |
parents | c2c3ad4fda58 |
children | b316d2106598 |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/model/River.java Fri Apr 15 16:06:15 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java Mon Apr 18 07:29:05 2011 +0000 @@ -16,6 +16,12 @@ import java.util.List; +import org.hibernate.Session; +import org.hibernate.Query; + +import de.intevation.flys.backend.SessionHolder; + + @Entity @Table(name = "rivers") public class River @@ -74,6 +80,31 @@ return name != null ? name : ""; } + + /** + * This method returns the first gauge that is intersected by <i>a</i> and + * <i>b</i>, + * + * @param a A start point. + * @param b An end point. + * + * @return the first intersecting gauge. + */ + public Gauge determineGauge(double a, double b) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createQuery( + "from Gauge where river=:river " + + "and not (range.a > :b or range.b < :a) order by a"); + query.setParameter("river", this); + query.setParameter("a", new BigDecimal(a)); + query.setParameter("b", new BigDecimal(b)); + + List<Gauge> gauges = query.list(); + + return gauges != null && gauges.size() > 0 ? gauges.get(0) : null; + } + /** * Returns the min and max distance of this river. The first position in the * resulting array contains the min distance, the second position the max