[PATCH] (issue1448) Use left join to permit loads with empty sq_time intervals to be handled

Wald Commits scm-commit at wald.intevation.org
Fri Sep 5 19:25:11 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1409922584 -7200
# Node ID 3bb00338228c39973cad99daa0e675a8fd5cc652
# Parent  5114b643a6d6ca0dc4f58202f390d96f18ed8275
(issue1448) Use left join to permit loads with empty sq_time intervals to be handled.

diff -r 5114b643a6d6 -r 3bb00338228c artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadData.java
--- 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() {
diff -r 5114b643a6d6 -r 3bb00338228c artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java
--- 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 =


More information about the Dive4Elements-commits mailing list