annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java @ 8210:3bb00338228c

(issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
author Andre Heinecke <andre.heinecke@intevation.de>
date Fri, 05 Sep 2014 15:09:44 +0200
parents 42ac86ec19c7
children 204905c16ade
rev   line source
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 /* Copyright (C) 2014 by Bundesanstalt für Gewässerkunde
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2 * Software engineering by Intevation GmbH
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3 *
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
6 * documentation coming with Dive4Elements River for details.
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
7 */
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8 package org.dive4elements.river.artifacts.model.minfo;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10 import java.sql.Timestamp;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 import java.util.HashMap;
8089
7e55790da464 Use list() instead of iterator(). Why does this not work?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8058
diff changeset
12 import java.util.List;
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14 import net.sf.ehcache.Cache;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 import net.sf.ehcache.Element;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 import org.apache.log4j.Logger;
8193
8d447516b7dd Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents: 8097
diff changeset
18 import org.dive4elements.river.artifacts.model.RiverFactory;
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19 import org.dive4elements.river.artifacts.cache.CacheFactory;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20 import org.dive4elements.river.backend.SessionHolder;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21 import org.hibernate.SQLQuery;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22 import org.hibernate.Session;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23 import org.hibernate.type.StandardBasicTypes;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 public class SedimentLoadDataFactory
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26 {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 private static Logger log = Logger.getLogger(SedimentLoadDataFactory.class);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29 public static final String CACHE_NAME = "sediment-load-data";
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 public static final String SUSPENDED_STRING = "Schwebstoff";
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33 public static final String SQL_LOAD_RIVER_SEDIMENT_LOADS =
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
34 "SELECT " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 "sl.id AS sl_id, " +
8058
fbe3ba5a480e Sediment load: Fetch kind of sediment load from database to tell if it is official or not.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8055
diff changeset
36 "sl.kind AS sl_kind, " +
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 "sl.description AS sl_description, " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38 "ti.start_time AS ti_start_time, " +
8097
6f3cf934ae99 Fix ti_stop_time naming
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8089
diff changeset
39 "ti.stop_time AS ti_stop_time, " +
8199
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
40 "sqti.start_time AS sq_start_time, " +
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
41 "sqti.stop_time AS sq_stop_time, " +
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
42 "sqti.id AS sq_ti_id, " +
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 "slv.value AS slv_value, " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
44 "gf.name AS gf_name, " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
45 "ms.id AS ms_id, " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46 "ms.station AS ms_station, " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
47 "ms.measurement_type AS ms_type " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
48 "FROM sediment_load_values slv " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
49 "JOIN sediment_load sl ON slv.sediment_load_id = sl.id " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 "JOIN time_intervals ti ON sl.time_interval_id = ti.id " +
8210
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
51 "LEFT JOIN time_intervals sqti ON sl.sq_time_interval_id = sqti.id " +
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 "JOIN grain_fraction gf ON sl.grain_fraction_id = gf.id " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
53 "JOIN measurement_station ms ON slv.measurement_station_id = ms.id " +
8058
fbe3ba5a480e Sediment load: Fetch kind of sediment load from database to tell if it is official or not.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8055
diff changeset
54 "JOIN rivers r ON ms.river_id = r.id " +
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
55 "WHERE r.name = :river " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
56 "ORDER BY sl.id";
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
57
8055
cd35b76f1ef8 Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8047
diff changeset
58 public static final SedimentLoadDataFactory INSTANCE =
cd35b76f1ef8 Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8047
diff changeset
59 new SedimentLoadDataFactory();
cd35b76f1ef8 Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8047
diff changeset
60
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
61 private SedimentLoadDataFactory() {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
62 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
63
8055
cd35b76f1ef8 Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8047
diff changeset
64 public synchronized SedimentLoadData getSedimentLoadData(String river) {
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
65 boolean debug = log.isDebugEnabled();
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
66
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
67 if (debug) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
68 log.debug(
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
69 "Looking for sediment load data for river '" + river + "'");
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
70 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
71
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
72 Cache cache = CacheFactory.getCache(CACHE_NAME);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
73
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
74 if (cache == null) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
75 if (debug) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
76 log.debug("Cache not configured.");
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
77 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
78 return getUncached(river);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
79 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
80
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
81 String key = "sediment-load-" + river;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
82
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
83 Element element = cache.get(key);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
84
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
85 if (element != null) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
86 if (debug) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
87 log.debug("Sediment load data found in cache");
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
88 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
89 return (SedimentLoadData)element.getValue();
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
90 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
91
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
92 SedimentLoadData sedimentLoad = getUncached(river);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
93
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
94 if (sedimentLoad != null) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
95 if (debug) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
96 log.debug("Store sediment load data in cache.");
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
97 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
98 cache.put(new Element(key, sedimentLoad));
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
99 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
100
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
101 return sedimentLoad;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
102 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
103
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
104 public SedimentLoadData getUncached(String river) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
105
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
106 Session session = SessionHolder.HOLDER.get();
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
107
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
108 SQLQuery sqlQuery = session.createSQLQuery(SQL_LOAD_RIVER_SEDIMENT_LOADS)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
109 .addScalar("sl_id", StandardBasicTypes.INTEGER)
8058
fbe3ba5a480e Sediment load: Fetch kind of sediment load from database to tell if it is official or not.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8055
diff changeset
110 .addScalar("sl_kind", StandardBasicTypes.INTEGER)
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
111 .addScalar("sl_description", StandardBasicTypes.STRING)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
112 .addScalar("ti_start_time", StandardBasicTypes.TIMESTAMP)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
113 .addScalar("ti_stop_time", StandardBasicTypes.TIMESTAMP)
8199
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
114 .addScalar("sq_start_time", StandardBasicTypes.TIMESTAMP)
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
115 .addScalar("sq_stop_time", StandardBasicTypes.TIMESTAMP)
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
116 .addScalar("sq_ti_id", StandardBasicTypes.INTEGER)
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
117 .addScalar("slv_value", StandardBasicTypes.DOUBLE)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
118 .addScalar("gf_name", StandardBasicTypes.STRING)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
119 .addScalar("ms_id", StandardBasicTypes.INTEGER)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
120 .addScalar("ms_station", StandardBasicTypes.DOUBLE)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
121 .addScalar("ms_type", StandardBasicTypes.STRING);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
122
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
123 sqlQuery.setString("river", river);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
124
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
125 SedimentLoadData.Load load = null;
8039
3a769d5fb733 Use GF_UNKNOWN constant instead of -1 to identify unknown grain fractions.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8034
diff changeset
126 int grainFractionIndex = SedimentLoadData.GF_UNKNOWN;
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
127
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
128 HashMap<Integer, SedimentLoadData.Station> id2station
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
129 = new HashMap<Integer, SedimentLoadData.Station>();
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
130
8089
7e55790da464 Use list() instead of iterator(). Why does this not work?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8058
diff changeset
131 List<Object[]> list = sqlQuery.list();
7e55790da464 Use list() instead of iterator(). Why does this not work?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8058
diff changeset
132
7e55790da464 Use list() instead of iterator(). Why does this not work?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8058
diff changeset
133 for (Object [] row: list) {
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
134
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
135 Integer sl_id = (Integer)row[0];
8058
fbe3ba5a480e Sediment load: Fetch kind of sediment load from database to tell if it is official or not.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8055
diff changeset
136 Integer sl_kind = (Integer)row[1];
fbe3ba5a480e Sediment load: Fetch kind of sediment load from database to tell if it is official or not.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8055
diff changeset
137 String sl_description = (String)row[2];
fbe3ba5a480e Sediment load: Fetch kind of sediment load from database to tell if it is official or not.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8055
diff changeset
138 Timestamp ti_start_time = (Timestamp)row[3];
fbe3ba5a480e Sediment load: Fetch kind of sediment load from database to tell if it is official or not.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8055
diff changeset
139 Timestamp ti_stop_time = (Timestamp)row[4];
8199
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
140 Timestamp sq_start_time = (Timestamp)row[5];
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
141 Timestamp sq_stop_time = (Timestamp)row[6];
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
142 Integer sq_id = (Integer)row[7];
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
143 Double slv_value = (Double)row[8];
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
144 String gf_name = (String)row[9];
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
145 Integer ms_id = (Integer)row[10];
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
146 Double ms_station = (Double)row[11];
42ac86ec19c7 (issue1448) Add sq time intervals to sediment load data model.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8193
diff changeset
147 String ms_type = (String)row[12];
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
148
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
149 if (load == null || load.getId() != sl_id) {
8210
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
150 if (sq_id == null) {
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
151 /* Avoid NPE when converting the objects. */
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
152 load = new SedimentLoadData.Load(
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
153 sl_id, sl_kind, sl_description,
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
154 ti_start_time, ti_stop_time);
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
155 } else {
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
156 load = new SedimentLoadData.Load(
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
157 sl_id, sl_kind, sl_description,
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
158 ti_start_time, ti_stop_time, sq_id,
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
159 sq_start_time, sq_stop_time);
3bb00338228c (issue1448) Use left join to permit loads with empty sq_time intervals to be handled.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8199
diff changeset
160 }
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
161
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
162 // Grain fractions only change when a new sediment load starts.
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
163 grainFractionIndex =
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
164 SedimentLoadData.grainFractionIndex(gf_name);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
165
8039
3a769d5fb733 Use GF_UNKNOWN constant instead of -1 to identify unknown grain fractions.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8034
diff changeset
166 if (grainFractionIndex == SedimentLoadData.GF_UNKNOWN) {
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
167 log.error("Unknown grain fraction type: " + gf_name);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
168 break;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
169 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
170 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
171
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
172 SedimentLoadData.Station station = id2station.get(ms_id);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
173 if (station == null) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
174 int type = ms_type.equalsIgnoreCase(SUSPENDED_STRING)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
175 ? SedimentLoadData.Station.SUSPENDED
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
176 : SedimentLoadData.Station.BED_LOAD;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
177
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
178 station = new SedimentLoadData.Station(type, ms_station);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
179 id2station.put(ms_id, station);
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
180 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
181
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
182 station.addValue(
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
183 grainFractionIndex,
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
184 new SedimentLoadData.Value(load, slv_value));
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
185 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
186
8193
8d447516b7dd Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents: 8097
diff changeset
187 SedimentLoadData sld = new SedimentLoadData(id2station.values(),
8d447516b7dd Sum up fractions from stations and previous stations according to respective validity model.
Tom Gottfried <tom@intevation.de>
parents: 8097
diff changeset
188 RiverFactory.getRiver(river).getKmUp());
8033
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
189
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
190 return sld;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
191 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
192 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
193 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org