Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/MainValuesService.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 | ad54896ec369 |
comparison
equal
deleted
inserted
replaced
1630:cafd8af6734a | 1631:26e19cdaed5e |
---|---|
5 import org.apache.log4j.Logger; | 5 import org.apache.log4j.Logger; |
6 | 6 |
7 import org.w3c.dom.Document; | 7 import org.w3c.dom.Document; |
8 import org.w3c.dom.Element; | 8 import org.w3c.dom.Element; |
9 | 9 |
10 import org.hibernate.Session; | |
11 | |
12 import de.intevation.artifacts.CallMeta; | 10 import de.intevation.artifacts.CallMeta; |
13 import de.intevation.artifacts.GlobalContext; | 11 import de.intevation.artifacts.GlobalContext; |
14 | |
15 import de.intevation.artifactdatabase.DefaultService; | |
16 | 12 |
17 import de.intevation.artifacts.common.ArtifactNamespaceContext; | 13 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
18 import de.intevation.artifacts.common.utils.XMLUtils; | 14 import de.intevation.artifacts.common.utils.XMLUtils; |
19 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | 15 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
20 | 16 |
21 import de.intevation.flys.backend.SessionHolder; | |
22 import de.intevation.flys.model.Gauge; | 17 import de.intevation.flys.model.Gauge; |
23 import de.intevation.flys.model.MainValue; | 18 import de.intevation.flys.model.MainValue; |
24 import de.intevation.flys.model.MainValueType; | 19 import de.intevation.flys.model.MainValueType; |
25 import de.intevation.flys.model.NamedMainValue; | 20 import de.intevation.flys.model.NamedMainValue; |
26 import de.intevation.flys.model.Range; | 21 import de.intevation.flys.model.Range; |
34 * This service returns the main values of a river's gauge based on the start | 29 * This service returns the main values of a river's gauge based on the start |
35 * and end point of the river. | 30 * and end point of the 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 MainValuesService extends DefaultService { | 34 public class MainValuesService extends FLYSService { |
40 | 35 |
41 /** The logger that is used by this service.*/ | 36 /** The logger that is used by this service.*/ |
42 private static Logger logger = Logger.getLogger(MainValuesService.class); | 37 private static Logger logger = Logger.getLogger(MainValuesService.class); |
43 | 38 |
44 | 39 |
57 public MainValuesService() { | 52 public MainValuesService() { |
58 } | 53 } |
59 | 54 |
60 | 55 |
61 @Override | 56 @Override |
62 public Document process( | 57 public Document doProcess( |
63 Document data, | 58 Document data, |
64 GlobalContext context, | 59 GlobalContext context, |
65 CallMeta callMeta | 60 CallMeta callMeta |
66 ) { | 61 ) { |
67 logger.debug("MainValuesService.process"); | 62 logger.debug("MainValuesService.process"); |
169 logger.debug("MainValuesService.buildMainValues"); | 164 logger.debug("MainValuesService.buildMainValues"); |
170 logger.debug("River: " + river.getName()); | 165 logger.debug("River: " + river.getName()); |
171 logger.debug("Gauge: " + gauge.getName()); | 166 logger.debug("Gauge: " + gauge.getName()); |
172 } | 167 } |
173 | 168 |
174 Session session = SessionHolder.acquire(); | 169 List<MainValue> mainValues = MainValuesFactory.getMainValues(gauge); |
175 try { | 170 |
176 List<MainValue> mainValues = MainValuesFactory.getMainValues(gauge); | 171 if (mainValues == null || mainValues.isEmpty()) { |
177 | 172 throw new NullPointerException("No main values found."); |
178 if (mainValues == null || mainValues.isEmpty()) { | 173 } |
179 throw new NullPointerException("No main values found."); | 174 |
180 } | 175 logger.debug(mainValues.size() + " main values found."); |
181 | 176 |
182 logger.debug(mainValues.size() + " main values found."); | 177 return mainValues; |
183 | |
184 return mainValues; | |
185 } | |
186 finally { | |
187 session.close(); | |
188 SessionHolder.release(); | |
189 } | |
190 } | 178 } |
191 | 179 |
192 | 180 |
193 protected Document buildDocument( | 181 protected Document buildDocument( |
194 River river, | 182 River river, |