Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/HYKFactory.java @ 8202:e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 12:58:17 +0200 |
parents | fac1aa67931b |
children | 0a5239a1e46e |
comparison
equal
deleted
inserted
replaced
8201:4b8c5a08de04 | 8202:e4606eae8ea5 |
---|---|
31 /** | 31 /** |
32 * Factory to access HYKs (hydrographic values). | 32 * Factory to access HYKs (hydrographic values). |
33 */ | 33 */ |
34 public class HYKFactory | 34 public class HYKFactory |
35 { | 35 { |
36 private static Logger logger = Logger.getLogger(HYKFactory.class); | 36 private static Logger log = Logger.getLogger(HYKFactory.class); |
37 | 37 |
38 public static String HYK_CACHE_NAME = "hykache"; | 38 public static String HYK_CACHE_NAME = "hykache"; |
39 | 39 |
40 | 40 |
41 /** Do not instantiate a HYKFactory. */ | 41 /** Do not instantiate a HYKFactory. */ |
45 | 45 |
46 /** | 46 /** |
47 * Get List of Zones for given river and km. | 47 * Get List of Zones for given river and km. |
48 */ | 48 */ |
49 public static Object getHYKs(int hykid, double km) { | 49 public static Object getHYKs(int hykid, double km) { |
50 logger.debug("HYKFactory.getHYKs"); | 50 log.debug("HYKFactory.getHYKs"); |
51 | 51 |
52 Cache cache = CacheFactory.getCache(HYK_CACHE_NAME); | 52 Cache cache = CacheFactory.getCache(HYK_CACHE_NAME); |
53 | 53 |
54 String cacheKey; | 54 String cacheKey; |
55 | 55 |
56 if (cache != null) { | 56 if (cache != null) { |
57 cacheKey = "" + hykid + "_" + km; | 57 cacheKey = "" + hykid + "_" + km; |
58 Element element = cache.get(cacheKey); | 58 Element element = cache.get(cacheKey); |
59 if (element != null) { | 59 if (element != null) { |
60 logger.debug("Got hyk from cache"); | 60 log.debug("Got hyk from cache"); |
61 return element.getValue(); | 61 return element.getValue(); |
62 } | 62 } |
63 } | 63 } |
64 else { | 64 else { |
65 cacheKey = null; | 65 cacheKey = null; |
66 } | 66 } |
67 | 67 |
68 List<Zone> zones = getZonesUncached(hykid, km); | 68 List<Zone> zones = getZonesUncached(hykid, km); |
69 | 69 |
70 if (zones != null && cacheKey != null) { | 70 if (zones != null && cacheKey != null) { |
71 logger.debug("Store hykzones in cache."); | 71 log.debug("Store hykzones in cache."); |
72 Element element = new Element(cacheKey, zones); | 72 Element element = new Element(cacheKey, zones); |
73 cache.put(element); | 73 cache.put(element); |
74 } | 74 } |
75 | 75 |
76 return zones; | 76 return zones; |
77 } | 77 } |
78 | 78 |
79 | 79 |
80 /** Return name for hyk with given id. */ | 80 /** Return name for hyk with given id. */ |
81 public static String getHykName(int hykid) { | 81 public static String getHykName(int hykid) { |
82 logger.debug("HYKFactory.getHykName " + hykid); | 82 log.debug("HYKFactory.getHykName " + hykid); |
83 | 83 |
84 Session session = SessionHolder.HOLDER.get(); | 84 Session session = SessionHolder.HOLDER.get(); |
85 | 85 |
86 Query query = session.createQuery( | 86 Query query = session.createQuery( |
87 "select description from HYK where id = :hykid "); | 87 "select description from HYK where id = :hykid "); |
96 * @param hykid ID of the 'main' HYK to query. | 96 * @param hykid ID of the 'main' HYK to query. |
97 * @param km for which to get the hyk-zones. | 97 * @param km for which to get the hyk-zones. |
98 * @return according zones. | 98 * @return according zones. |
99 */ | 99 */ |
100 public static List<Zone> getZonesUncached(int hykid, double km) { | 100 public static List<Zone> getZonesUncached(int hykid, double km) { |
101 if (logger.isDebugEnabled()) { | 101 if (log.isDebugEnabled()) { |
102 logger.debug("HYKFactory.getZoneUncached " + hykid + " km " + km); | 102 log.debug("HYKFactory.getZoneUncached " + hykid + " km " + km); |
103 } | 103 } |
104 | 104 |
105 Session session = SessionHolder.HOLDER.get(); | 105 Session session = SessionHolder.HOLDER.get(); |
106 | 106 |
107 // Find out flow-direction of river. | 107 // Find out flow-direction of river. |
160 | 160 |
161 sqlQuery.setInteger("hykid", hykid); | 161 sqlQuery.setInteger("hykid", hykid); |
162 sqlQuery.setDouble("flowDir", flowDir); | 162 sqlQuery.setDouble("flowDir", flowDir); |
163 sqlQuery.setDouble("km", km); | 163 sqlQuery.setDouble("km", km); |
164 | 164 |
165 boolean debug = logger.isDebugEnabled(); | 165 boolean debug = log.isDebugEnabled(); |
166 | 166 |
167 if (debug) { | 167 if (debug) { |
168 logger.debug("HYK SQL: " + sqlQuery.getQueryString()); | 168 log.debug("HYK SQL: " + sqlQuery.getQueryString()); |
169 } | 169 } |
170 | 170 |
171 List<Object[]> results = sqlQuery.list(); | 171 List<Object[]> results = sqlQuery.list(); |
172 | 172 |
173 if (debug) { | 173 if (debug) { |
174 logger.debug("Found " + results.size() + " HYKFormation IDs in DB."); | 174 log.debug("Found " + results.size() + " HYKFormation IDs in DB."); |
175 } | 175 } |
176 | 176 |
177 if (results == null || results.isEmpty()) { | 177 if (results == null || results.isEmpty()) { |
178 if (debug) { | 178 if (debug) { |
179 logger.debug("No HYK found for ID " + hykid + " at km " + km); | 179 log.debug("No HYK found for ID " + hykid + " at km " + km); |
180 } | 180 } |
181 return new ArrayList<HYKFormation>(); | 181 return new ArrayList<HYKFormation>(); |
182 } | 182 } |
183 | 183 |
184 Object[] resultSet = results.get(0); | 184 Object[] resultSet = results.get(0); |