comparison backend/src/main/java/org/dive4elements/river/model/Gauge.java @ 8482:0c22ef71d154

Use explicit query to avoid hibernate connection leak.
author Tom Gottfried <tom@intevation.de>
date Thu, 27 Nov 2014 20:15:38 +0100
parents a895eb07a7dc
children 5e38e2924c07
comparison
equal deleted inserted replaced
8481:7dd39219bd68 8482:0c22ef71d154
176 * @return the min and max W value of this gauge [min,max]. 176 * @return the min and max W value of this gauge [min,max].
177 */ 177 */
178 public double[] determineMinMaxW() { 178 public double[] determineMinMaxW() {
179 Session session = SessionHolder.HOLDER.get(); 179 Session session = SessionHolder.HOLDER.get();
180 180
181 List<DischargeTable> tables = getDischargeTables(); 181 DischargeTable dischargeTable = fetchMasterDischargeTable();
182 DischargeTable dischargeTable = null;
183
184 for (DischargeTable tmp: tables) {
185 if (tmp.getKind() == 0) {
186 dischargeTable = tmp;
187 break;
188 }
189 }
190 182
191 if (dischargeTable == null) { 183 if (dischargeTable == null) {
192 return null; 184 return null;
193 } 185 }
194 186
251 return results.isEmpty() ? null : results.get(0); 243 return results.isEmpty() ? null : results.get(0);
252 } 244 }
253 245
254 246
255 public DischargeTable fetchMasterDischargeTable() { 247 public DischargeTable fetchMasterDischargeTable() {
256 for (DischargeTable dt: dischargeTables) { 248 Session session = SessionHolder.HOLDER.get();
257 if (dt.getKind() == MASTER_DISCHARGE_TABLE) { 249
258 return dt; 250 Query query = session.createQuery(
259 } 251 "from DischargeTable " +
260 } 252 "where kind = 0 " +
261 253 "and gauge = :gauge");
262 return null; 254
255 query.setParameter("gauge", this);
256
257 List<Object> results = query.list();
258
259 return results.isEmpty()
260 ? null
261 : (DischargeTable)results.get(0);
263 } 262 }
264 263
265 /** 264 /**
266 * Returns an array of [days, qs] necessary to create duration curves. 265 * Returns an array of [days, qs] necessary to create duration curves.
267 * 266 *

http://dive4elements.wald.intevation.org