Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/model/Gauge.java @ 468:8d76556c9616
Added methods to retrieve the min and max W and Q values of a Wst and Gauge.
flys-backend/trunk@1705 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 15 Apr 2011 13:45:06 +0000 |
parents | bfee0e05b4e7 |
children | 46bb2b9e0bdc |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java Fri Apr 15 10:31:15 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java Fri Apr 15 13:45:06 2011 +0000 @@ -17,6 +17,12 @@ import javax.persistence.OneToOne; import javax.persistence.OneToMany; +import org.hibernate.Session; +import org.hibernate.Query; + +import de.intevation.flys.backend.SessionHolder; + + @Entity @Table(name = "gauges") public class Gauge @@ -133,5 +139,43 @@ public void setDischargeTables(List<DischargeTable> dischargeTables) { this.dischargeTables = dischargeTables; } + + + /** + * Returns min and max W values of this gauge. + * + * @return the min and max W value of this gauge [min,max]. + */ + public double[] determineMinMaxW() { + Session session = SessionHolder.HOLDER.get(); + + List<DischargeTable> tables = getDischargeTables(); + DischargeTable dischargeTable = null; + + for (DischargeTable tmp: tables) { + if (tmp.getKind() == 0) { + dischargeTable = tmp; + break; + } + } + + if (dischargeTable == null) { + return null; + } + + Query query = session.createQuery( + "select min(w) as min, max(w) as max from DischargeTableValue " + + "where table_id =:table"); + query.setParameter("table", dischargeTable.getId()); + + List results = query.list(); + Object[] result = (Object[]) results.get(0); + + return result != null + ? new double[] { + ((BigDecimal) result[0]).doubleValue(), + ((BigDecimal) result[1]).doubleValue() } + : null; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :