Mercurial > dive4elements > river
changeset 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 | 3570e4af8cb2 |
children | 70de916d3e3a |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/model/River.java |
diffstat | 2 files changed, 37 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Fri Apr 15 16:06:15 2011 +0000 +++ b/flys-backend/ChangeLog Mon Apr 18 07:29:05 2011 +0000 @@ -1,3 +1,9 @@ +2011-04-18 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/model/River.java:: + Added a new method to determine the gauge based on a given start and end + point of the river. + 2011-04-15 Sascha L. Teichmann <sascha.teichmann@intevation.de> * doc/schema/postgresql.sql: Added 'position' column to wst_columns
--- 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