Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
313:89bd0417418f | 314:aeeb9054b7cf |
---|---|
20 import de.intevation.flys.model.Attribute; | 20 import de.intevation.flys.model.Attribute; |
21 import de.intevation.flys.model.Position; | 21 import de.intevation.flys.model.Position; |
22 import de.intevation.flys.model.Range; | 22 import de.intevation.flys.model.Range; |
23 | 23 |
24 import de.intevation.flys.artifacts.model.AnnotationsFactory; | 24 import de.intevation.flys.artifacts.model.AnnotationsFactory; |
25 import de.intevation.flys.artifacts.model.SessionHolder; | |
25 | 26 |
27 import org.hibernate.Session; | |
26 | 28 |
27 /** | 29 /** |
28 * This service provides information about distances of a specified river. | 30 * This service provides information about distances of a specified river. |
29 * | 31 * |
30 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 32 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
64 ElementCreator ec = new ElementCreator( | 66 ElementCreator ec = new ElementCreator( |
65 result, | 67 result, |
66 ArtifactNamespaceContext.NAMESPACE_URI, | 68 ArtifactNamespaceContext.NAMESPACE_URI, |
67 ArtifactNamespaceContext.NAMESPACE_PREFIX); | 69 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
68 | 70 |
69 List<Annotation> annotations = AnnotationsFactory.getAnnotations(river); | 71 Session session = SessionHolder.acquire(); |
72 try { | |
73 List<Annotation> annotations = AnnotationsFactory.getAnnotations(river); | |
70 | 74 |
71 if (annotations == null || annotations.size() == 0) { | 75 if (annotations == null || annotations.size() == 0) { |
72 logger.warn("No information found for the specified river!"); | 76 logger.warn("No information found for the specified river!"); |
73 return result; | 77 return result; |
78 } | |
79 | |
80 Element all = ec.create("distances"); | |
81 | |
82 for (Annotation a: annotations) { | |
83 Element distance = buildDistanceNode(ec, a); | |
84 | |
85 if (distance != null) { | |
86 all.appendChild(distance); | |
87 } | |
88 } | |
89 | |
90 result.appendChild(all); | |
74 } | 91 } |
75 | 92 finally { |
76 Element all = ec.create("distances"); | 93 session.close(); |
77 | 94 SessionHolder.release(); |
78 for (Annotation a: annotations) { | |
79 Element distance = buildDistanceNode(ec, a); | |
80 | |
81 if (distance != null) { | |
82 all.appendChild(distance); | |
83 } | |
84 } | 95 } |
85 | |
86 result.appendChild(all); | |
87 | 96 |
88 return result; | 97 return result; |
89 } | 98 } |
90 | 99 |
91 | 100 |