Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/GaugeTimerangeState.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | 2966787b5188 |
children | e86cd5176678 |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import java.util.Calendar; | |
4 import java.util.List; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import org.hibernate.Session; | |
9 import org.hibernate.SQLQuery; | |
10 import org.hibernate.type.StandardBasicTypes; | |
11 | |
12 import de.intevation.flys.model.Gauge; | |
13 import de.intevation.flys.backend.SessionHolder; | |
14 | |
15 import de.intevation.flys.artifacts.FLYSArtifact; | |
16 import de.intevation.flys.utils.FLYSUtils; | |
17 | |
18 | |
19 /** | |
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
21 */ | |
22 public class GaugeTimerangeState extends IntRangeState { | |
23 | |
24 private static final Logger logger = | |
25 Logger.getLogger(GaugeTimerangeState.class); | |
26 | |
27 | |
28 protected int[] getLowerUpper(FLYSArtifact flys) { | |
29 Gauge gauge = FLYSUtils.getReferenceGauge(flys); | |
30 | |
31 if (gauge == null) { | |
32 logger.warn("No reference gauge specified!"); | |
33 return new int[] { 0, 0 }; | |
34 } | |
35 | |
36 Session session = SessionHolder.HOLDER.get(); | |
37 | |
38 SQLQuery query = session.createSQLQuery( | |
39 "SELECT min(start_time) as min, max(stop_time) as max " + | |
40 "FROM time_intervals WHERE id in " + | |
41 "(SELECT time_interval_id FROM discharge_tables " + | |
42 "WHERE gauge_id =:gid)"); | |
43 | |
44 query.addScalar("min", StandardBasicTypes.CALENDAR); | |
45 query.addScalar("max", StandardBasicTypes.CALENDAR); | |
46 | |
47 query.setInteger("gid", gauge.getId()); | |
48 | |
49 List results = query.list(); | |
50 | |
51 if (results != null) { | |
52 Object[] res = (Object[]) results.get(0); | |
53 | |
54 Calendar lo = (Calendar) res[0]; | |
55 Calendar up = (Calendar) res[1]; | |
56 | |
57 return new int[] { lo.get(Calendar.YEAR), up.get(Calendar.YEAR) }; | |
58 } | |
59 | |
60 logger.warn("Could not determine time range for gauge: " + gauge); | |
61 | |
62 return null; | |
63 } | |
64 | |
65 | |
66 @Override | |
67 protected Object getLower(FLYSArtifact flys) { | |
68 int[] lowerUpper = getLowerUpper(flys); | |
69 | |
70 return lowerUpper != null ? lowerUpper[0] : 0; | |
71 } | |
72 | |
73 | |
74 @Override | |
75 protected Object getUpper(FLYSArtifact flys) { | |
76 int[] lowerUpper = getLowerUpper(flys); | |
77 | |
78 return lowerUpper != null ? lowerUpper[1] : 0; | |
79 } | |
80 | |
81 | |
82 @Override | |
83 protected String getUIProvider() { | |
84 return "gaugetimerange"; | |
85 } | |
86 } | |
87 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |