changeset 9633:b0520a85739d

Nachtrag Pos. 19: query for most recent discharge table added
author mschaefer
date Thu, 17 Oct 2019 16:48:03 +0200
parents 9c07a33c2d62
children 694062b1875a
files backend/src/main/java/org/dive4elements/river/model/Gauge.java
diffstat 1 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/model/Gauge.java	Tue Oct 15 15:14:07 2019 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/Gauge.java	Thu Oct 17 16:48:03 2019 +0200
@@ -243,6 +243,23 @@
     }
 
     /**
+     * Fetches from the database the most recent discharge table
+     */
+    public DischargeTable fetchRecentDischargeTable() {
+        final Session session = SessionHolder.HOLDER.get();
+
+        final Query query = session.createQuery("FROM DischargeTable" //
+                + " WHERE (gauge = :gauge)" //
+                + " ORDER BY timeInterval.startTime DESC");
+
+        query.setParameter("gauge", this);
+
+        final List<Object> results = query.list();
+
+        return results.isEmpty() ? null : (DischargeTable) results.get(0);
+    }
+
+    /**
      * Returns an array of [days, qs] necessary to create duration curves.
      *
      * @return a 2dim array of [days, qs] where days is an int[] and qs is
@@ -251,8 +268,11 @@
     public Object[] fetchDurationCurveData() {
         final Session session = SessionHolder.HOLDER.get();
 
-        final Query query = session.createQuery("select cast(nmv.name as integer) as days, mv.value as q " + "from MainValue as mv "
-                + "join mv.mainValue as nmv " + "join nmv.type mvt " + "where mvt.name = 'D' and mv.gauge.id = :gauge_id " + "order by days");
+        final Query query = session.createQuery("select cast(nmv.name as integer) as days, mv.value as q " //
+                + "from MainValue as mv " //
+                + "join mv.mainValue as nmv " //
+                + "join nmv.type mvt " //
+                + "where mvt.name = 'D' and mv.gauge.id = :gauge_id " + "order by days");
 
         query.setParameter("gauge_id", getId());
 

http://dive4elements.wald.intevation.org