Mercurial > dive4elements > river
changeset 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 | 7dd39219bd68 |
children | 2db7a949ff8b |
files | backend/src/main/java/org/dive4elements/river/model/Gauge.java |
diffstat | 1 files changed, 14 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/model/Gauge.java Thu Nov 27 19:55:55 2014 +0100 +++ b/backend/src/main/java/org/dive4elements/river/model/Gauge.java Thu Nov 27 20:15:38 2014 +0100 @@ -178,15 +178,7 @@ public double[] determineMinMaxW() { Session session = SessionHolder.HOLDER.get(); - List<DischargeTable> tables = getDischargeTables(); - DischargeTable dischargeTable = null; - - for (DischargeTable tmp: tables) { - if (tmp.getKind() == 0) { - dischargeTable = tmp; - break; - } - } + DischargeTable dischargeTable = fetchMasterDischargeTable(); if (dischargeTable == null) { return null; @@ -253,13 +245,20 @@ public DischargeTable fetchMasterDischargeTable() { - for (DischargeTable dt: dischargeTables) { - if (dt.getKind() == MASTER_DISCHARGE_TABLE) { - return dt; - } - } + Session session = SessionHolder.HOLDER.get(); - return null; + Query query = session.createQuery( + "from DischargeTable " + + "where kind = 0 " + + "and gauge = :gauge"); + + query.setParameter("gauge", this); + + List<Object> results = query.list(); + + return results.isEmpty() + ? null + : (DischargeTable)results.get(0); } /**