annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadDataFactory.java @ 8055:cd35b76f1ef8

Sediment load. More off year based calculations.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 18 Jul 2014 13:03:28 +0200
parents c835f3cf098e
children fbe3ba5a480e
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;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
12 import java.util.Iterator;
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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, " +
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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.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
36 "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
37 "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
38 "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
39 "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
40 "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
41 "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
42 "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
43 "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
44 "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
45 "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
46 "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
47 "JOIN measurement_station ms ON slv.measurement_station_id = ms.id " +
8047
c835f3cf098e Sediment load: Added join to fetch measurement station via ranges which know the river. Added a visitor for values, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8039
diff changeset
48 "JOIN ranges rng ON ms.range_id = rng.id " +
c835f3cf098e Sediment load: Added join to fetch measurement station via ranges which know the river. Added a visitor for values, too.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8039
diff changeset
49 "JOIN rivers r ON rng.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)
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 .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
106 .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
107 .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
108 .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
109 .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
110 .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
111 .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
112 .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
113
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 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
115
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 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
117 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
118
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 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
120 = 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
121
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 for (Iterator iter = sqlQuery.iterate(); iter.hasNext();) {
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 Object [] row = (Object [])iter.next();
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 Integer sl_id = (Integer)row[0];
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 String sl_description = (String)row[1];
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 Timestamp ti_start_time = (Timestamp)row[2];
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 Timestamp ti_stop_time = (Timestamp)row[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
129 Double slv_value = (Double)row[4];
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 String gf_name = (String)row[5];
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
131 Integer ms_id = (Integer)row[6];
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
132 Double ms_station = (Double)row[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
133 String ms_type = (String)row[8];
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 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
136 load = new SedimentLoadData.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
137 sl_id, sl_description, ti_start_time, ti_stop_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
138
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 // 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
140 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
141 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
142
8039
3a769d5fb733 Use GF_UNKNOWN constant instead of -1 to identify unknown grain fractions.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 8034
diff changeset
143 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
144 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
145 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
146 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache it. The data structure a way more straight forward. TODO: Implement calculation on this basis.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
147 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 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
150 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
151 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
152 ? 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
153 : 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
154
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 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
156 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
157 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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.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
160 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
161 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
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
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
164 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
165
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 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
167 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 }
5e3f4b4fcb28 New way to loaded sediment loads from database and cache 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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org