annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/sq/StaticSQFactory.java @ 9801:1d7a72a50183 3.2.x tip

Assume Compose V2, consistently
author Tom Gottfried <tom@intevation.de>
date Thu, 23 Nov 2023 10:14:13 +0100
parents 0a5239a1e46e
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5500
diff changeset
9 package org.dive4elements.river.artifacts.model.sq;
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
10
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
11 import java.math.BigDecimal;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 import java.util.Date;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 import java.util.List;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
15 import net.sf.ehcache.Cache;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
16 import net.sf.ehcache.Element;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
17
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8694
diff changeset
18 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8694
diff changeset
19 import org.apache.logging.log4j.LogManager;
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
20 import org.hibernate.Query;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21 import org.hibernate.Session;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5500
diff changeset
23 import org.dive4elements.river.artifacts.cache.CacheFactory;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5500
diff changeset
24 import org.dive4elements.river.backend.SessionHolder;
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
25 import org.dive4elements.river.model.MeasurementStation;
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
27
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
28 public class StaticSQFactory
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
29 {
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
30 private static final Logger log =
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8694
diff changeset
31 LogManager.getLogger(StaticSQFactory.class);
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
33 public static final String SQL_SQ =
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
34 "SELECT " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
35 "sq.description AS description,"+
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
36 "ti.start_time AS start_time," +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
37 "ti.stop_time AS stop_time, " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
38 "ms.name AS station_name, " +
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 7236
diff changeset
39 "CASE WHEN r.km_up = 1 AND ra.b IS NOT NULL " +
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 7236
diff changeset
40 "THEN ra.b " +
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 7236
diff changeset
41 "ELSE ra.a " +
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 7236
diff changeset
42 "END AS station_km, " +
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
43 "ms.measurement_type AS measurement_type, " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
44 "sqv.parameter AS parameter, " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
45 "sqv.a AS a, " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
46 "sqv.b AS b, " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
47 "sqv.qmax AS qmax " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
48 "FROM sq_relation sq " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
49 "JOIN time_intervals ti ON ti.id = sq.time_interval_id " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
50 "JOIN sq_relation_value sqv ON sqv.sq_relation_id = sq.id " +
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 7236
diff changeset
51 "JOIN measurement_station ms " +
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 7236
diff changeset
52 "ON sqv.measurement_station_id = ms.id " +
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 7236
diff changeset
53 "JOIN ranges ra ON ra.id = ms.range_id " +
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 7236
diff changeset
54 "JOIN rivers r ON r.id = ra.river_id ";
7236
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
55
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
56 public static final String STATION_CLAUSE =
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 "WHERE " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58 "r.name = :river " +
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
59 "AND ms.id = :ms_id ";
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
60
7236
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
61 public static final String ID_CLAUSE =
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
62 "WHERE " +
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
63 "sqv.id = :dis_id ";
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
64
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
65 private StaticSQFactory() {
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
66 }
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
67
8543
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
68 /** Get SQ relations for a measurement station's location.
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
69 * Returns all SQRelations for the location of the station and
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
70 * not just for the station. E.g. for a "Geschiebemessstelle"
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
71 * and a "Schwebstoffmesstelle" at the same place.*/
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
72 public static StaticSQContainer getSQRelationsForLocation(
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
73 String river,
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
74 int mStationId
8543
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
75 ) {
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
76 Session session = SessionHolder.HOLDER.get();
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
77 Query query = session.createQuery(
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
78 "from MeasurementStation " +
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
79 "where id=:ms_id")
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
80 .setParameter("ms_id", mStationId);
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
81 MeasurementStation mStation = (MeasurementStation)query.list().get(0);
8543
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
82
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
83 /* Take the first container for the station requested. */
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
84 StaticSQContainer retval = getSQRelations(river, mStationId);
8545
c6723e5b6857 (issue1750) It is an error if there are more then two stations at the same range.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8543
diff changeset
85
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
86 /* And it's companion station */
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
87 MeasurementStation companion = mStation.findCompanionStation();
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
88 if (companion != null) {
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
89 int stationId = companion.getId();
8543
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
90 StaticSQContainer additional = getSQRelations(river, stationId);
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
91 if (additional == null || additional.getSQRelations() == null) {
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
92 /* New one is empty, just take the old one. */
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
93 return retval;
8543
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
94 }
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
95 if (retval == null ||
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
96 retval.getSQRelations() == null ||
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
97 retval.getSQRelations().isEmpty()) {
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
98 /* Old one is empty, just take the new one. */
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
99 return additional;
8543
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
100 }
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
101 for (StaticSQRelation add: additional.getSQRelations()) {
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
102 /* Add SQ relations from new one to old one */
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
103 retval.addSQRelation(add);
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
104 }
8543
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
105 }
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
106 return retval;
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
107 }
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
108
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
109
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 public static StaticSQContainer getSQRelations(
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 String river,
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
112 int mStationId
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 ) {
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 Cache cache = CacheFactory.getCache(StaticSQCacheKey.CACHE_NAME);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
115
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 StaticSQCacheKey cacheKey;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 if (cache != null) {
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
119 cacheKey = new StaticSQCacheKey(river, mStationId);
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
120 Element element = cache.get(cacheKey);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 if (element != null) {
8543
9a5b3079aad4 (issue1750) Take Static SQ Relations based on a range and merge them together
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8412
diff changeset
122 log.debug("Got static sq relations from cache");
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
123 return (StaticSQContainer)element.getValue();
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
124 }
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
125 }
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
126 else {
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
127 cacheKey = null;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
128 }
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
129
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
130 StaticSQContainer values = getUncached(river, mStationId);
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
131
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
132 if (values != null && cacheKey != null) {
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
133 log.debug("Store static sq relations in cache.");
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
134 Element element = new Element(cacheKey, values);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
135 cache.put(element);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
136 }
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
137 return values;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
138 }
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
139
7236
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
140 public static StaticSQContainer getDistinctRelation(int id) {
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
141 Session session = SessionHolder.HOLDER.get();
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
142
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
143 Query query = session.createSQLQuery(SQL_SQ + ID_CLAUSE)
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
144 .addScalar("description")
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
145 .addScalar("start_time")
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
146 .addScalar("stop_time")
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
147 .addScalar("station_name")
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
148 .addScalar("station_km")
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
149 .addScalar("measurement_type")
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
150 .addScalar("parameter")
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
151 .addScalar("a")
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
152 .addScalar("b")
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
153 .addScalar("qmax");
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
154
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
155 query.setParameter("dis_id", id);
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
156
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
157 /* This could be done nicer with hibernate */
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
158 List<Object []> list = query.list();
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
159 if (list.isEmpty()) {
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
160 log.debug("Query returened nothing");
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
161 return null;
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
162 }
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
163 Object [] row = list.get(0);
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
164
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
165 StaticSQContainer sq = new StaticSQContainer();
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
166 sq.setDescription((String)list.get(0)[0]);
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
167 sq.setStationName((String)list.get(0)[3]);
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
168 sq.setKm(((BigDecimal)list.get(0)[4]).doubleValue());
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
169
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
170 StaticSQRelation relation = new StaticSQRelation();
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
171 relation.setStartTime((Date)row[1]);
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
172 relation.setStopTime((Date)row[2]);
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
173 relation.setType((String)row[5]);
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
174 relation.setParameter((String)row[6]);
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
175 relation.setA(((BigDecimal)row[7]).doubleValue());
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
176 relation.setB(((BigDecimal)row[8]).doubleValue());
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
177 relation.setQmax(((BigDecimal)row[9]).doubleValue());
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
178 sq.addSQRelation(relation);
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
179
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
180 return sq;
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
181 }
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
182
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
183 private static StaticSQContainer getUncached(
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
184 String river,
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
185 int mStationId
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
186 ) {
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
187 Session session = SessionHolder.HOLDER.get();
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
188
7236
a9bd4a23a852 (issue1474) Add datacage loading for SQ Relations
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
189 Query query = session.createSQLQuery(SQL_SQ + STATION_CLAUSE)
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
190 .addScalar("description")
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
191 .addScalar("start_time")
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
192 .addScalar("stop_time")
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
193 .addScalar("station_name")
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
194 .addScalar("station_km")
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
195 .addScalar("measurement_type")
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
196 .addScalar("parameter")
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
197 .addScalar("a")
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
198 .addScalar("b")
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
199 .addScalar("qmax");
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
200
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
201 query.setParameter("river", river);
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
202 query.setParameter("ms_id", mStationId);
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
203
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
204 List<Object []> list = query.list();
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
205
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
206 if (list.isEmpty()) {
8694
9bb7f19cbb6f (issue1750) Use new MeasuremenStation-methods to find companion station and do less checking for inconsistent data (schema or at least importer do the job now).
Tom Gottfried <tom@intevation.de>
parents: 8605
diff changeset
207 log.debug("Query returned empty");
5500
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
208 return new StaticSQContainer();
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
209 }
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
210
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
211 StaticSQContainer sq = new StaticSQContainer();
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
212 sq.setDescription((String)list.get(0)[0]);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
213 sq.setStationName((String)list.get(0)[3]);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
214 sq.setKm(((BigDecimal)list.get(0)[4]).doubleValue());
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
215
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
216 for (Object[] row : list) {
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
217 StaticSQRelation relation = new StaticSQRelation();
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
218 relation.setStartTime((Date)row[1]);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
219 relation.setStopTime((Date)row[2]);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
220 relation.setType((String)row[5]);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
221 relation.setParameter((String)row[6]);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
222 relation.setA(((BigDecimal)row[7]).doubleValue());
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
223 relation.setB(((BigDecimal)row[8]).doubleValue());
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
224 relation.setQmax(((BigDecimal)row[9]).doubleValue());
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
225 sq.addSQRelation(relation);
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
226 }
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
227 return sq;
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
228 }
700ac898ab0b Added Factory and model for static sq relations.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
229 }

http://dive4elements.wald.intevation.org