changeset 7312:349730f8a49f

issue1345: Added getDepth() to SedimentDensityFactory.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 14 Oct 2013 12:15:34 +0200
parents 5ac4c9119aef
children bcae19901bf0
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java	Mon Oct 14 12:14:20 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java	Mon Oct 14 12:15:34 2013 +0200
@@ -48,6 +48,14 @@
         "       JOIN sediment_density_values sdv ON sd.id = sdv.sediment_density_id" +
         "   WHERE sd.id = :id";
 
+    /** Query to get sediment density depth by sediment density id. */
+    private static final String SQL_SELECT_DENSITY_DEPTH_BY_ID =
+        "SELECT d.lower AS lower, " +
+        "       d.upper AS upper" +
+        "   FROM sediment_density sd " +
+        "       JOIN depths d ON d.id = sd.depth_id " +
+        "   WHERE sd.id = :id";
+
     /** Query to get sediment density description by id. */
     private static final String SQL_SELECT_DESCRIPTION_BY_ID =
         "SELECT sd.description " +
@@ -112,6 +120,21 @@
         return density;
     }
 
+    /** Query and return depth of a sediment density entry. */
+    public static double[] getDepth(int id) {
+        log.debug("getDepth");
+        Session session = SessionHolder.HOLDER.get();
+        SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_DENSITY_DEPTH_BY_ID)
+            .addScalar("lower", StandardBasicTypes.DOUBLE)
+            .addScalar("upper", StandardBasicTypes.DOUBLE);
+        sqlQuery.setInteger("id", id);
+        List<Object[]> results = sqlQuery.list();
+        Object[] row = results.get(0);
+
+        return new double[] {(Double)row[0], (Double)row[1]};
+    }
+
+    /** Query and return description of a sediment density entry. */
     public static String getSedimentDensityDescription(int id) {
         log.debug("getSedimentDensityDescription");
         Session session = SessionHolder.HOLDER.get();

http://dive4elements.wald.intevation.org