comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java @ 1898:7053e3255ab4

Employ cache for WstValueTables that have been fetched by wst_id. flys-artifacts/trunk@3258 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 16 Nov 2011 09:11:14 +0000
parents d5e51cc7da23
children 4b64692b2d1e
comparison
equal deleted inserted replaced
1897:cf8a376eb4c9 1898:7053e3255ab4
60 /** 60 /**
61 * Get WstValueTable to interpolate values of a given Wst. 61 * Get WstValueTable to interpolate values of a given Wst.
62 */ 62 */
63 public static WstValueTable getTable(int wst_id) { 63 public static WstValueTable getTable(int wst_id) {
64 64
65 /** @TODO cached/uncached */ 65 Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
66
67 WstValueTableCacheKey cacheKey;
68
69 if (cache != null) {
70 // "-1" is the symbolic river-id for "no river, but wst_id".
71 cacheKey = new WstValueTableCacheKey(-1, wst_id);
72 Element element = cache.get(cacheKey);
73 if (element != null) {
74 log.debug("Got specific wst value table from cache");
75 return (WstValueTable) element.getValue();
76 }
77 }
78 else {
79 cacheKey = null;
80 }
66 81
67 Session session = SessionHolder.HOLDER.get(); 82 Session session = SessionHolder.HOLDER.get();
68 83
69 // Fetch data for one column only. 84 // Fetch data for one column only.
70 85
71 WstValueTable.Column [] columns = loadColumns(session, wst_id); 86 WstValueTable.Column [] columns = loadColumns(session, wst_id);
72 loadQRanges(session, columns, wst_id); 87 loadQRanges(session, columns, wst_id);
73 List<WstValueTable.Row> rows = loadRows(session, wst_id, columns.length); 88 List<WstValueTable.Row> rows = loadRows(session, wst_id, columns.length);
74 89
75 return new WstValueTable(columns, rows); 90 WstValueTable valueTable = new WstValueTable(columns, rows);
76 } 91
92 if (valueTable != null && cacheKey != null) {
93 log.debug("Store wst value table in cache");
94 Element element = new Element(cacheKey, valueTable);
95 cache.put(element);
96 }
97
98 return valueTable;
99 }
100
101
77 public static WstValueTable getTable(River river, int kind) { 102 public static WstValueTable getTable(River river, int kind) {
78 103
79 Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME); 104 Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
80 105
81 WstValueTableCacheKey cacheKey; 106 WstValueTableCacheKey cacheKey;

http://dive4elements.wald.intevation.org