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

http://dive4elements.wald.intevation.org