changeset 6725:7ea933f9c6ea

issu1393/SedimentLoadFactory: Handle off_epoch type queries.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 31 Jul 2013 11:32:00 +0200
parents 0baf7abffcc6
children b68798973da2
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
diffstat 1 files changed, 46 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Wed Jul 31 11:13:41 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Wed Jul 31 11:32:00 2013 +0200
@@ -35,10 +35,12 @@
     /** Private logger to use here. */
     private static Logger log = Logger.getLogger(SedimentLoadFactory.class);
 
+    // Cache name/keys
     public static final String LOADS_CACHE_NAME = "sedimentloads";
     public static final String LOAD_DATA_CACHE_NAME = "sedimentload-data";
 
-    /** Query to get km and ws for wst_id and column_pos. */
+    /** Query to get description and start year of single type
+     * sediment_yields. */
     public static final String SQL_SELECT_SINGLES =
         "SELECT DISTINCT " +
         "       sy.description AS description, " +
@@ -51,7 +53,23 @@
         "       AND ti.stop_time IS NULL " +
         "       AND syv.station BETWEEN :startKm AND :endKm";
 
-    /** Query to get name for wst_id and column_pos. */
+    /** Query to get description, name and time range for official
+     * epoch-type sediment yields. */
+    public static final String SQL_SELECT_OFFEPOCHS =
+        "SELECT DISTINCT " +
+        "       ti.start_time AS startYear, " +
+        "       ti.stop_time AS end " +
+        "   FROM     sediment_yield sy " +
+        "       JOIN rivers r ON sy.river_id = r.id " +
+        "       JOIN sediment_yield_values syv ON sy.id = syv.sediment_yield_id " +
+        "       JOIN time_intervals ti ON sy.time_interval_id = ti.id " +
+        "   WHERE   r.name = :name " +
+        "       AND ti.stop_time IS NOT NULL " +
+        "       AND syv.station BETWEEN :startKm AND :endKm " +
+        "       AND sy.kind = 1";
+
+    /** Query to get description, name and time range for epoch-type
+     * sediment yields. */
     public static final String SQL_SELECT_EPOCHS =
         "SELECT DISTINCT " +
         "       sy.description AS description, " +
@@ -145,7 +163,8 @@
     }
 
     /**
-     *
+     * @param river name of river.
+     * @param type
      */
     public static SedimentLoad[] getLoads(
         String river,
@@ -289,6 +308,30 @@
             }
             return loads;
         }
+        else if (type.equals("off_epoch")) {
+            sqlQuery = session.createSQLQuery(SQL_SELECT_OFFEPOCHS)
+                .addScalar("startYear", StandardBasicTypes.DATE)
+                .addScalar("end", StandardBasicTypes.DATE);
+            sqlQuery.setString("name", river);
+            sqlQuery.setDouble("startKm", startKm);
+            sqlQuery.setDouble("endKm", endKm);
+            List<Object []> results = sqlQuery.list();
+
+            SedimentLoad[] loads = new SedimentLoad[results.size()];
+            for (int i = 0; i < results.size(); i++) {
+                Object[] row = results.get(i);
+                loads[i] = new SedimentLoad(
+                    ((Date) row[0]).toString() + (Date) row[1],
+                    (Date) row[0],
+                    (Date) row[1],
+                    true,
+                    "");
+            }
+            return loads;
+        }
+        else {
+             log.warn("getSedimentLoadsUncached does not understand type " + type);
+        }
         return new SedimentLoad[0];
     }
 

http://dive4elements.wald.intevation.org