Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/RiverService.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 | a63d79107289 |
children | 614ffddb860e |
comparison
equal
deleted
inserted
replaced
1630:cafd8af6734a | 1631:26e19cdaed5e |
---|---|
13 import de.intevation.artifacts.common.ArtifactNamespaceContext; | 13 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
14 import de.intevation.artifacts.common.utils.XMLUtils; | 14 import de.intevation.artifacts.common.utils.XMLUtils; |
15 | 15 |
16 import de.intevation.artifactdatabase.DefaultService; | 16 import de.intevation.artifactdatabase.DefaultService; |
17 | 17 |
18 import de.intevation.flys.backend.SessionHolder; | |
19 import de.intevation.flys.model.River; | 18 import de.intevation.flys.model.River; |
20 | 19 |
21 import de.intevation.flys.artifacts.model.RiverFactory; | 20 import de.intevation.flys.artifacts.model.RiverFactory; |
22 | 21 |
23 import org.hibernate.Session; | |
24 | 22 |
25 /** | 23 /** |
26 * This service provides information about the supported rivers by this | 24 * This service provides information about the supported rivers by this |
27 * application. | 25 * application. |
28 * | 26 * |
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
30 */ | 28 */ |
31 public class RiverService extends DefaultService { | 29 public class RiverService extends FLYSService { |
32 | 30 |
33 /** The logger used in this service.*/ | 31 /** The logger used in this service.*/ |
34 private static Logger logger = Logger.getLogger(RiverService.class); | 32 private static Logger logger = Logger.getLogger(RiverService.class); |
35 | 33 |
36 | 34 |
37 /** | 35 protected Document doProcess( |
38 * The default constructor. | |
39 */ | |
40 public RiverService() { | |
41 } | |
42 | |
43 | |
44 public Document process( | |
45 Document data, | 36 Document data, |
46 GlobalContext globalContext, | 37 GlobalContext globalContext, |
47 CallMeta callMeta | 38 CallMeta callMeta |
48 ) { | 39 ) { |
49 logger.debug("RiverService.process"); | 40 logger.debug("RiverService.process"); |
53 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | 44 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
54 result, | 45 result, |
55 ArtifactNamespaceContext.NAMESPACE_URI, | 46 ArtifactNamespaceContext.NAMESPACE_URI, |
56 ArtifactNamespaceContext.NAMESPACE_PREFIX); | 47 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
57 | 48 |
58 Session session = SessionHolder.acquire(); | 49 List<River> allRivers = RiverFactory.getRivers(); |
59 try { | |
60 List<River> allRivers = RiverFactory.getRivers(); | |
61 | 50 |
62 Element rivers = ec.create("rivers"); | 51 Element rivers = ec.create("rivers"); |
63 | 52 |
64 for (River river: allRivers) { | 53 for (River river: allRivers) { |
65 Element r = ec.create("river"); | 54 Element r = ec.create("river"); |
66 ec.addAttr(r, "name", river.getName(), true); | 55 ec.addAttr(r, "name", river.getName(), true); |
67 | 56 |
68 rivers.appendChild(r); | 57 rivers.appendChild(r); |
69 } | 58 } |
70 | 59 |
71 result.appendChild(rivers); | 60 result.appendChild(rivers); |
72 } | |
73 finally { | |
74 session.close(); | |
75 SessionHolder.release(); | |
76 } | |
77 | 61 |
78 return result; | 62 return result; |
79 } | 63 } |
80 } | 64 } |
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 65 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |