# HG changeset patch # User Ingo Weinzierl # Date 1325585456 0 # Node ID ab1e642e7c853e61acca519c59bcc70d79591d44 # Parent 056b3a5aa181c3459447a43373511c71346a7cc5 Added a new method Wst.determineMinMaxQFree() to determine the min/max Qs at a given kilometer. flys-backend/trunk@3571 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 056b3a5aa181 -r ab1e642e7c85 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Mon Jan 02 13:42:27 2012 +0000 +++ b/flys-backend/ChangeLog Tue Jan 03 10:10:56 2012 +0000 @@ -1,3 +1,9 @@ +2012-01-03 Ingo Weinzierl + + * src/main/java/de/intevation/flys/model/Wst.java: Added a method + determineMinMaxQFree() that determines the min/max Qs at a given + kilometer. + 2012-01-02 Sascha L. Teichmann * doc/schema/postgresql.sql: Remove 'NOT NULL' constraint from diff -r 056b3a5aa181 -r ab1e642e7c85 flys-backend/src/main/java/de/intevation/flys/model/Wst.java --- a/flys-backend/src/main/java/de/intevation/flys/model/Wst.java Mon Jan 02 13:42:27 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Wst.java Tue Jan 03 10:10:56 2012 +0000 @@ -18,7 +18,9 @@ import org.apache.log4j.Logger; import org.hibernate.Session; +import org.hibernate.SQLQuery; import org.hibernate.Query; +import org.hibernate.type.StandardBasicTypes; import de.intevation.flys.backend.SessionHolder; @@ -37,6 +39,11 @@ private List columns; + + public static final String SQL_SELECT_MINMAX = + "select min(q) as minQ, max(q) as maxQ from wst_q_values " + + "where wst_id = :wst and not (a > :km or b < :km)"; + public Wst() { } @@ -176,5 +183,27 @@ ((BigDecimal)result[0]).doubleValue(), ((BigDecimal)result[1]).doubleValue() }; } + + + public double[] determineMinMaxQFree(double km) { + Session session = SessionHolder.HOLDER.get(); + + SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_MINMAX) + .addScalar("minQ", StandardBasicTypes.DOUBLE) + .addScalar("maxQ", StandardBasicTypes.DOUBLE); + + sqlQuery.setInteger("wst", getId()); + sqlQuery.setDouble("km", km); + + List minmaxQ = sqlQuery.list(); + + if (minmaxQ.isEmpty()) { + return null; + } + + Object[] mm = minmaxQ.get(0); + + return new double[] { (Double) mm[0], (Double) mm[1] }; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :