annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java @ 1909:4b64692b2d1e

Added methods to create WstValueTables ('interpolators') for specific columns of wsts. flys-artifacts/trunk@3269 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 16 Nov 2011 14:47:02 +0000
parents 7053e3255ab4
children 1f90fdd4fa04
rev   line source
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
3 import java.util.Arrays;
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
4 import java.util.List;
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.util.ArrayList;
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
6
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
7 import net.sf.ehcache.Cache;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
8 import net.sf.ehcache.Element;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
9
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
10 import de.intevation.flys.artifacts.cache.CacheFactory;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
11
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
12 import de.intevation.flys.backend.SessionHolder;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
13
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
14 import org.apache.log4j.Logger;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
15
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
16 import de.intevation.flys.model.River;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
17 import de.intevation.flys.model.Wst;
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 import org.hibernate.Session;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 import org.hibernate.Query;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 import org.hibernate.SQLQuery;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 import org.hibernate.type.StandardBasicTypes;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
25 /**
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
26 * Creates WstValueTable s from database.
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
27 * WstValueTable s are used to interpolate given w/q/km values.
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
28 */
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public class WstValueTableFactory
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 private static Logger log = Logger.getLogger(WstValueTableFactory.class);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
33 public static final int DEFAULT_KIND = 0;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
34
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 // TODO: put this into a property file
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
36
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
37 public static final String HQL_WST =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
38 "from Wst where river=:river and kind=:kind";
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
39
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
40 public static final String SQL_SELECT_NAMES_POS =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
41 "SELECT position, name FROM wst_columns " +
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
42 "WHERE wst_id = :wst_id ORDER BY position";
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
43
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
44 /** Select Qs for wst (view sorted by column). */
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
45 public static final String SQL_SELECT_QS =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
46 "SELECT column_pos, q, a, b FROM wst_q_values " +
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
47 "WHERE wst_id = :wst_id";
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
48
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
49 // (sorted by km)
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
50 public static final String SQL_SELECT_WS =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
51 "SELECT km, w, column_pos FROM wst_w_values " +
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
52 "WHERE wst_id = :wst_id";
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
54 /** Statement to query qranges of a single column. */
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
55 public static final String SQL_SELECT_QS_AT_COL =
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
56 "SELECT column_pos, q, a, b FROM wst_q_values " +
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
57 "WHERE wst_id = :wst_id AND column_pos = :column_pos";
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
58
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
59 // (sorted by km)
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
60 public static final String SQL_SELECT_WS_AT_COL =
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
61 "SELECT km, w FROM wst_w_values " +
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
62 "WHERE wst_id = :wst_id AND column_pos = :column_pos";
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
63
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
64
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 private WstValueTableFactory() {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
68
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 public static WstValueTable getTable(River river) {
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
70 return getTable(river, DEFAULT_KIND);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
73
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
74 /**
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
75 * Get WstValueTable to interpolate values of a given Wst.
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
76 */
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
77 public static WstValueTable getTable(int wst_id) {
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
78
1898
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
79 Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
80
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
81 WstValueTableCacheKey cacheKey;
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
82
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
83 if (cache != null) {
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
84 // "-1" is the symbolic river-id for "no river, but wst_id".
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
85 cacheKey = new WstValueTableCacheKey(-1, wst_id);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
86 Element element = cache.get(cacheKey);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
87 if (element != null) {
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
88 log.debug("Got specific wst value table from cache");
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
89 return (WstValueTable) element.getValue();
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
90 }
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
91 }
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
92 else {
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
93 cacheKey = null;
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
94 }
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
95
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
96 Session session = SessionHolder.HOLDER.get();
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
97
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
98 // Fetch data for one column only.
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
99
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
100 WstValueTable.Column [] columns = loadColumns(session, wst_id);
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
101 loadQRanges(session, columns, wst_id);
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
102 List<WstValueTable.Row> rows = loadRows(session, wst_id, columns.length);
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
103
1898
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
104 WstValueTable valueTable = new WstValueTable(columns, rows);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
105
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
106 if (valueTable != null && cacheKey != null) {
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
107 log.debug("Store wst value table in cache");
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
108 Element element = new Element(cacheKey, valueTable);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
109 cache.put(element);
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
110 }
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
111
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
112 return valueTable;
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
113 }
1898
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
114
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
115 /**
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
116 * Get Table for a specific column of a wst.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
117 */
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
118 public static WstValueTable getWstColumnTable(int wst_id, int col_pos) {
1898
7053e3255ab4 Employ cache for WstValueTables that have been fetched by wst_id.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1894
diff changeset
119
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
120 /** @TODO cached/uncached */
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
121
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
122 Session session = SessionHolder.HOLDER.get();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
123
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
124 // Fetch data for one column only.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
125
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
126 WstValueTable.Column [] columns = loadColumn(session, wst_id, col_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
127 loadQRanges(session, columns, wst_id, col_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
128 List<WstValueTable.Row> rows = loadRowsOneColumn(session, wst_id, col_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
129
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
130 return new WstValueTable(columns, rows);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
131 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
132
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
133
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
134 /**
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
135 * Get table for first wst of given kind at given river.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
136 */
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 public static WstValueTable getTable(River river, int kind) {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138
632
07640ab913fd First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 626
diff changeset
139 Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140
626
e3ee131d5dd3 Moved WST value table cache key to a separate class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
141 WstValueTableCacheKey cacheKey;
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 if (cache != null) {
626
e3ee131d5dd3 Moved WST value table cache key to a separate class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 458
diff changeset
144 cacheKey = new WstValueTableCacheKey(river.getId(), kind);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 Element element = cache.get(cacheKey);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 if (element != null) {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 log.debug("got wst value table from cache");
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 return (WstValueTable)element.getValue();
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 else {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 cacheKey = null;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 WstValueTable valueTable = getTableUncached(river, kind);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156
632
07640ab913fd First part of storing qs in ranges
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 626
diff changeset
157 if (valueTable != null && cacheKey != null) {
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 log.debug("store wst value table in cache");
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 Element element = new Element(cacheKey, valueTable);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 cache.put(element);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 return valueTable;
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
166 public static WstValueTable getTableUncached(River river) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
167 return getTableUncached(river, DEFAULT_KIND);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
168 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
169
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 public static WstValueTable getTableUncached(River river, int kind) {
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 Session session = SessionHolder.HOLDER.get();
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
174 Wst wst = loadWst(session, river, kind);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
175
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
176 if (wst == null) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
177 return null;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
178 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
179
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
180 WstValueTable.Column [] columns = loadColumns(session, wst);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
181
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
182 loadQRanges(session, columns, wst);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
183
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
184 List<WstValueTable.Row> rows = loadRows(session, wst, columns.length);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
185
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
186 return new WstValueTable(columns, rows);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
187 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
188
1780
b503d92dd709 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 742
diff changeset
189 /**
b503d92dd709 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 742
diff changeset
190 * @param kind Kind of wst.
b503d92dd709 Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 742
diff changeset
191 */
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
192 protected static Wst loadWst(Session session, River river, int kind) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
193 Query query = session.createQuery(HQL_WST);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 query.setParameter("river", river);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 query.setInteger("kind", kind);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 List<Wst> wsts = query.list();
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
199 // TODO Multiple wsts can match, why return just the first one?
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
200 return wsts.isEmpty() ? null : wsts.get(0);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
201 }
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
203
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
204 /**
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
205 * Load rows with a single columns result.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
206 * @param session session to use for querying db.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
207 * @param wst_id id of wst (in db).
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
208 * @param column_pos the column_pos (within the db) of the wst_value_table
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
209 * of which the values shall be fetched.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
210 * @return resultant rows.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
211 */
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
212 protected static List<WstValueTable.Row> loadRowsOneColumn(
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
213 Session session,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
214 int wst_id,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
215 int column_pos
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
216 ) {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
217 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WS_AT_COL)
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
218 .addScalar("km", StandardBasicTypes.DOUBLE)
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
219 .addScalar("w", StandardBasicTypes.DOUBLE);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
220
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
221 sqlQuery.setInteger("wst_id", wst_id);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
222 sqlQuery.setInteger("column_pos", column_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
223
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
224 List<Object []> results = sqlQuery.list();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
225
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
226 double [] ws = null;
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
227
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
228 ArrayList<WstValueTable.Row> rows = new ArrayList<WstValueTable.Row>();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
229
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
230 // Walk over rows.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
231 for (Object [] result: results) {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
232 ws = new double[1];
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
233 WstValueTable.Row row =
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
234 new WstValueTable.Row((Double) result[0], ws);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
235 rows.add(row);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
236
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
237 Double w = (Double) result[1];
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
238 ws[0] = w != null ? w : Double.NaN;
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
239 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
240
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
241 rows.trimToSize();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
242 return rows;
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
243 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
244
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
245 protected static List<WstValueTable.Row> loadRows(
742
c09c9e05ecfa Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 633
diff changeset
246 Session session,
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
247 int wst_id,
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
248 int numColumns
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
249 ) {
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
250 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WS)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
251 .addScalar("km", StandardBasicTypes.DOUBLE)
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
252 .addScalar("w", StandardBasicTypes.DOUBLE)
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
253 .addScalar("column_pos", StandardBasicTypes.INTEGER);
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
254
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
255 sqlQuery.setInteger("wst_id", wst_id);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
256
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
257 List<Object []> results = sqlQuery.list();
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
258
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
259 int lastColumn = Integer.MAX_VALUE;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
260 double [] ws = null;
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
261
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
262 ArrayList<WstValueTable.Row> rows = new ArrayList<WstValueTable.Row>();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
263
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
264 for (Object [] result: results) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
265 int column = (Integer)result[2];
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
266 if (column < lastColumn) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
267 ws = new double[numColumns];
1894
d5e51cc7da23 New method to get interpolator for given wst_ids, also prepopulate arrays with NaNs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1839
diff changeset
268 Arrays.fill(ws, Double.NaN);
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
269 WstValueTable.Row row =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
270 new WstValueTable.Row((Double)result[0], ws);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
271 rows.add(row);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
272 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
273 Double w = (Double)result[1];
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
274 ws[column] = w != null ? w : Double.NaN;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
275 lastColumn = column;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
276 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
277
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
278 rows.trimToSize();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
279 return rows;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
280 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
281
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
282 protected static List<WstValueTable.Row> loadRows(
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
283 Session session,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
284 Wst wst,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
285 int numColumns
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
286 ) {
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
287 return loadRows(session, wst.getId(), numColumns);
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
288 }
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
289
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
290
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
291 protected static WstValueTable.Column [] loadColumn(
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
292 Session session,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
293 int wst_id,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
294 int col_pos
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
295 ) {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
296 return new WstValueTable.Column [] {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
297 new WstValueTable.Column(WKmsFactory.getWKmsName(col_pos, wst_id))};
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
298 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
299
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
300
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
301 /**
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
302 * Get columns from wst-id.
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
303 */
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
304 protected static WstValueTable.Column [] loadColumns(
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
305 Session session,
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
306 int wst_id
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
307 ) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
308 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_NAMES_POS)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
309 .addScalar("position", StandardBasicTypes.INTEGER)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
310 .addScalar("name", StandardBasicTypes.STRING);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
311
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
312 sqlQuery.setInteger("wst_id", wst_id);
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
313
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
314 List<Object []> columnNames = sqlQuery.list();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
315
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
316 WstValueTable.Column [] columns =
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
317 new WstValueTable.Column[columnNames.size()];
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
318
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
319 for (int i = 0; i < columns.length; ++i) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
320 columns[i] = new WstValueTable.Column(
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
321 (String)columnNames.get(i)[1]);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
322 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
323 return columns;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
324 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
325
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
326 /**
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
327 * Get columns from Wst.
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
328 */
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
329 protected static WstValueTable.Column [] loadColumns(
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
330 Session session,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
331 Wst wst
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
332 ) {
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
333 return loadColumns(session, wst.getId());
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
334 }
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
335
1909
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
336
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
337 /**
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
338 * Build a QRange-Tree.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
339 */
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
340 protected static void loadQRanges(
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
341 Session session,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
342 WstValueTable.Column [] columns,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
343 int wst_id,
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
344 int column_pos
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
345 ) {
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
346 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_QS_AT_COL)
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
347 .addScalar("column_pos", StandardBasicTypes.INTEGER) // keep to maintain order.
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
348 .addScalar("q", StandardBasicTypes.DOUBLE)
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
349 .addScalar("a", StandardBasicTypes.DOUBLE)
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
350 .addScalar("b", StandardBasicTypes.DOUBLE);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
351
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
352 sqlQuery.setInteger("wst_id", wst_id);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
353 sqlQuery.setInteger("column_pos", column_pos);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
354
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
355 List<Object []> qRanges = sqlQuery.list();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
356
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
357 int qSize = qRanges.size();
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
358
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
359 QRangeTree qRangeTree = new QRangeTree(qRanges, 0, qSize);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
360 columns[0].setQRangeTree(qRangeTree);
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
361 }
4b64692b2d1e Added methods to create WstValueTables ('interpolators') for specific columns of wsts.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1898
diff changeset
362
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
363 protected static void loadQRanges(
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
364 Session session,
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
365 WstValueTable.Column [] columns,
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
366 int wst_id
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
367 ) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
368 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_QS)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
369 .addScalar("column_pos", StandardBasicTypes.INTEGER)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
370 .addScalar("q", StandardBasicTypes.DOUBLE)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
371 .addScalar("a", StandardBasicTypes.DOUBLE)
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
372 .addScalar("b", StandardBasicTypes.DOUBLE);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
373
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
374 sqlQuery.setInteger("wst_id", wst_id);
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
375
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
376 List<Object []> qRanges = sqlQuery.list();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
377
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
378 int start = -1;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
379 int Q = qRanges.size();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
380 Integer lastColumn = null;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
381
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
382 for (int i = 0; i < Q; ++i) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
383 Object [] qRange = qRanges.get(i);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
384 Integer columnId = (Integer)qRange[0];
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
385 if (lastColumn == null) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
386 lastColumn = columnId;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
387 start = i;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
388 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
389 else if (!lastColumn.equals(columnId)) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
390 QRangeTree qRangeTree = new QRangeTree(qRanges, start, i);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
391 columns[lastColumn].setQRangeTree(qRangeTree);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
392 lastColumn = columnId;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
393 start = i;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
394 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
395 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
396
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
397 if (start != -1) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
398 QRangeTree qRangeTree = new QRangeTree(qRanges, start, Q);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
399 columns[lastColumn].setQRangeTree(qRangeTree);
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
400 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
401
742
c09c9e05ecfa Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 633
diff changeset
402 /* This is debug code to visualize the q ranges trees
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
403
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
404 java.io.PrintWriter out = null;
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
405 try {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
406 out = new java.io.PrintWriter(
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
407 new java.io.FileWriter(
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
408 "/tmp/qranges" + System.currentTimeMillis() + ".dot"));
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
409
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
410 out.println("graph \"Q ranges trees\" {");
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
411
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
412 for (int i = 0; i < columns.length; ++i) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
413 QRangeTree tree = columns[i].getQRangeTree();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
414 out.println(tree.toGraph());
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
415 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
416
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
417 out.println("}");
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
418
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
419 out.flush();
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
420 }
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
421 catch (java.io.IOException ioe) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
422 log.error(ioe);
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
423 }
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
424 finally {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
425 if (out != null) {
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
426 out.close();
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
427 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
428 }
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
429 */
1839
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
430
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
431 }
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
432
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
433 protected static void loadQRanges(
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
434 Session session,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
435 WstValueTable.Column [] columns,
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
436 Wst wst
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
437 ) {
c3b44da22a3a Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1780
diff changeset
438 loadQRanges(session, columns, wst.getId());
633
d08f77e7f7e8 WST value table: Qs are now stored in ranges for each column.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 632
diff changeset
439 }
443
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
440
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
441 }
5d65fe4c08d5 Separated the WST table loading logic from the calculations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
442 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org