comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java @ 1927:1f90fdd4fa04

Resolved TODO about caching certain WstValueTables. flys-artifacts/trunk@3307 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 23 Nov 2011 11:07:34 +0000
parents 4b64692b2d1e
children ed550e325248
comparison
equal deleted inserted replaced
1926:fde3db5e68e8 1927:1f90fdd4fa04
99 99
100 WstValueTable.Column [] columns = loadColumns(session, wst_id); 100 WstValueTable.Column [] columns = loadColumns(session, wst_id);
101 loadQRanges(session, columns, wst_id); 101 loadQRanges(session, columns, wst_id);
102 List<WstValueTable.Row> rows = loadRows(session, wst_id, columns.length); 102 List<WstValueTable.Row> rows = loadRows(session, wst_id, columns.length);
103 103
104 WstValueTable valueTable = new WstValueTable(columns, rows); 104 WstValueTable valueTable = new WstValueTable(columns, rows);
105 105
106 if (valueTable != null && cacheKey != null) { 106 if (valueTable != null && cacheKey != null) {
107 log.debug("Store wst value table in cache"); 107 log.debug("Store wst value table in cache");
108 Element element = new Element(cacheKey, valueTable); 108 Element element = new Element(cacheKey, valueTable);
109 cache.put(element); 109 cache.put(element);
115 /** 115 /**
116 * Get Table for a specific column of a wst. 116 * Get Table for a specific column of a wst.
117 */ 117 */
118 public static WstValueTable getWstColumnTable(int wst_id, int col_pos) { 118 public static WstValueTable getWstColumnTable(int wst_id, int col_pos) {
119 119
120 /** @TODO cached/uncached */ 120 Cache cache = CacheFactory.getCache(WstValueTableCacheKey.CACHE_NAME);
121
122 WstValueTableCacheKey cacheKey;
123
124 if (cache != null) {
125 // A negaitve/negative number is the symbolic 'river-id' for
126 // "no river and kind but wst_id and colpos".
127 cacheKey = new WstValueTableCacheKey(-wst_id, -col_pos);
128 Element element = cache.get(cacheKey);
129 if (element != null) {
130 log.debug("Got specific wst value table from cache");
131 return (WstValueTable) element.getValue();
132 }
133 }
134 else {
135 cacheKey = null;
136 }
121 137
122 Session session = SessionHolder.HOLDER.get(); 138 Session session = SessionHolder.HOLDER.get();
123 139
124 // Fetch data for one column only. 140 // Fetch data for one column only.
125 141
126 WstValueTable.Column [] columns = loadColumn(session, wst_id, col_pos); 142 WstValueTable.Column [] columns = loadColumn(session, wst_id, col_pos);
127 loadQRanges(session, columns, wst_id, col_pos); 143 loadQRanges(session, columns, wst_id, col_pos);
128 List<WstValueTable.Row> rows = loadRowsOneColumn(session, wst_id, col_pos); 144 List<WstValueTable.Row> rows = loadRowsOneColumn(session, wst_id, col_pos);
129 145
130 return new WstValueTable(columns, rows); 146 WstValueTable valueTable = new WstValueTable(columns, rows);
147
148 if (valueTable != null && cacheKey != null) {
149 log.debug("Store wst value table in cache (wst: "
150 + wst_id + "/ col: " + col_pos + ")");
151 Element element = new Element(cacheKey, valueTable);
152 cache.put(element);
153 }
154
155 return valueTable;
131 } 156 }
132 157
133 158
134 /** 159 /**
135 * Get table for first wst of given kind at given river. 160 * Get table for first wst of given kind at given river.

http://dive4elements.wald.intevation.org