Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTableFactory.java @ 626:e3ee131d5dd3
Moved WST value table cache key to a separate class.
flys-artifacts/trunk@1991 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 24 May 2011 11:23:57 +0000 |
parents | 523a256451cd |
children | 07640ab913fd |
comparison
equal
deleted
inserted
replaced
625:c0c60a611fca | 626:e3ee131d5dd3 |
---|---|
1 package de.intevation.flys.artifacts.model; | 1 package de.intevation.flys.artifacts.model; |
2 | |
3 import java.io.Serializable; | |
4 | 2 |
5 import java.util.ArrayList; | 3 import java.util.ArrayList; |
6 import java.util.Comparator; | 4 import java.util.Comparator; |
7 import java.util.List; | 5 import java.util.List; |
8 import java.util.Collections; | 6 import java.util.Collections; |
36 public static final String SQL_POS_WQ = | 34 public static final String SQL_POS_WQ = |
37 "SELECT position, w, q, column_pos" + | 35 "SELECT position, w, q, column_pos" + |
38 " FROM wst_value_table" + | 36 " FROM wst_value_table" + |
39 " WHERE wst_id = :wst_id"; | 37 " WHERE wst_id = :wst_id"; |
40 | 38 |
41 public static final class CacheKey | |
42 implements Serializable | |
43 { | |
44 private int riverId; | |
45 private int kind; | |
46 | |
47 public CacheKey(int riverId, int kind) { | |
48 this.riverId = riverId; | |
49 this.kind = kind; | |
50 } | |
51 | |
52 public int hashCode() { | |
53 return (riverId << 8) | kind; | |
54 } | |
55 | |
56 public boolean equals(Object other) { | |
57 if (!(other instanceof CacheKey)) { | |
58 return false; | |
59 } | |
60 CacheKey o = (CacheKey)other; | |
61 return riverId == o.riverId && kind == o.kind; | |
62 } | |
63 } // class CacheKey | |
64 | |
65 private WstValueTableFactory() { | 39 private WstValueTableFactory() { |
66 } | 40 } |
67 | 41 |
68 public static WstValueTable getTable(River river) { | 42 public static WstValueTable getTable(River river) { |
69 return getTable(river, 0); | 43 return getTable(river, 0); |
71 | 45 |
72 public static WstValueTable getTable(River river, int kind) { | 46 public static WstValueTable getTable(River river, int kind) { |
73 | 47 |
74 Cache cache = CacheFactory.getCache(CACHE_NAME); | 48 Cache cache = CacheFactory.getCache(CACHE_NAME); |
75 | 49 |
76 CacheKey cacheKey; | 50 WstValueTableCacheKey cacheKey; |
77 | 51 |
78 if (cache != null) { | 52 if (cache != null) { |
79 cacheKey = new CacheKey(river.getId(), kind); | 53 cacheKey = new WstValueTableCacheKey(river.getId(), kind); |
80 Element element = cache.get(cacheKey); | 54 Element element = cache.get(cacheKey); |
81 if (element != null) { | 55 if (element != null) { |
82 log.debug("got wst value table from cache"); | 56 log.debug("got wst value table from cache"); |
83 return (WstValueTable)element.getValue(); | 57 return (WstValueTable)element.getValue(); |
84 } | 58 } |