changeset 314:aeeb9054b7cf

Acquire/release sessions in services to avoid db connection leaks. flys-artifacts/trunk@1699 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 14 Apr 2011 13:45:50 +0000
parents 89bd0417418f
children 94c176fdcb89
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/RiverService.java
diffstat 3 files changed, 47 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Apr 14 13:36:06 2011 +0000
+++ b/flys-artifacts/ChangeLog	Thu Apr 14 13:45:50 2011 +0000
@@ -1,3 +1,9 @@
+2011-04-14	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* trunk/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java,
+	  trunk/src/main/java/de/intevation/flys/artifacts/services/RiverService.java:
+	  Acquire/release sessions in services to avoid db connection leaks.
+
 2011-04-14  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/states/DefaultState.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java	Thu Apr 14 13:36:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java	Thu Apr 14 13:45:50 2011 +0000
@@ -22,7 +22,9 @@
 import de.intevation.flys.model.Range;
 
 import de.intevation.flys.artifacts.model.AnnotationsFactory;
+import de.intevation.flys.artifacts.model.SessionHolder;
 
+import org.hibernate.Session;
 
 /**
  * This service provides information about distances of a specified river.
@@ -66,24 +68,31 @@
             ArtifactNamespaceContext.NAMESPACE_URI,
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
-        List<Annotation> annotations = AnnotationsFactory.getAnnotations(river);
-
-        if (annotations == null || annotations.size() == 0) {
-            logger.warn("No information found for the specified river!");
-            return result;
-        }
-
-        Element all = ec.create("distances");
+        Session session = SessionHolder.acquire();
+        try {
+            List<Annotation> annotations = AnnotationsFactory.getAnnotations(river);
 
-        for (Annotation a: annotations) {
-            Element distance = buildDistanceNode(ec, a);
+            if (annotations == null || annotations.size() == 0) {
+                logger.warn("No information found for the specified river!");
+                return result;
+            }
 
-            if (distance != null) {
-                all.appendChild(distance);
+            Element all = ec.create("distances");
+
+            for (Annotation a: annotations) {
+                Element distance = buildDistanceNode(ec, a);
+
+                if (distance != null) {
+                    all.appendChild(distance);
+                }
             }
+
+            result.appendChild(all);
         }
-
-        result.appendChild(all);
+        finally {
+            session.close();
+            SessionHolder.release();
+        }
 
         return result;
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/RiverService.java	Thu Apr 14 13:36:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/RiverService.java	Thu Apr 14 13:45:50 2011 +0000
@@ -17,7 +17,9 @@
 import de.intevation.flys.model.River;
 
 import de.intevation.flys.artifacts.model.RiverFactory;
+import de.intevation.flys.artifacts.model.SessionHolder;
 
+import org.hibernate.Session;
 
 /**
  * This service provides information about the supported rivers by this
@@ -52,18 +54,25 @@
             ArtifactNamespaceContext.NAMESPACE_URI,
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
-        List<River> allRivers = RiverFactory.getRivers();
-
-        Element rivers = ec.create("rivers");
+        Session session = SessionHolder.acquire();
+        try {
+            List<River> allRivers = RiverFactory.getRivers();
 
-        for (River river: allRivers) {
-            Element r = ec.create("river");
-            ec.addAttr(r, "name", river.getName(), true);
+            Element rivers = ec.create("rivers");
 
-            rivers.appendChild(r);
+            for (River river: allRivers) {
+                Element r = ec.create("river");
+                ec.addAttr(r, "name", river.getName(), true);
+
+                rivers.appendChild(r);
+            }
+
+            result.appendChild(rivers);
         }
-
-        result.appendChild(rivers);
+        finally {
+            session.close();
+            SessionHolder.release();
+        }
 
         return result;
     }

http://dive4elements.wald.intevation.org