Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKmsFactory.java @ 9214:091fd9676496
Made DateRange class immutable
author | gernotbelger |
---|---|
date | Tue, 03 Jul 2018 14:26:56 +0200 |
parents | 23264d1a528f |
children |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5728
diff
changeset
|
9 package org.dive4elements.river.artifacts.model; |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
10 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 import java.util.List; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
12 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
13 import net.sf.ehcache.Cache; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
14 import net.sf.ehcache.Element; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
16 import org.apache.log4j.Logger; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
17 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
18 import org.hibernate.Session; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
20 import org.hibernate.SQLQuery; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 import org.hibernate.type.StandardBasicTypes; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
22 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5728
diff
changeset
|
23 import org.dive4elements.river.artifacts.cache.CacheFactory; |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5728
diff
changeset
|
25 import org.dive4elements.river.backend.SessionHolder; |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
26 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
27 /** |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1886
diff
changeset
|
28 * Factory to access ready-made WQKms for other (than computed) 'kinds' of |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
29 * WST-data. |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 */ |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 public class WQKmsFactory |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 private static Logger log = Logger.getLogger(WQKmsFactory.class); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 /** Query to get km and wqs for wst_id and column_pos. */ |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
36 private static final String SQL_SELECT_WQS = |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
37 "SELECT position, w, q FROM wst_value_table " + |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
38 "WHERE wst_id = :wst_id AND column_pos = :column_pos"; |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
39 /** Query to get km and wqs for wst_id and column_pos. */ |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
41 private static final String SQL_SELECT_WQS_RANGE = |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
42 "SELECT position, w, q FROM wst_value_table " + |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
43 "WHERE wst_id = :wst_id AND column_pos = :column_pos " + |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
44 "AND position BETWEEN :kmfrom AND :kmto"; |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
45 |
5726
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
46 /** Get wst_id and position from wst_columns. */ |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
47 private static final String SQL_SELECT_COLUMN = |
5726
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
48 "SELECT wst_id, position FROM wst_columns WHERE id = :column_id"; |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
49 |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
50 /** Query to get name for wst_id and column_pos. */ |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
51 private static final String SQL_SELECT_NAME = |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
52 "SELECT name " + |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
53 "FROM wst_columns "+ |
5727
26dcd924befc
WQKmsFactory: Fix name sql.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5726
diff
changeset
|
54 "WHERE id = :column_id"; |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
55 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
56 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
57 /** Hidden constructor, use static methods instead. */ |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
58 private WQKmsFactory() { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
59 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
60 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
61 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
62 /** |
5727
26dcd924befc
WQKmsFactory: Fix name sql.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5726
diff
changeset
|
63 * Get WKms for given column (pos) and wst_id, caring about the cache. |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
64 */ |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
65 public static WQKms getWQKms(final int columnPos, final int wst_id) { |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
66 return getWQKms(columnPos, wst_id, Double.NaN, Double.NaN); |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
67 } |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
68 |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
69 /** |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
70 * Get WKms for given column (pos) and wst_id, caring about the cache. |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
71 */ |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
72 public static WQKms getWQKms(final int columnPos, final int wst_id, final double from, final double to) { |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
73 log.debug("WQKmsFactory.getWQKms"); |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
74 final Cache cache = CacheFactory.getCache(StaticWQKmsCacheKey.CACHE_NAME); |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
75 |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
76 final StaticWQKmsCacheKey cacheKey; |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
77 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
78 if (cache != null) { |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
79 cacheKey = new StaticWQKmsCacheKey(wst_id, columnPos, from, to); |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
80 Element element = cache.get(cacheKey); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
81 if (element != null) { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
82 log.debug("Got static wst values from cache"); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
83 return (WQKms)element.getValue(); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
84 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
85 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
86 else { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
87 cacheKey = null; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
88 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
89 |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
90 final WQKms values = getWQKmsUncached(columnPos, wst_id, from, to); |
5728
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
91 |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
92 if (values != null && cache != null && cacheKey != null) { |
5728
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
93 log.debug("Store static wst values in cache."); |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
94 final Element element = new Element(cacheKey, values); |
5728
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
95 cache.put(element); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
96 } |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
97 return values; |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
98 } |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
99 |
5728
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
100 /** |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
101 * Get WKms for given column (id), caring about the cache. |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
102 */ |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
103 public static WQKms getWQKmsCID(int columnID) { |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
104 log.debug("WQKmsFactory.getWQKms"); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
105 Cache cache = CacheFactory.getCache(StaticWQKmsCacheKey.CACHE_NAME); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
106 |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
107 StaticWQKmsCacheKey cacheKey; |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
108 |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
109 if (cache != null) { |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
110 cacheKey = new StaticWQKmsCacheKey(-columnID, -columnID, Double.NaN, Double.NaN); |
5728
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
111 Element element = cache.get(cacheKey); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
112 if (element != null) { |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
113 log.debug("Got static wst values from cache"); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
114 return (WQKms)element.getValue(); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
115 } |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
116 } |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
117 else { |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
118 cacheKey = null; |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
119 } |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
120 |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
121 int[] cInfo = getColumn(columnID); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
122 if (cInfo == null) return null; |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
123 WQKms values = getWQKmsUncached(cInfo[1], cInfo[0], Double.NaN, Double.NaN); |
5728
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
124 |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
125 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
126 if (values != null && cacheKey != null) { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
127 log.debug("Store static wst values in cache."); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
128 Element element = new Element(cacheKey, values); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
129 cache.put(element); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
130 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
131 return values; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
132 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
133 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
134 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
135 /** |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
136 * Get WQKms from db. |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
137 * @param column the position columns value |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
138 * @param wst_id database id of the wst |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
139 * @return respective WQKms. |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
140 */ |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
141 private static WQKms getWQKmsUncached(final int column, final int wst_id, final double from, final double to) { |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
142 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
143 if (log.isDebugEnabled()) { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
144 log.debug("WQKmsFactory.getWQKmsUncached, column " |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
145 + column + ", wst_id " + wst_id); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
146 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
147 |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
148 final WQKms wqkms = new WQKms(WKmsFactory.getWKmsName(column, wst_id)); |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
149 |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
150 boolean hasRange = !Double.isNaN(from) && !Double.isNaN(to); |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
151 |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
152 final String query = hasRange ? SQL_SELECT_WQS_RANGE : SQL_SELECT_WQS; |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
153 |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
154 final Session session = SessionHolder.HOLDER.get(); |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
155 final SQLQuery sqlQuery = session.createSQLQuery(query) |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
156 .addScalar("position", StandardBasicTypes.DOUBLE) |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
157 .addScalar("w", StandardBasicTypes.DOUBLE) |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
158 .addScalar("q", StandardBasicTypes.DOUBLE); |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
159 |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
160 sqlQuery.setInteger("wst_id", wst_id); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
161 sqlQuery.setInteger("column_pos", column); |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
162 if( hasRange ) |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
163 { |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
164 sqlQuery.setDouble("kmfrom", from); |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
165 sqlQuery.setDouble("kmto", to); |
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
166 } |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
167 |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
168 final List<Object []> results = sqlQuery.list(); |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
169 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
170 for (int i = 0, N = results.size(); i < N; i++) { |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
171 final Object[] row = results.get(i); |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
172 // add(w, q, km) |
8856 | 173 if (row == null |
174 || row[0] == null | |
175 || row[1] == null | |
176 || row[2] == null | |
177 ) { | |
6001
bd6d7da9c6fd
WQKmsFactory: prevent NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
178 log.warn("A value in result for WQKms is null."); |
6002
bcea24d8c2ec
WQKmsFactory: Prevent NPE this time.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
6001
diff
changeset
|
179 continue; |
6001
bd6d7da9c6fd
WQKmsFactory: prevent NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
180 } |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
181 wqkms.add((Double) row[1], (Double) row[2], (Double) row[0]); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
182 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
183 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
184 return wqkms; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
185 } |
5726
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
186 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
187 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
188 /** |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
189 * Get WQKms from db. |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
190 * @param columnID the columns database id value |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
191 * @param wst_id database id of the wst |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
192 * @return respective WQKms. |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
193 */ |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
194 public static int[] getColumn(int columnID) { |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
195 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
196 if (log.isDebugEnabled()) { |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
197 log.debug("WQKmsFactory.getColumn, columnID " |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
198 + columnID); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
199 } |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
200 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
201 Session session = SessionHolder.HOLDER.get(); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
202 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
203 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_COLUMN) |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
204 .addScalar("wst_id", StandardBasicTypes.INTEGER) |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
205 .addScalar("position", StandardBasicTypes.INTEGER); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
206 sqlQuery.setInteger("column_id", columnID); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
207 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
208 List<Object []> results = sqlQuery.list(); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
209 |
8876
23264d1a528f
Allow access to staticwqkms data; also allow to acces by km range
gernotbelger
parents:
8856
diff
changeset
|
210 // FIXME: right? this will always return row[0]! |
5726
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
211 for (int i = 0, N = results.size(); i < N; i++) { |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
212 Object[] row = results.get(i); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
213 return new int[] {(Integer)row[0], (Integer)row[1]}; |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
214 } |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
215 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
216 return null; |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
217 } |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
218 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
219 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
220 /** Get name for a WKms. */ |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
221 public static String getWQKmsName(int columnID) { |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
222 log.debug("WQKmsFactory.getWQKmsName c/" + columnID); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
223 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
224 String name = null; |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
225 Session session = SessionHolder.HOLDER.get(); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
226 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
227 SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME) |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
228 .addScalar("name", StandardBasicTypes.STRING); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
229 nameQuery.setInteger("column_id", columnID); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
230 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
231 List<String> names = nameQuery.list(); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
232 if (names.size() >= 1) { |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
233 name = names.get(0); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
234 } |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
235 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
236 return name; |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
237 } |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
238 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
239 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |