Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
7235:03201eaf594f | 7236:a9bd4a23a852 |
---|---|
42 "sqv.qmax AS qmax " + | 42 "sqv.qmax AS qmax " + |
43 "FROM sq_relation sq " + | 43 "FROM sq_relation sq " + |
44 "JOIN time_intervals ti ON ti.id = sq.time_interval_id " + | 44 "JOIN time_intervals ti ON ti.id = sq.time_interval_id " + |
45 "JOIN rivers r ON r.id = sq.river_id " + | 45 "JOIN rivers r ON r.id = sq.river_id " + |
46 "JOIN sq_relation_value sqv ON sqv.sq_relation_id = sq.id " + | 46 "JOIN sq_relation_value sqv ON sqv.sq_relation_id = sq.id " + |
47 "JOIN measurement_station ms ON sqv.measurement_station_id = ms.id " + | 47 "JOIN measurement_station ms ON sqv.measurement_station_id = ms.id "; |
48 | |
49 public static final String STATION_CLAUSE = | |
48 "WHERE " + | 50 "WHERE " + |
49 "r.name = :river " + | 51 "r.name = :river " + |
50 "AND ms.id = :ms_id "; | 52 "AND ms.id = :ms_id "; |
51 | 53 |
54 public static final String ID_CLAUSE = | |
55 "WHERE " + | |
56 "sqv.id = :dis_id "; | |
52 | 57 |
53 private StaticSQFactory() { | 58 private StaticSQFactory() { |
54 } | 59 } |
55 | 60 |
56 public static StaticSQContainer getSQRelations( | 61 public static StaticSQContainer getSQRelations( |
81 cache.put(element); | 86 cache.put(element); |
82 } | 87 } |
83 return values; | 88 return values; |
84 } | 89 } |
85 | 90 |
91 public static StaticSQContainer getDistinctRelation(int id) { | |
92 Session session = SessionHolder.HOLDER.get(); | |
93 | |
94 Query query = session.createSQLQuery(SQL_SQ + ID_CLAUSE) | |
95 .addScalar("description") | |
96 .addScalar("start_time") | |
97 .addScalar("stop_time") | |
98 .addScalar("station_name") | |
99 .addScalar("station_km") | |
100 .addScalar("measurement_type") | |
101 .addScalar("parameter") | |
102 .addScalar("a") | |
103 .addScalar("b") | |
104 .addScalar("qmax"); | |
105 | |
106 query.setParameter("dis_id", id); | |
107 | |
108 /* This could be done nicer with hibernate */ | |
109 List<Object []> list = query.list(); | |
110 if (list.isEmpty()) { | |
111 log.debug("Query returened nothing"); | |
112 return null; | |
113 } | |
114 Object [] row = list.get(0); | |
115 | |
116 StaticSQContainer sq = new StaticSQContainer(); | |
117 sq.setDescription((String)list.get(0)[0]); | |
118 sq.setStationName((String)list.get(0)[3]); | |
119 sq.setKm(((BigDecimal)list.get(0)[4]).doubleValue()); | |
120 | |
121 StaticSQRelation relation = new StaticSQRelation(); | |
122 relation.setStartTime((Date)row[1]); | |
123 relation.setStopTime((Date)row[2]); | |
124 relation.setType((String)row[5]); | |
125 relation.setParameter((String)row[6]); | |
126 relation.setA(((BigDecimal)row[7]).doubleValue()); | |
127 relation.setB(((BigDecimal)row[8]).doubleValue()); | |
128 relation.setQmax(((BigDecimal)row[9]).doubleValue()); | |
129 sq.addSQRelation(relation); | |
130 | |
131 return sq; | |
132 } | |
133 | |
86 private static StaticSQContainer getUncached( | 134 private static StaticSQContainer getUncached( |
87 String river, | 135 String river, |
88 int measurementStation | 136 int measurementStation |
89 ) { | 137 ) { |
90 Session session = SessionHolder.HOLDER.get(); | 138 Session session = SessionHolder.HOLDER.get(); |
91 | 139 |
92 Query query = session.createSQLQuery(SQL_SQ) | 140 Query query = session.createSQLQuery(SQL_SQ + STATION_CLAUSE) |
93 .addScalar("description") | 141 .addScalar("description") |
94 .addScalar("start_time") | 142 .addScalar("start_time") |
95 .addScalar("stop_time") | 143 .addScalar("stop_time") |
96 .addScalar("station_name") | 144 .addScalar("station_name") |
97 .addScalar("station_km") | 145 .addScalar("station_km") |
105 query.setParameter("ms_id", measurementStation); | 153 query.setParameter("ms_id", measurementStation); |
106 | 154 |
107 List<Object []> list = query.list(); | 155 List<Object []> list = query.list(); |
108 | 156 |
109 if (list.isEmpty()) { | 157 if (list.isEmpty()) { |
158 log.debug("Query returened empty"); | |
110 return new StaticSQContainer(); | 159 return new StaticSQContainer(); |
111 } | 160 } |
112 | 161 |
113 StaticSQContainer sq = new StaticSQContainer(); | 162 StaticSQContainer sq = new StaticSQContainer(); |
114 sq.setDescription((String)list.get(0)[0]); | 163 sq.setDescription((String)list.get(0)[0]); |