Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/minfo/FlowVelocityMeasurementFactory.java @ 4463:3395f8c6b030
FlowVelocityMeasurementFactory: New, do the query to fetch measured flow velocities.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 09 Nov 2012 10:25:41 +0100 |
parents | |
children | 4e4226d99b49 |
comparison
equal
deleted
inserted
replaced
4462:ab7cf7789daf | 4463:3395f8c6b030 |
---|---|
1 package de.intevation.flys.artifacts.model.minfo; | |
2 | |
3 import gnu.trove.TDoubleArrayList; | |
4 | |
5 import java.util.Calendar; | |
6 import java.util.Date; | |
7 import java.util.List; | |
8 | |
9 import net.sf.ehcache.Cache; | |
10 import net.sf.ehcache.Element; | |
11 | |
12 import org.apache.log4j.Logger; | |
13 import org.hibernate.SQLQuery; | |
14 import org.hibernate.Session; | |
15 import org.hibernate.type.StandardBasicTypes; | |
16 | |
17 import de.intevation.flys.artifacts.cache.CacheFactory; | |
18 import de.intevation.flys.model.FlowVelocityMeasurement; | |
19 import de.intevation.flys.model.FlowVelocityMeasurementValue; | |
20 import de.intevation.flys.backend.SessionHolder; | |
21 | |
22 | |
23 public class FlowVelocityMeasurementFactory | |
24 { | |
25 /** Private logger to use here. */ | |
26 private static Logger log = Logger.getLogger(FlowVelocityMeasurementFactory.class); | |
27 | |
28 /** Query to get description and start year, given name and a km range. */ | |
29 public static final String SQL_SELECT_ONE = | |
30 "SELECT station, datetime, w, q, v, description " + | |
31 " FROM flow_velocity_measure_values" + | |
32 " WHERE id = :id"; | |
33 | |
34 | |
35 private FlowVelocityMeasurementFactory() { | |
36 } | |
37 | |
38 | |
39 public static FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue | |
40 getFlowVelocityMeasurement(int id) | |
41 { | |
42 log.debug("FlowVelocityMeasurementFactory.getFlowVelocityMeasurementValue"); | |
43 Session session = SessionHolder.HOLDER.get(); | |
44 SQLQuery sqlQuery = null; | |
45 sqlQuery = session.createSQLQuery(SQL_SELECT_ONE); | |
46 sqlQuery.setParameter("id", id); | |
47 | |
48 List<Object []> results = sqlQuery.list(); | |
49 if (results.size() > 0) { | |
50 Object[] row = results.get(0); | |
51 if (row == null || row.length < 6) { | |
52 return null; | |
53 } | |
54 return FlowVelocityMeasurementValue.getUnmapped( | |
55 Double.parseDouble(row[0].toString()), | |
56 Double.parseDouble(row[2].toString()), | |
57 Double.valueOf(row[3].toString()), | |
58 Double.valueOf(row[4].toString()), null, row[5].toString()); | |
59 } | |
60 return null; | |
61 } | |
62 } | |
63 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |