[PATCH 2 of 3] issue1435: SedimentDensityFactory: Changed variable name of query to reflect

Wald Commits scm-commit at wald.intevation.org
Tue Oct 1 09:59:56 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1380614600 -7200
# Node ID 13f0bdeb2b47cae254906e8b0036af3d57f4cf87
# Parent  c9e74fe2ed4d6f0e6c17c9f2e51836089cd0274f
issue1435: SedimentDensityFactory: Changed variable name of query to reflect
purpose better, added query and method to find description of density by its
id.

diff -r c9e74fe2ed4d -r 13f0bdeb2b47 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	Tue Oct 01 10:01:00 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java	Tue Oct 01 10:03:20 2013 +0200
@@ -39,8 +39,8 @@
         "       JOIN sediment_density_values sdv ON sd.id = sdv.sediment_density_id" +
         "   WHERE r.name = :name";
 
-    /** Query to get sediment density values and kms by id and year. */
-    private static final String SQL_SELECT_DENSITY_BY_ID_YEAR =
+    /** Query to get sediment density values and kms by id. */
+    private static final String SQL_SELECT_DENSITY_BY_ID =
         "SELECT sdv.station AS km, " +
         "       sdv.density AS density," +
         "       sdv.year AS year " +
@@ -48,6 +48,12 @@
         "       JOIN sediment_density_values sdv ON sd.id = sdv.sediment_density_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 " +
+        "   FROM sediment_density sd" +
+        "   WHERE sd.id = :id";
+
     private SedimentDensityFactory() {}
 
     public static SedimentDensity getSedimentDensity(
@@ -106,12 +112,23 @@
         return density;
     }
 
+    public static String getSedimentDensityDescription(int id) {
+        log.debug("getSedimentDensityDescription");
+        Session session = SessionHolder.HOLDER.get();
+        SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_DESCRIPTION_BY_ID)
+            .addScalar("description", StandardBasicTypes.STRING);
+        sqlQuery.setInteger("id", id);
+        List<Object> results = sqlQuery.list();
+
+        return (String) results.get(0);
+    }
+
     public static SedimentDensity getSedimentDensityUncached(
         int id
     ) {
         log.debug("getSedimentDensityUncached id/year");
         Session session = SessionHolder.HOLDER.get();
-        SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_DENSITY_BY_ID_YEAR)
+        SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_DENSITY_BY_ID)
             .addScalar("km", StandardBasicTypes.DOUBLE)
             .addScalar("density", StandardBasicTypes.DOUBLE)
             .addScalar("year", StandardBasicTypes.INTEGER);


More information about the Dive4elements-commits mailing list