Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKmsFactory.java @ 9801:1d7a72a50183 3.2.x tip
Assume Compose V2, consistently
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 23 Nov 2023 10:14:13 +0100 |
parents | 0a5239a1e46e |
children |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
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 |
9726 | 16 import org.apache.logging.log4j.Logger; |
17 import org.apache.logging.log4j.LogManager; | |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
18 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 import org.hibernate.Session; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
20 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 import org.hibernate.SQLQuery; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
22 import org.hibernate.type.StandardBasicTypes; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5728
diff
changeset
|
24 import org.dive4elements.river.artifacts.cache.CacheFactory; |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5728
diff
changeset
|
26 import org.dive4elements.river.backend.SessionHolder; |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
27 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
28 /** |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1886
diff
changeset
|
29 * 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
|
30 * WST-data. |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 */ |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 public class WQKmsFactory |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 { |
9726 | 34 private static Logger log = LogManager.getLogger(WQKmsFactory.class); |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
36 /** Query to get km and wqs for wst_id and column_pos. */ |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
37 public static final String SQL_SELECT_WQS = |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
38 "SELECT position, w, q FROM wst_value_table " + |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
39 "WHERE wst_id = :wst_id AND column_pos = :column_pos"; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 |
5726
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
41 /** Get wst_id and position from wst_columns. */ |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
42 public static final String 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
|
43 "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
|
44 |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
45 /** Query to get name for wst_id and column_pos. */ |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
46 public static final String SQL_SELECT_NAME = |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
47 "SELECT name " + |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
48 "FROM wst_columns "+ |
5727
26dcd924befc
WQKmsFactory: Fix name sql.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5726
diff
changeset
|
49 "WHERE id = :column_id"; |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
50 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
51 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
52 /** Hidden constructor, use static methods instead. */ |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
53 private WQKmsFactory() { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
54 } |
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 /** |
5727
26dcd924befc
WQKmsFactory: Fix name sql.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5726
diff
changeset
|
58 * 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
|
59 */ |
5728
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
60 public static WQKms getWQKms(int columnPos, int wst_id) { |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
61 log.debug("WQKmsFactory.getWQKms"); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
62 Cache cache = CacheFactory.getCache(StaticWQKmsCacheKey.CACHE_NAME); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
63 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
64 StaticWQKmsCacheKey cacheKey; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
65 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
66 if (cache != 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
|
67 cacheKey = new StaticWQKmsCacheKey(wst_id, columnPos); |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
68 Element element = cache.get(cacheKey); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
69 if (element != null) { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
70 log.debug("Got static wst values from cache"); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
71 return (WQKms)element.getValue(); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
72 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
73 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
74 else { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
75 cacheKey = null; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
76 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
77 |
5728
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
78 WQKms values = getWQKmsUncached(columnPos, wst_id); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
79 |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
80 if (values != null && 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
|
81 log.debug("Store static wst values in cache."); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
82 Element element = new Element(cacheKey, values); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
83 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
|
84 } |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
85 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
|
86 } |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
87 |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
88 /** |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
89 * 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
|
90 */ |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
95 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
|
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 if (cache != null) { |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
98 cacheKey = new StaticWQKmsCacheKey(-columnID, -columnID); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 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
|
103 } |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
104 } |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
105 else { |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
106 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
|
107 } |
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 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
|
110 if (cInfo == null) return null; |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
111 WQKms values = getWQKmsUncached(cInfo[1], cInfo[0]); |
c08f691652cf
WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5727
diff
changeset
|
112 |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
113 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
114 if (values != null && cacheKey != null) { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
115 log.debug("Store static wst values in cache."); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
116 Element element = new Element(cacheKey, values); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
117 cache.put(element); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
118 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
119 return values; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
120 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
121 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
122 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
123 /** |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
124 * Get WQKms from db. |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
125 * @param column the position columns value |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
126 * @param wst_id database id of the wst |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
127 * @return respective WQKms. |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
128 */ |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
129 public static WQKms getWQKmsUncached(int column, int wst_id) { |
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 if (log.isDebugEnabled()) { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
132 log.debug("WQKmsFactory.getWQKmsUncached, column " |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
133 + column + ", wst_id " + wst_id); |
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 WQKms wqkms = new WQKms(WKmsFactory.getWKmsName(column, wst_id)); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
137 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
138 Session session = SessionHolder.HOLDER.get(); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
139 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WQS) |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
140 .addScalar("position", StandardBasicTypes.DOUBLE) |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
141 .addScalar("w", StandardBasicTypes.DOUBLE) |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
142 .addScalar("q", StandardBasicTypes.DOUBLE); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
143 sqlQuery.setInteger("wst_id", wst_id); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
144 sqlQuery.setInteger("column_pos", column); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
145 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
146 List<Object []> results = sqlQuery.list(); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
147 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
148 for (int i = 0, N = results.size(); i < N; i++) { |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
149 Object[] row = results.get(i); |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
150 // add(w, q, km) |
8856 | 151 if (row == null |
152 || row[0] == null | |
153 || row[1] == null | |
154 || row[2] == null | |
155 ) { | |
6001
bd6d7da9c6fd
WQKmsFactory: prevent NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
156 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
|
157 continue; |
6001
bd6d7da9c6fd
WQKmsFactory: prevent NPE.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5994
diff
changeset
|
158 } |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
159 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
|
160 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
161 |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
162 return wqkms; |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
163 } |
5726
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
164 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
165 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
166 /** |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
167 * 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
|
168 * @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
|
169 * @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
|
170 * @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
|
171 */ |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
172 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
|
173 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
174 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
|
175 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
|
176 + columnID); |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
177 } |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
178 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
179 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
|
180 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
181 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
|
182 .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
|
183 .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
|
184 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
|
185 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
186 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
|
187 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
188 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
|
189 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
|
190 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
|
191 } |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
192 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
193 return null; |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
194 } |
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 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
197 /** 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
|
198 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
|
199 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
|
200 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
201 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
|
202 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
|
203 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
204 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
|
205 .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
|
206 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
|
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<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
|
209 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
|
210 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
|
211 } |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
212 |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
213 return name; |
17eba7d251b2
WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4051
diff
changeset
|
214 } |
1825
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
215 } |
02cd002205a3
Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
216 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |