Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DistanceInfoService.java @ 1631:26e19cdaed5e
Improved database session handling in services and artifacts.
flys-artifacts/trunk@2807 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 22 Sep 2011 10:07:22 +0000 |
parents | b1ed0ec0236f |
children | e92bc9b0ca1d |
comparison
equal
deleted
inserted
replaced
1630:cafd8af6734a | 1631:26e19cdaed5e |
---|---|
12 import de.intevation.artifacts.GlobalContext; | 12 import de.intevation.artifacts.GlobalContext; |
13 | 13 |
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; | 14 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
15 import de.intevation.artifacts.common.utils.XMLUtils; | 15 import de.intevation.artifacts.common.utils.XMLUtils; |
16 | 16 |
17 import de.intevation.artifactdatabase.DefaultService; | |
18 | |
19 import de.intevation.flys.backend.SessionHolder; | |
20 import de.intevation.flys.model.Annotation; | 17 import de.intevation.flys.model.Annotation; |
21 import de.intevation.flys.model.Attribute; | 18 import de.intevation.flys.model.Attribute; |
22 import de.intevation.flys.model.Position; | 19 import de.intevation.flys.model.Position; |
23 import de.intevation.flys.model.Range; | 20 import de.intevation.flys.model.Range; |
24 import de.intevation.flys.model.Edge; | 21 import de.intevation.flys.model.Edge; |
25 | 22 |
26 import de.intevation.flys.artifacts.model.AnnotationsFactory; | 23 import de.intevation.flys.artifacts.model.AnnotationsFactory; |
27 | 24 |
28 import org.hibernate.Session; | |
29 | |
30 import de.intevation.flys.artifacts.cache.CacheFactory; | 25 import de.intevation.flys.artifacts.cache.CacheFactory; |
31 | 26 |
32 import net.sf.ehcache.Cache; | 27 import net.sf.ehcache.Cache; |
33 | 28 |
34 /** | 29 /** |
35 * This service provides information about distances of a specified river. | 30 * This service provides information about distances of a specified river. |
36 * | 31 * |
37 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 32 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
38 */ | 33 */ |
39 public class DistanceInfoService extends DefaultService { | 34 public class DistanceInfoService extends FLYSService { |
40 | 35 |
41 private static enum DistanceFilter { | 36 private static enum DistanceFilter { |
42 NONE, LOCATIONS, DISTANCES | 37 NONE, LOCATIONS, DISTANCES |
43 } | 38 } |
44 | 39 |
58 public DistanceInfoService() { | 53 public DistanceInfoService() { |
59 } | 54 } |
60 | 55 |
61 | 56 |
62 @Override | 57 @Override |
63 public Document process( | 58 public Document doProcess( |
64 Document data, | 59 Document data, |
65 GlobalContext globalContext, | 60 GlobalContext globalContext, |
66 CallMeta callMeta | 61 CallMeta callMeta |
67 ) { | 62 ) { |
68 logger.debug("DistanceInfoService.process"); | 63 logger.debug("DistanceInfoService.process"); |
118 | 113 |
119 protected Document getUncached(String river, String filtertype) { | 114 protected Document getUncached(String river, String filtertype) { |
120 | 115 |
121 Document result = XMLUtils.newDocument(); | 116 Document result = XMLUtils.newDocument(); |
122 | 117 |
123 Session session = SessionHolder.acquire(); | 118 Iterator<Annotation> iter = |
124 | 119 AnnotationsFactory.getAnnotationsIterator(river); |
125 try { | 120 |
126 Iterator<Annotation> iter = | 121 Element all = result.createElement("distances"); |
127 AnnotationsFactory.getAnnotationsIterator(river); | 122 |
128 | 123 DistanceFilter filter = getDistanceFilter(filtertype); |
129 Element all = result.createElement("distances"); | 124 |
130 | 125 while (iter.hasNext()) { |
131 DistanceFilter filter = getDistanceFilter(filtertype); | 126 Annotation a = iter.next(); |
132 | 127 Element distance = buildDistanceNode(result, a, filter); |
133 while (iter.hasNext()) { | 128 |
134 Annotation a = iter.next(); | 129 if (distance != null) { |
135 Element distance = buildDistanceNode(result, a, filter); | 130 all.appendChild(distance); |
136 | |
137 if (distance != null) { | |
138 all.appendChild(distance); | |
139 } | |
140 } | 131 } |
141 | 132 } |
142 result.appendChild(all); | 133 |
143 } | 134 result.appendChild(all); |
144 finally { | |
145 session.close(); | |
146 SessionHolder.release(); | |
147 } | |
148 | 135 |
149 return result; | 136 return result; |
150 } | 137 } |
151 | 138 |
152 | 139 |