[PATCH 4 of 5] issue1345: Added getDepth() to SedimentDensityFactory

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


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1381745734 -7200
# Node ID 349730f8a49f2cd75592f8cf4fd4c419a0873c6f
# Parent  5ac4c9119aefe4f4601f09461cb3399d3c3a7492
issue1345: Added getDepth() to SedimentDensityFactory.

diff -r 5ac4c9119aef -r 349730f8a49f artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java
--- 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();


More information about the Dive4elements-commits mailing list