changeset 2374:ab1e642e7c85

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
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 03 Jan 2012 10:10:56 +0000
parents 056b3a5aa181
children 61cb16549eb1 ecab7e7804a9
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/model/Wst.java
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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	<sascha.teichmann@intevation.de>
 
 	* doc/schema/postgresql.sql: Remove 'NOT NULL' constraint from
--- 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<WstColumn> 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<Object[]> 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 :

http://dive4elements.wald.intevation.org