annotate artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQKmsFactory.java @ 5863:4897a58c8746

River artifacts: Added new copyright headers.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 28 Apr 2013 14:40:59 +0200
parents 5aa05a7a34b7
children af13ceeba52a
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 *
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
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
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
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. */
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
36 public static final String SQL_SELECT_WQS =
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";
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
39
5726
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
40 /** 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
41 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
42 "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
43
1825
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
44 /** 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
45 public static final String SQL_SELECT_NAME =
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
46 "SELECT name " +
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
47 "FROM wst_columns "+
5727
26dcd924befc WQKmsFactory: Fix name sql.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5726
diff changeset
48 "WHERE id = :column_id";
1825
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
49
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 /** Hidden constructor, use static methods instead. */
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
52 private WQKmsFactory() {
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
53 }
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 /**
5727
26dcd924befc WQKmsFactory: Fix name sql.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5726
diff changeset
57 * 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
58 */
5728
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
59 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
60 log.debug("WQKmsFactory.getWQKms");
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
61 Cache cache = CacheFactory.getCache(StaticWQKmsCacheKey.CACHE_NAME);
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
62
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
63 StaticWQKmsCacheKey cacheKey;
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
64
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
65 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
66 cacheKey = new StaticWQKmsCacheKey(wst_id, columnPos);
1825
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
67 Element element = cache.get(cacheKey);
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
68 if (element != null) {
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
69 log.debug("Got static wst values from cache");
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
70 return (WQKms)element.getValue();
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
71 }
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 else {
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
74 cacheKey = null;
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
75 }
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
76
5728
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
77 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
78
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
79 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
80 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
81 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
82 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
83 }
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
84 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
85 }
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 * 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
89 */
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
90 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
91 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
92 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
93
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
94 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
95
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
96 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
97 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
98 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
99 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
100 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
101 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
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 }
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
104 else {
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
105 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
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
c08f691652cf WQKmsFactory: Add functionality to fetch WQKms if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5727
diff changeset
108 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
109 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
110 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
111
1825
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
112
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
113 if (values != null && cacheKey != null) {
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
114 log.debug("Store static wst values in cache.");
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
115 Element element = new Element(cacheKey, values);
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
116 cache.put(element);
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
117 }
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
118 return values;
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
119 }
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 * Get WQKms from db.
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
124 * @param column the position columns value
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
125 * @param wst_id database id of the wst
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
126 * @return respective WQKms.
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
127 */
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
128 public static WQKms getWQKmsUncached(int column, int wst_id) {
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
129
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
130 if (log.isDebugEnabled()) {
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
131 log.debug("WQKmsFactory.getWQKmsUncached, column "
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
132 + column + ", wst_id " + wst_id);
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 WQKms wqkms = new WQKms(WKmsFactory.getWKmsName(column, wst_id));
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
136
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
137 Session session = SessionHolder.HOLDER.get();
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
138 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WQS)
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
139 .addScalar("position", StandardBasicTypes.DOUBLE)
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
140 .addScalar("w", StandardBasicTypes.DOUBLE)
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
141 .addScalar("q", StandardBasicTypes.DOUBLE);
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
142 sqlQuery.setInteger("wst_id", wst_id);
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
143 sqlQuery.setInteger("column_pos", column);
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
144
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
145 List<Object []> results = sqlQuery.list();
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 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
148 Object[] row = results.get(i);
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
149 // add(w, q, km)
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
150 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
151 }
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
152
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
153 return wqkms;
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
154 }
5726
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
155
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
156
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
157 /**
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
158 * 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
159 * @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
160 * @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
161 * @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
162 */
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
163 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
164
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
165 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
166 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
167 + columnID);
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
168 }
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
169
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
170 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
171
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
172 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
173 .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
174 .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
175 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
176
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
177 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
178
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
179 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
180 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
181 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
182 }
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
183
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
184 return null;
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
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 /** 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
189 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
190 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
191
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
192 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
193 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
194
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
195 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
196 .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
197 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
198
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
199 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
200 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
201 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
202 }
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 return name;
17eba7d251b2 WQKmsFactory: Add name getting function if only column id is known.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4051
diff changeset
205 }
1825
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
206 }
02cd002205a3 Added 'static' wqkms data access.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff changeset
207 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org