Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WKmsFactory.java @ 1726:e3b9164a85fe
Fetch name of static WKms.
flys-artifacts/trunk@3008 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 18 Oct 2011 14:03:43 +0000 |
parents | fb4fb1c67c35 |
children | 2e5ebdeb8af9 |
comparison
equal
deleted
inserted
replaced
1725:d9afb16d1fd4 | 1726:e3b9164a85fe |
---|---|
25 */ | 25 */ |
26 public class WKmsFactory | 26 public class WKmsFactory |
27 { | 27 { |
28 private static Logger log = Logger.getLogger(WKmsFactory.class); | 28 private static Logger log = Logger.getLogger(WKmsFactory.class); |
29 | 29 |
30 /** | |
31 * Value for wsts 'kind' typically used for "additional | |
32 * longitudinal sections. | |
33 */ | |
34 public static final int KIND_ZUS = 1; | |
35 | |
36 /** | |
37 * Value for wsts 'kind' typically used for flood protection measures | |
38 * (e.g. dikes). | |
39 */ | |
40 public static final int KIND_PROTECTION = 5; | |
41 | |
42 /** Query to get km and ws for wst_id and column_pos. */ | 30 /** Query to get km and ws for wst_id and column_pos. */ |
43 public static final String SQL_SELECT_WS = | 31 public static final String SQL_SELECT_WS = |
44 "SELECT km, w FROM wst_w_values " + | 32 "SELECT km, w FROM wst_w_values " + |
45 "WHERE wst_id = :wst_id AND column_pos = :column_pos"; | 33 "WHERE wst_id = :wst_id AND column_pos = :column_pos"; |
34 | |
35 public static final String SQL_SELECT_NAME = | |
36 "SELECT name " + | |
37 "FROM wst_columns "+ | |
38 "WHERE wst_id = :wst_id AND position = :column_pos"; | |
46 | 39 |
47 | 40 |
48 private WKmsFactory() { | 41 private WKmsFactory() { |
49 } | 42 } |
50 | 43 |
51 | 44 |
52 /** | 45 /** |
53 * Get WKms for given column and wst_id, caring about the cache. | 46 * Get WKms for given column and wst_id, caring about the cache. |
54 */ | 47 */ |
55 public static WKms getWKms(int kind, int column, int wst_id) { | 48 public static WKms getWKms(int column, int wst_id) { |
56 log.debug("WKmsFactory.getWKms"); | 49 log.debug("WKmsFactory.getWKms"); |
57 Cache cache = CacheFactory.getCache(StaticWKmsCacheKey.CACHE_NAME); | 50 Cache cache = CacheFactory.getCache(StaticWKmsCacheKey.CACHE_NAME); |
58 | 51 |
59 StaticWKmsCacheKey cacheKey; | 52 StaticWKmsCacheKey cacheKey; |
60 | 53 |
68 } | 61 } |
69 else { | 62 else { |
70 cacheKey = null; | 63 cacheKey = null; |
71 } | 64 } |
72 | 65 |
73 WKms values = getWKmsUncached(kind, column, wst_id); | 66 WKms values = getWKmsUncached(column, wst_id); |
74 | 67 |
75 if (values != null && cacheKey != null) { | 68 if (values != null && cacheKey != null) { |
76 log.debug("Store static wst values in cache."); | 69 log.debug("Store static wst values in cache."); |
77 Element element = new Element(cacheKey, values); | 70 Element element = new Element(cacheKey, values); |
78 cache.put(element); | 71 cache.put(element); |
81 } | 74 } |
82 | 75 |
83 | 76 |
84 /** | 77 /** |
85 * Get WKms from db. | 78 * Get WKms from db. |
79 * @param column the position columns value | |
80 * @param wst_id database id of the wst | |
81 * @return according WKms. | |
86 */ | 82 */ |
87 public static WKms getWKmsUncached(int kind, int column, int wst_id) { | 83 public static WKms getWKmsUncached(int column, int wst_id) { |
88 log.debug("WKmsFactory.getWKmsUncached c/" + column + ", wst_id/" + wst_id); | 84 log.debug("WKmsFactory.getWKmsUncached c/" + column + ", wst_id/" + wst_id); |
89 Session session = SessionHolder.HOLDER.get(); | 85 Session session = SessionHolder.HOLDER.get(); |
86 | |
87 String name = "todo"; | |
88 | |
89 SQLQuery nameQuery = session.createSQLQuery(SQL_SELECT_NAME) | |
90 .addScalar("name", StandardBasicTypes.STRING); | |
91 nameQuery.setInteger("wst_id", wst_id); | |
92 nameQuery.setInteger("column_pos", column); | |
93 | |
94 List<String> names = nameQuery.list(); | |
95 if (names.size() >= 1) { | |
96 name = names.get(0); | |
97 } | |
98 | |
99 WKmsImpl wkms = new WKmsImpl(name); | |
90 | 100 |
91 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WS) | 101 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_WS) |
92 .addScalar("km", StandardBasicTypes.DOUBLE) | 102 .addScalar("km", StandardBasicTypes.DOUBLE) |
93 .addScalar("w", StandardBasicTypes.DOUBLE); | 103 .addScalar("w", StandardBasicTypes.DOUBLE); |
94 sqlQuery.setInteger("wst_id", wst_id); | 104 sqlQuery.setInteger("wst_id", wst_id); |
95 sqlQuery.setInteger("column_pos", column); | 105 sqlQuery.setInteger("column_pos", column); |
96 | 106 |
97 List<Object []> results = sqlQuery.list(); | 107 List<Object []> results = sqlQuery.list(); |
98 | 108 |
99 // TODO Fetch name in a separate query. | |
100 String name = "todo"; | |
101 | |
102 WKmsImpl wkms = new WKmsImpl(name); | |
103 double kms [] = new double[results.size()]; | 109 double kms [] = new double[results.size()]; |
104 double ws [] = new double[results.size()]; | 110 double ws [] = new double[results.size()]; |
105 | 111 |
106 int lastColumn = Integer.MAX_VALUE; | 112 int lastColumn = Integer.MAX_VALUE; |
107 | 113 |