Mercurial > dive4elements > river
diff flys-backend/src/main/java/de/intevation/flys/model/Wst.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 | c8c09e31cdb8 |
children | b5ca22aae092 |
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/model/Wst.java Fri Apr 15 10:31:15 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Wst.java Fri Apr 15 13:45:06 2011 +0000 @@ -1,6 +1,8 @@ package de.intevation.flys.model; import java.io.Serializable; +import java.math.BigDecimal; +import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; @@ -12,11 +14,21 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToOne; +import org.apache.log4j.Logger; + +import org.hibernate.Session; +import org.hibernate.Query; + +import de.intevation.flys.backend.SessionHolder; + + @Entity @Table(name = "wsts") public class Wst implements Serializable { + private static Logger logger = Logger.getLogger(Wst.class); + private Integer id; private River river; private String description; @@ -79,5 +91,53 @@ public void setKind(Integer kind) { this.kind = kind; } + + + /** + * Determines the min and max Q values of this WST. The min value is placed + * in the first field of the resulting array - the max value is placed in + * the second field. + * + * @return the min and max Q values of this WST. + */ + public double[] determineMinMaxQ() { + double[] ab = river.determineMinMaxDistance(); + return determineMinMaxQ(new Range(ab[0], ab[1], river)); + } + + + /** + * Determines the min and max Q values of this WST in the given range. The + * min value is placed in the first field of the resulting array - the max + * value is placed in the second field. + * + * @param range The range used for querying the Q values. + * + * @return the min and max Q values of this WST. + */ + public double[] determineMinMaxQ(Range range) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createQuery( + "select min(q), max(q) from WstQRange where " + + " id in " + + " (select wstQRange.id from WstColumnQRange where " + + " wstColumn.id in (select id from WstColumn where wst.id = :wst)) " + + " and range.id in " + + " (select id from Range where not (a > :end or b < :start))"); + + query.setParameter("wst", getId()); + query.setParameter("start", range.getA()); + query.setParameter("end", range.getB()); + + 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 :