changeset 6785:6da574f78d60

SedimentLoadFactory: Survive not completely defined sediment loads.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 08 Aug 2013 16:03:41 +0200
parents 4d157de77d86
children 70b440dc5317
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
diffstat 1 files changed, 22 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Thu Aug 08 15:46:18 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Thu Aug 08 16:03:41 2013 +0200
@@ -395,19 +395,27 @@
             sqlQuery.setString("grain", "total");
             List<Object []> results = sqlQuery.list();
             SedimentLoad load = new SedimentLoad();
-            Object[] row = results.get(0);
-            load = new SedimentLoad(
-                    (String) row[0],
-                    (Date) row[1],
-                    null,
-                    false,
-                    (String) row[4]);
-            getValues("coarse", sqlQuery, load, floatStations);
-            getValues("fine_middle", sqlQuery, load, floatStations);
-            getValues("sand", sqlQuery, load, floatStations);
-            getValues("suspended_sediment", sqlQuery, load, suspStations);
-            getValues("susp_sand_bed", sqlQuery, load, floatStations);
-            getValues("susp_sand", sqlQuery, load, floatStations);
+            if (results.isEmpty()) {
+                log.warn("Empty result for year calculation.");
+            }
+            else {
+                Object[] row = results.get(0);
+                load = new SedimentLoad(
+                        (String) row[0],
+                        (Date) row[1],
+                        null,
+                        false,
+                        (String) row[4]);
+            }
+            load = getValues("coarse", sqlQuery, load, floatStations);
+            load = getValues("fine_middle", sqlQuery, load, floatStations);
+            load = getValues("sand", sqlQuery, load, floatStations);
+            load = getValues("suspended_sediment", sqlQuery, load, suspStations);
+            load = getValues("susp_sand_bed", sqlQuery, load, floatStations);
+            load = getValues("susp_sand", sqlQuery, load, floatStations);
+
+            log.debug("sqlQ: " + sqlQuery.toString());
+            log.debug("sqlQ2: " + sqlQuery.getQueryString());
 
             return load;
         }
@@ -628,6 +636,7 @@
 
     /**
      * Return sediment loads with 'unknown' fraction type.
+     * @param river Name of the river
      * @param unit Restrict result set to those of given unit.
      * @param type Type like year, epoch, off_epoch
      */

http://dive4elements.wald.intevation.org