Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FixingsColumnFactory.java @ 2622:8bc1e1cb7f7b
Fixed the fixings columns caching problem.
flys-artifacts/trunk@4207 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 06 Apr 2012 10:12:34 +0000 |
parents | cc0fa1798a3c |
children | a441be7f1589 |
comparison
equal
deleted
inserted
replaced
2621:f0cc556eda29 | 2622:8bc1e1cb7f7b |
---|---|
14 import org.hibernate.Session; | 14 import org.hibernate.Session; |
15 import org.hibernate.SQLQuery; | 15 import org.hibernate.SQLQuery; |
16 | 16 |
17 import org.hibernate.type.StandardBasicTypes; | 17 import org.hibernate.type.StandardBasicTypes; |
18 | 18 |
19 import org.apache.log4j.Logger; | |
20 | |
19 public class FixingsColumnFactory | 21 public class FixingsColumnFactory |
20 { | 22 { |
21 public static final String CACHE_NAME = "fixing-columns"; | 23 private static Logger log = Logger.getLogger(FixingsColumnFactory.class); |
24 | |
25 public static final String CACHE_NAME = "fixings-columns"; | |
22 | 26 |
23 public static final String SQL_COLUMN_WS = | 27 public static final String SQL_COLUMN_WS = |
24 "SELECT wcv.position AS km, wcv.w AS w " + | 28 "SELECT wcv.position AS km, wcv.w AS w " + |
25 "FROM wst_column_values wcv " + | 29 "FROM wst_column_values wcv " + |
26 "WHERE wst_column_id = :column_id " + | 30 "WHERE wst_column_id = :column_id " + |
39 private FixingsColumnFactory() { | 43 private FixingsColumnFactory() { |
40 } | 44 } |
41 | 45 |
42 public FixingsColumn getColumnData(Fixing.Column column) { | 46 public FixingsColumn getColumnData(Fixing.Column column) { |
43 | 47 |
44 FixingsColumn result; | 48 boolean debug = log.isDebugEnabled(); |
49 | |
50 if (debug) { | |
51 log.debug("FixingsColumnFactory.getColumnData"); | |
52 } | |
45 | 53 |
46 Cache cache = CacheFactory.getCache(CACHE_NAME); | 54 Cache cache = CacheFactory.getCache(CACHE_NAME); |
47 | 55 |
48 if (cache != null) { | 56 if (cache == null) { |
49 Integer cacheKey = Integer.valueOf(column.getId()); | 57 if (debug) { |
50 Element element = cache.get(cacheKey); | 58 log.debug("Cache unconfigured."); |
59 } | |
60 return getUncached(column); | |
61 } | |
51 | 62 |
52 if (element != null) { | 63 Integer cacheKey = Integer.valueOf(column.getId()); |
53 return (FixingsColumn)element.getValue(); | 64 Element element = cache.get(cacheKey); |
65 | |
66 if (element != null) { | |
67 if (debug) { | |
68 log.debug("Column " + cacheKey + " found in cache."); | |
54 } | 69 } |
55 | 70 return (FixingsColumn)element.getValue(); |
56 if ((result = getUncached(column)) != null) { | 71 } |
72 else { | |
73 FixingsColumn result = getUncached(column); | |
74 if (result != null) { | |
75 if (debug) { | |
76 log.debug("Store column " + cacheKey + " into cache."); | |
77 } | |
57 cache.put(new Element(cacheKey, result)); | 78 cache.put(new Element(cacheKey, result)); |
58 } | 79 } |
80 return result; | |
59 } | 81 } |
60 else { | |
61 result = getUncached(column); | |
62 } | |
63 | |
64 return result; | |
65 } | 82 } |
66 | 83 |
67 protected FixingsColumn getUncached(Fixing.Column column) { | 84 protected FixingsColumn getUncached(Fixing.Column column) { |
68 Session session = SessionHolder.HOLDER.get(); | 85 Session session = SessionHolder.HOLDER.get(); |
69 | 86 |