# HG changeset patch # User Ingo Weinzierl # Date 1303111745 0 # Node ID 1e196c75563b75a14b609bee8303b3b231e8f4f1 # Parent 3570e4af8cb27215d4d329281db4af30b330cf4d 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 diff -r 3570e4af8cb2 -r 1e196c75563b flys-backend/ChangeLog --- 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 + + * 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 * doc/schema/postgresql.sql: Added 'position' column to wst_columns diff -r 3570e4af8cb2 -r 1e196c75563b flys-backend/src/main/java/de/intevation/flys/model/River.java --- 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 a and + * b, + * + * @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 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