comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadFactory.java @ 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
parents 7f438ee10be6
children b468dc65154a
comparison
equal deleted inserted replaced
7497:8b2479d4ae30 7498:6bfa19119040
67 public static final String SQL_SELECT_SINGLE_FRACTION_BY_ID = 67 public static final String SQL_SELECT_SINGLE_FRACTION_BY_ID =
68 "SELECT DISTINCT " + 68 "SELECT DISTINCT " +
69 " gf.name AS fraction " + 69 " gf.name AS fraction " +
70 " FROM sediment_yield sy " + 70 " FROM sediment_yield sy " +
71 " JOIN grain_fraction gf ON gf.id = grain_fraction_id " + 71 " JOIN grain_fraction gf ON gf.id = grain_fraction_id " +
72 " WHERE sy.id = :id ";
73
74 /** Query to get unit name of single sediment_yield. */
75 public static final String SQL_SELECT_SINGLE_UNIT_BY_ID =
76 "SELECT DISTINCT " +
77 " u.name AS unit " +
78 " FROM sediment_yield sy " +
79 " JOIN units u ON u.id = unit_id " +
72 " WHERE sy.id = :id "; 80 " WHERE sy.id = :id ";
73 81
74 /** Query to get description of single sediment_yield. */ 82 /** Query to get description of single sediment_yield. */
75 public static final String SQL_SELECT_SINGLE_BY_ID = 83 public static final String SQL_SELECT_SINGLE_BY_ID =
76 "SELECT DISTINCT " + 84 "SELECT DISTINCT " +
310 318
311 List<Object[]> results = sqlQuery.list(); 319 List<Object[]> results = sqlQuery.list();
312 Object[] row = results.get(0); 320 Object[] row = results.get(0);
313 321
314 return new Date[] {(Date)row[0], (Date) row[1]}; 322 return new Date[] {(Date)row[0], (Date) row[1]};
323 }
324
325 /**
326 * Get sediment load unit name.
327 * @param id the sediment yield by id.
328 * @return sediment yields unit name.
329 */
330 public static String getSedimentYieldUnitName(int id) {
331 log.debug("SedimentLoadFactory.getSedimentYieldUnitName");
332
333 Session session = SessionHolder.HOLDER.get();
334 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_SINGLE_UNIT_BY_ID)
335 .addScalar("unit", StandardBasicTypes.STRING);
336 sqlQuery.setDouble("id", id);
337
338 List<Object> results = sqlQuery.list();
339
340 return (String) results.get(0);
315 } 341 }
316 342
317 /** 343 /**
318 * Get sediment load fraction name. 344 * Get sediment load fraction name.
319 * @param id the sediment yield by id. 345 * @param id the sediment yield by id.

http://dive4elements.wald.intevation.org