[PATCH] minMax queries
Wald Commits
scm-commit at wald.intevation.org
Wed Aug 15 14:34:28 CEST 2018
# HG changeset patch
# User gernotbelger
# Date 1534336463 -7200
# Node ID 34cd4faf43f4321f541f67a9b40cd49cf2e8d468
# Parent bc9a45d2b1faad50c99d83768a556e6a3a3fa0b4
minMax queries
diff -r bc9a45d2b1fa -r 34cd4faf43f4 artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java Wed Aug 15 13:59:09 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/DynamicMainValuesTimeRangeDeterminationService.java Wed Aug 15 14:34:23 2018 +0200
@@ -25,6 +25,7 @@
import org.dive4elements.river.model.Gauge;
import org.dive4elements.river.model.River;
import org.dive4elements.river.model.sinfo.DailyDischargeValue;
+import org.dive4elements.river.model.sinfo.DailyDischargeValue.MinMax;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -92,18 +93,15 @@
for (final Gauge gauge : gauges) {
- final List<DailyDischargeValue> qdvsGlobal = DailyDischargeValue.getGlobalMinMax(gauge);
- if (qdvsGlobal == null) {
-
+ final Date minGlobalForGauge = DailyDischargeValue.getGlobalMinMax(gauge, MinMax.min);
+ final Date maxGlobalForGauge = DailyDischargeValue.getGlobalMinMax(gauge, MinMax.max);
+ if (minGlobalForGauge == null || maxGlobalForGauge == null) { // der Fall, dass nur eins von beiden null ist, kann eigentlich nciht vorkommen
gaugeResults.add(new GaugeInfoResult.GaugeInfo(getMsg(meta, "bundu.wst_no_data_at_all"), gauge, null, null));
// TODO : wenn der Workflow abgebrochen werden soll, GlobalErrorMsg setzen, dass mind. ein Pegel überhaupt keine Daten
// hat (der Mechnismus auf Client-Seite ist schon implementiert)
continue;
}
- assert qdvsGlobal.size() == 2;
- final Date minGlobalForGauge = qdvsGlobal.get(0).getDay();
- final Date maxGlobalForGauge = qdvsGlobal.get(1).getDay();
if (minGlobalForGauge.getTime() > startTime.getTime())
min = minGlobalForGauge;
diff -r bc9a45d2b1fa -r 34cd4faf43f4 backend/src/main/java/org/dive4elements/river/model/sinfo/DailyDischargeValue.java
--- a/backend/src/main/java/org/dive4elements/river/model/sinfo/DailyDischargeValue.java Wed Aug 15 13:59:09 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/sinfo/DailyDischargeValue.java Wed Aug 15 14:34:23 2018 +0200
@@ -11,7 +11,6 @@
package org.dive4elements.river.model.sinfo;
import java.io.Serializable;
-import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -50,6 +49,10 @@
DAY, DISCHARGE;
}
+ public enum MinMax {
+ min, max
+ }
+
/***** FIELDS *****/
private static final long serialVersionUID = -6192738825193230784L;
@@ -139,22 +142,17 @@
/**
* Selects from the database the daily discharge, puts the first and the last into a List (min, max day)
*/
- public static List<DailyDischargeValue> getGlobalMinMax(final Gauge gauge) {
+
+ public static Date getGlobalMinMax(final Gauge gauge, final MinMax minmax) {
final Session session = SessionHolder.HOLDER.get();
- final Query query = session
- .createQuery("SELECT v" + " FROM DailyDischargeValue AS v JOIN v.dailyDischarge AS s" + " WHERE (s.gauge.id=:gaugeid) ORDER BY day");
+ final Query query = session.createQuery(
+ "SELECT " + minmax.toString() + "(v.day) " + " FROM DailyDischargeValue AS v JOIN v.dailyDischarge AS s" + " WHERE (s.gauge.id=:gaugeid)");
query.setParameter("gaugeid", gauge.getId());
- return minMaxFromDbResultHelper(query.list());
+ final List<Date> list = query.list();
+ if (list != null && list.size() == 1) {
+ return list.get(0);
+ }
+ return null;
}
- private static List<DailyDischargeValue> minMaxFromDbResultHelper(final List<DailyDischargeValue> values) {
- if (values != null && values.size() > 1) {
- final List<DailyDischargeValue> newList = new ArrayList<>();
- newList.add(values.get(0));
- newList.add(values.get(values.size() - 1));
- return newList;
- }
- return null;
-
- }
}
More information about the Dive4Elements-commits
mailing list