[PATCH] Use explicit query to avoid hibernate connection leak

Wald Commits scm-commit at wald.intevation.org
Thu Nov 27 20:16:11 CET 2014


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1417115738 -3600
# Node ID 0c22ef71d1540c4d003aac47b422e0610e274146
# Parent  7dd39219bd68f9311c7054c02ca1b90a7367210e
Use explicit query to avoid hibernate connection leak.

diff -r 7dd39219bd68 -r 0c22ef71d154 backend/src/main/java/org/dive4elements/river/model/Gauge.java
--- 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);
     }
 
     /**


More information about the Dive4Elements-commits mailing list