changeset 7219:13f0bdeb2b47

issue1435: SedimentDensityFactory: Changed variable name of query to reflect purpose better, added query and method to find description of density by its id.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 01 Oct 2013 10:03:20 +0200
parents c9e74fe2ed4d
children 7a6cb5b34bfc
files artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java
diffstat 1 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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);

http://dive4elements.wald.intevation.org