Mercurial > dive4elements > river
changeset 7198:f707ee04ac80
issue1435: Prepare SedimentDensityFactory to delive data by sedimentdesity.id and .year.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 30 Sep 2013 09:08:50 +0200 |
parents | 1750b4448c0c |
children | baf04164fcc6 |
files | artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java |
diffstat | 1 files changed, 33 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java Mon Sep 30 07:40:19 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java Mon Sep 30 09:08:50 2013 +0200 @@ -39,6 +39,15 @@ " 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 = + "SELECT sdv.station AS km, " + + " sdv.density AS density," + + " sdv.year AS year " + + " FROM sediment_density sd" + + " JOIN sediment_density_values sdv ON sd.id = sdv.sediment_density_id" + + " WHERE sdv.year = :year AND sd.id = :id"; + private SedimentDensityFactory() {} public static SedimentDensity getSedimentDensity( @@ -96,5 +105,29 @@ density.cleanUp(); return density; } + + public static SedimentDensity getSedimentDensityUncached( + int id, + int year + ) { + log.debug("getSedimentDensityUncached id/year"); + Session session = SessionHolder.HOLDER.get(); + SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_DENSITY) + .addScalar("km", StandardBasicTypes.DOUBLE) + .addScalar("density", StandardBasicTypes.DOUBLE) + .addScalar("year", StandardBasicTypes.INTEGER); + sqlQuery.setInteger("id", id); + sqlQuery.setInteger("year", year); + List<Object[]> results = sqlQuery.list(); + SedimentDensity density = new SedimentDensity(); + for (Object[] row : results) { + if (row[0] != null && row[1] != null && row[2] != null) { + density.addDensity((Double)row[0], (Double)row[1], (Integer)row[2]); + } + } + + density.cleanUp(); + return density; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :