changeset 7305:2e4ffd35cafa

issue1345: Prepare SedimentLoadFactory to deliver fraction name and time ranges.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 14 Oct 2013 09:52:17 +0200
parents 615795d54831
children d7b2c14a9693
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
diffstat 1 files changed, 56 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Mon Oct 14 09:51:27 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java	Mon Oct 14 09:52:17 2013 +0200
@@ -54,6 +54,23 @@
         "       AND ti.stop_time IS NULL " +
         "       AND syv.station BETWEEN :startKm AND :endKm";
 
+    /** Query to get fraction name of single sediment_yield. */
+    public static final String SQL_SELECT_SINGLE_TIMES_BY_ID =
+        "SELECT DISTINCT " +
+        "       ti.start_time AS starttime, " +
+        "       ti.stop_time  AS stoptime " +
+        "   FROM    sediment_yield sy " +
+        "   JOIN    time_intervals ti ON ti.id = sy.time_interval_id " +
+        "   WHERE   sy.id = :id ";
+
+    /** Query to get fraction name of single sediment_yield. */
+    public static final String SQL_SELECT_SINGLE_FRACTION_BY_ID =
+        "SELECT DISTINCT " +
+        "       gf.name AS fraction " +
+        "   FROM    sediment_yield sy " +
+        "   JOIN    grain_fraction gf ON gf.id = grain_fraction_id " +
+        "   WHERE   sy.id = :id ";
+
     /** Query to get description of single sediment_yield. */
     public static final String SQL_SELECT_SINGLE_BY_ID =
         "SELECT DISTINCT " +
@@ -278,6 +295,45 @@
     }
 
     /**
+     * Get sediment yields time definition.
+     * @param id the sediment yield by id.
+     * @return sediment yields fraction name.
+     */
+    public static Date[] getSedimentYieldTimes(int id) {
+        log.debug("SedimentLoadFactory.getSedimentYieldTimes");
+
+        Session session = SessionHolder.HOLDER.get();
+        SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_SINGLE_TIMES_BY_ID)
+                .addScalar("starttime", StandardBasicTypes.DATE)
+                .addScalar("stoptime", StandardBasicTypes.DATE);
+        sqlQuery.setDouble("id", id);
+
+        List<Object[]> results = sqlQuery.list();
+        Object[] row = results.get(0);
+
+        return new Date[] {(Date)row[0], (Date) row[1]};
+    }
+
+    /**
+     * Get sediment load fraction name.
+     * @param id the sediment yield by id.
+     * @return sediment yields fraction name.
+     */
+    public static String getSedimentYieldFractionName(int id) {
+        log.debug("SedimentLoadFactory.getSedimentYieldFractionName");
+
+        Session session = SessionHolder.HOLDER.get();
+        SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_SINGLE_FRACTION_BY_ID)
+                .addScalar("fraction", StandardBasicTypes.STRING);
+        sqlQuery.setDouble("id", id);
+
+        List<Object> results = sqlQuery.list();
+
+        return (String) results.get(0);
+    }
+
+
+    /**
      * Get sediment load description.
      * @param id the sediment yield by id.
      * @return sediment yields description

http://dive4elements.wald.intevation.org