[PATCH] Nachtrag Pos. 19: query for most recent discharge table added

Wald Commits scm-commit at wald.intevation.org
Thu Oct 17 16:48:24 CEST 2019


# HG changeset patch
# User mschaefer
# Date 1571323683 -7200
#      Thu Oct 17 16:48:03 2019 +0200
# Node ID b0520a85739d84d21467503ba074f2412ad82ac5
# Parent  9c07a33c2d620c76dc2882929404d96a2257438f
Nachtrag Pos. 19: query for most recent discharge table added

diff -r 9c07a33c2d62 -r b0520a85739d backend/src/main/java/org/dive4elements/river/model/Gauge.java
--- 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());
 


More information about the Dive4Elements-commits mailing list