[PATCH 4 of 7] issue1345: Prepare SedimentLoadFactory to deliver fraction name and time ranges

Wald Commits scm-commit at wald.intevation.org
Mon Oct 14 09:58:48 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1381737137 -7200
# Node ID 2e4ffd35cafaaf4400af0bcd1c886141ea42d085
# Parent  615795d54831015e1156dd15bc1de0015e93fdaf
issue1345: Prepare SedimentLoadFactory to deliver fraction name and time ranges.

diff -r 615795d54831 -r 2e4ffd35cafa artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java
--- 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


More information about the Dive4elements-commits mailing list