[PATCH 02 of 19] issue1435: Prepare SedimentDensityFactory to delive data by sedimentdesity.id and .year
Wald Commits
scm-commit at wald.intevation.org
Mon Sep 30 17:30:27 CEST 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1380524930 -7200
# Node ID f707ee04ac8075777383e110c7f0fdd1f62a6478
# Parent 1750b4448c0ceade32ee97ee3e65ac377f37e566
issue1435: Prepare SedimentDensityFactory to delive data by sedimentdesity.id and .year.
diff -r 1750b4448c0c -r f707ee04ac80 artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensityFactory.java
--- 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 :
More information about the Dive4elements-commits
mailing list