# HG changeset patch # User Felix Wolfsteller # Date 1383319412 -3600 # Node ID 6bfa1911904053a26a3dbb7f45c4362580edb6b1 # Parent 8b2479d4ae30d3ebf346599e866eefd059680088 issue1658: Have SedimentLoadFactory deliver unit name for given id. diff -r 8b2479d4ae30 -r 6bfa19119040 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java --- 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 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.