Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 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 | 1a00cb4998a8 |
children | 4aa078e28cfd |
line wrap: on
line diff
--- 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; }