Mercurial > dive4elements > river
changeset 7498:6bfa19119040
issue1658: Have SedimentLoadFactory deliver unit name for given id.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 01 Nov 2013 16:23:32 +0100 (2013-11-01) |
parents | 8b2479d4ae30 |
children | ab17c76611f9 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java |
diffstat | 1 files changed, 26 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java Fri Nov 01 16:22:11 2013 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java Fri Nov 01 16:23:32 2013 +0100 @@ -71,6 +71,14 @@ " JOIN grain_fraction gf ON gf.id = grain_fraction_id " + " WHERE sy.id = :id "; + /** Query to get unit name of single sediment_yield. */ + public static final String SQL_SELECT_SINGLE_UNIT_BY_ID = + "SELECT DISTINCT " + + " u.name AS unit " + + " FROM sediment_yield sy " + + " JOIN units u ON u.id = unit_id " + + " WHERE sy.id = :id "; + /** Query to get description of single sediment_yield. */ public static final String SQL_SELECT_SINGLE_BY_ID = "SELECT DISTINCT " + @@ -315,6 +323,24 @@ } /** + * Get sediment load unit name. + * @param id the sediment yield by id. + * @return sediment yields unit name. + */ + public static String getSedimentYieldUnitName(int id) { + log.debug("SedimentLoadFactory.getSedimentYieldUnitName"); + + Session session = SessionHolder.HOLDER.get(); + SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_SINGLE_UNIT_BY_ID) + .addScalar("unit", StandardBasicTypes.STRING); + sqlQuery.setDouble("id", id); + + List<Object> results = sqlQuery.list(); + + return (String) results.get(0); + } + + /** * Get sediment load fraction name. * @param id the sediment yield by id. * @return sediment yields fraction name.