changeset 8210:3bb00338228c

(issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 05 Sep 2014 15:09:44 +0200 (2014-09-05)
parents 5114b643a6d6
children f01fc10e2184 ebdf34cae14d
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java
diffstat 2 files changed, 29 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Fri Sep 05 18:30:20 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java	Fri Sep 05 15:09:44 2014 +0200
@@ -140,6 +140,23 @@
             int    kind,
             String description,
             Date   startTime,
+            Date   stopTime
+        ) {
+            this.id          = id;
+            this.kind        = kind;
+            this.description = description;
+            this.startTime   = startTime;
+            this.stopTime    = stopTime;
+            this.sqStartTime = null;
+            this.sqStopTime  = null;
+            this.sqRelId     = 0;
+        }
+
+        public Load(
+            int    id,
+            int    kind,
+            String description,
+            Date   startTime,
             Date   stopTime,
             int    sqRelId,
             Date   sqStartTime,
@@ -153,7 +170,6 @@
             this.sqStartTime = sqStartTime;
             this.sqStopTime  = sqStopTime;
             this.sqRelId     = sqRelId;
-            log.debug("Creating Load with sqrelid: " + sqRelId + " start: "+ sqStartTime);
         }
 
         public int getId() {
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java	Fri Sep 05 18:30:20 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java	Fri Sep 05 15:09:44 2014 +0200
@@ -48,7 +48,7 @@
         "FROM sediment_load_values slv " +
           "JOIN sediment_load sl ON slv.sediment_load_id = sl.id " +
           "JOIN time_intervals ti ON sl.time_interval_id = ti.id " +
-          "JOIN time_intervals sqti ON sl.sq_time_interval_id = sqti.id " +
+          "LEFT JOIN time_intervals sqti ON sl.sq_time_interval_id = sqti.id " +
           "JOIN grain_fraction gf ON sl.grain_fraction_id = gf.id " +
           "JOIN measurement_station ms ON slv.measurement_station_id = ms.id " +
           "JOIN rivers r ON ms.river_id = r.id " +
@@ -147,10 +147,17 @@
             String    ms_type          = (String)row[12];
 
             if (load == null || load.getId() != sl_id) {
-                load = new SedimentLoadData.Load(
-                    sl_id, sl_kind, sl_description,
-                    ti_start_time, ti_stop_time, sq_id,
-                    sq_start_time, sq_stop_time);
+                if (sq_id == null) {
+                    /* Avoid NPE when converting the objects. */
+                    load = new SedimentLoadData.Load(
+                        sl_id, sl_kind, sl_description,
+                        ti_start_time, ti_stop_time);
+                } else {
+                    load = new SedimentLoadData.Load(
+                        sl_id, sl_kind, sl_description,
+                        ti_start_time, ti_stop_time, sq_id,
+                        sq_start_time, sq_stop_time);
+                }
 
                 // Grain fractions only change when a new sediment load starts.
                 grainFractionIndex =

http://dive4elements.wald.intevation.org