annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java @ 8089:7e55790da464

Use list() instead of iterator(). Why does this not work?
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 15 Aug 2014 18:01:06 +0200
parents fbe3ba5a480e
children 6f3cf934ae99
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;
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
18 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
19 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
20 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
21 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
22 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
23
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 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
25 {
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 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
27
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 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
29
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 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
31
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 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
33 "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
34 "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
35 "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
36 "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
37 "ti.start_time AS ti_start_time, " +
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.stop_time AS ti_stoptime, " +
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
39 "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
40 "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
41 "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
42 "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
43 "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
44 "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
45 "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
46 "JOIN time_intervals ti ON sl.time_interval_id = ti.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
47 "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
48 "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
49 "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
50 "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
51 "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
52
8055
cd35b76f1ef8 Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8047
diff changeset
53 public static final SedimentLoadDataFactory INSTANCE =
cd35b76f1ef8 Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8047
diff changeset
54 new SedimentLoadDataFactory();
cd35b76f1ef8 Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8047
diff changeset
55
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
56 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
57 }
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
58
8055
cd35b76f1ef8 Sediment load. More off year based calculations.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8047
diff changeset
59 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
60 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
61
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 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
63 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
64 "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
65 }
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 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
68
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 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
70 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
71 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
72 }
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 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
74 }
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
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 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
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 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
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 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
81 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
82 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
83 }
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 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
85 }
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
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 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
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 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
90 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
91 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
92 }
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 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
94 }
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
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 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
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
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 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
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 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
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 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
104 .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
105 .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
106 .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
107 .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
108 .addScalar("ti_stop_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
109 .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
110 .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
111 .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
112 .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
113 .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
114
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
115 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
116
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 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
118 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
119
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 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
121 = 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
122
8089
7e55790da464 Use list() instead of iterator(). Why does this not work?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8058
diff changeset
123 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
124
7e55790da464 Use list() instead of iterator(). Why does this not work?
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8058
diff changeset
125 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
126
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 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
128 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
129 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
130 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
131 Timestamp ti_stop_time = (Timestamp)row[4];
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
132 Double slv_value = (Double)row[5];
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
133 String gf_name = (String)row[6];
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
134 Integer ms_id = (Integer)row[7];
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
135 Double ms_station = (Double)row[8];
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 String ms_type = (String)row[9];
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
137
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
138 if (load == null || load.getId() != 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
139 load = new SedimentLoadData.Load(
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
140 sl_id, sl_kind, sl_description,
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
141 ti_start_time, ti_stop_time);
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
142
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
143 // 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
144 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
145 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
146
8039
3a769d5fb733 Use GF_UNKNOWN constant instead of -1 to identify unknown grain fractions.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8034
diff changeset
147 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
148 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
149 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
150 }
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
151 }
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
152
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
153 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
154 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
155 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
156 ? 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
157 : 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
158
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
159 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
160 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
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
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 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
164 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
165 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
166 }
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
8034
b6e7cfcabf2c Wire the neighbors to the measurement stations together. This eases the lookup for same types (suspended or bed load).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8033
diff changeset
168 SedimentLoadData sld = new SedimentLoadData(id2station.values());
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
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 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
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 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org