Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/StaticSQFactory.java @ 7236:a9bd4a23a852
(issue1474) Add datacage loading for SQ Relations
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 02 Oct 2013 17:04:23 +0200 |
parents | af13ceeba52a |
children | 17db08570637 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/StaticSQFactory.java Tue Oct 01 17:10:55 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/StaticSQFactory.java Wed Oct 02 17:04:23 2013 +0200 @@ -44,11 +44,16 @@ "JOIN time_intervals ti ON ti.id = sq.time_interval_id " + "JOIN rivers r ON r.id = sq.river_id " + "JOIN sq_relation_value sqv ON sqv.sq_relation_id = sq.id " + - "JOIN measurement_station ms ON sqv.measurement_station_id = ms.id " + + "JOIN measurement_station ms ON sqv.measurement_station_id = ms.id "; + + public static final String STATION_CLAUSE = "WHERE " + "r.name = :river " + "AND ms.id = :ms_id "; + public static final String ID_CLAUSE = + "WHERE " + + "sqv.id = :dis_id "; private StaticSQFactory() { } @@ -83,13 +88,56 @@ return values; } + public static StaticSQContainer getDistinctRelation(int id) { + Session session = SessionHolder.HOLDER.get(); + + Query query = session.createSQLQuery(SQL_SQ + ID_CLAUSE) + .addScalar("description") + .addScalar("start_time") + .addScalar("stop_time") + .addScalar("station_name") + .addScalar("station_km") + .addScalar("measurement_type") + .addScalar("parameter") + .addScalar("a") + .addScalar("b") + .addScalar("qmax"); + + query.setParameter("dis_id", id); + + /* This could be done nicer with hibernate */ + List<Object []> list = query.list(); + if (list.isEmpty()) { + log.debug("Query returened nothing"); + return null; + } + Object [] row = list.get(0); + + StaticSQContainer sq = new StaticSQContainer(); + sq.setDescription((String)list.get(0)[0]); + sq.setStationName((String)list.get(0)[3]); + sq.setKm(((BigDecimal)list.get(0)[4]).doubleValue()); + + StaticSQRelation relation = new StaticSQRelation(); + relation.setStartTime((Date)row[1]); + relation.setStopTime((Date)row[2]); + relation.setType((String)row[5]); + relation.setParameter((String)row[6]); + relation.setA(((BigDecimal)row[7]).doubleValue()); + relation.setB(((BigDecimal)row[8]).doubleValue()); + relation.setQmax(((BigDecimal)row[9]).doubleValue()); + sq.addSQRelation(relation); + + return sq; + } + private static StaticSQContainer getUncached( String river, int measurementStation ) { Session session = SessionHolder.HOLDER.get(); - Query query = session.createSQLQuery(SQL_SQ) + Query query = session.createSQLQuery(SQL_SQ + STATION_CLAUSE) .addScalar("description") .addScalar("start_time") .addScalar("stop_time") @@ -107,6 +155,7 @@ List<Object []> list = query.list(); if (list.isEmpty()) { + log.debug("Query returened empty"); return new StaticSQContainer(); }