comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HYKFactory.java @ 2139:923256599afe

Somewhat improved hyk handling and rendering. flys-artifacts/trunk@3717 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 19 Jan 2012 12:52:44 +0000
parents 04b6b6a4564d
children 345a236f7075
comparison
equal deleted inserted replaced
2138:59bb5c895be3 2139:923256599afe
37 37
38 38
39 /** 39 /**
40 * Get List of Zones for given river and km. 40 * Get List of Zones for given river and km.
41 */ 41 */
42 public static Object getHYKs(int riverId, double km) { 42 public static Object getHYKs(int hykid, double km) {
43 logger.debug("HYKFactory.getHYKs"); 43 logger.debug("HYKFactory.getHYKs");
44 44
45 Cache cache = CacheFactory.getCache(HYK_CACHE_NAME); 45 Cache cache = CacheFactory.getCache(HYK_CACHE_NAME);
46 46
47 String cacheKey; 47 String cacheKey;
48 48
49 if (cache != null) { 49 if (cache != null) {
50 cacheKey = "" + riverId + "_" + km; 50 cacheKey = "" + hykid + "_" + km;
51 Element element = cache.get(cacheKey); 51 Element element = cache.get(cacheKey);
52 if (element != null) { 52 if (element != null) {
53 logger.debug("Got hyk from cache"); 53 logger.debug("Got hyk from cache");
54 return (List<Zone>)element.getValue(); 54 return (List<Zone>)element.getValue();
55 } 55 }
56 } 56 }
57 else { 57 else {
58 cacheKey = null; 58 cacheKey = null;
59 } 59 }
60 60
61 List<Zone> zones = getZonesUncached(riverId, km); 61 List<Zone> zones = getZonesUncached(hykid, km);
62 62
63 if (zones != null && cacheKey != null) { 63 if (zones != null && cacheKey != null) {
64 logger.debug("Store hykzones in cache."); 64 logger.debug("Store hykzones in cache.");
65 Element element = new Element(cacheKey, zones); 65 Element element = new Element(cacheKey, zones);
66 cache.put(element); 66 cache.put(element);
68 68
69 return zones; 69 return zones;
70 } 70 }
71 71
72 72
73 public static String getHykName(int hykid) {
74 logger.debug("HYKFactory.getHykName " + hykid);
75
76 Session session = SessionHolder.HOLDER.get();
77
78 // TODO respect interval better. respect multiples (sort, limit),
79 // TODO respect flow direction of river.
80 Query query = session.createQuery(
81 "select description from HYK where id = :hykid ");
82 query.setParameter("hykid", hykid);
83
84 return (String) query.uniqueResult();
85 }
86
87
73 /** 88 /**
74 * 89 *
75 * @param column the position columns value 90 * @param column the position columns value
76 * @param wst_id database id of the wst 91 * @param wst_id database id of the wst
77 * @return according WKms. 92 * @return according WKms.
78 */ 93 */
79 // TODO we also need to know the HYK-id to specify which set we are 94 // TODO we also need to know the HYK-id to specify which set we are
80 // inspecting. 95 // inspecting.
81 public static List<Zone> getZonesUncached(int riverId, double km) { 96 public static List<Zone> getZonesUncached(int hykid, double km) {
82 97
83 if (logger.isDebugEnabled()) { 98 if (logger.isDebugEnabled()) {
84 logger.debug("HYKFactory.getZoneUncached " + riverId + " km " + km); 99 logger.debug("HYKFactory.getZoneUncached " + hykid + " km " + km);
85 } 100 }
86 101
87 Session session = SessionHolder.HOLDER.get(); 102 Session session = SessionHolder.HOLDER.get();
88 103
89 // TODO respect interval better. respect multiples (sort, limit), 104 // TODO respect interval better. respect multiples (sort, limit),
90 // TODO respect flow direction of river. 105 // TODO respect flow direction of river.
91 Query query = session.createQuery( 106 Query query = session.createQuery(
92 "from HYKFormation where entry.HYK.river.id = :riverid " + 107 "from HYKFormation where entry.HYK.id = :hykid " +
93 " and entry.km between " + 108 " and :km between entry.km - cast(distance_vl/1000.0 + 0.001 as big_decimal) and " +
94 ":km - cast(distance_vl/1000.0 - 0.001 as big_decimal) and " + 109 " entry.km + cast(distance_vl/1000.0 + 0.001 as big_decimal)" +
95 ":km + cast(distance_vl/1000.0 + 0.001 as big_decimal)"); 110 " order by entry.km asc");
96 query.setParameter("riverid", riverId); 111 query.setParameter("hykid", hykid);
97 query.setParameter("km", new BigDecimal(km)); 112 query.setParameter("km", new BigDecimal(km));
98 logger.debug("Big km " + new BigDecimal(km)); 113 logger.debug("Big km " + new BigDecimal(km));
99 List<HYKFormation> forms = query.list(); 114 List<HYKFormation> forms = query.list();
100 115
101 List<Zone> zones = new ArrayList<Zone>(); 116 List<Zone> zones = new ArrayList<Zone>();
102 for (HYKFormation form : forms) { 117 // TODO limit query by one; sensible sorting.
103 logger.debug("One HYKFormation found (entry: " 118 // Take the first one.
104 + form.getEntry().getId() 119 if (forms.size() >= 1) {
105 + ") /km " + form.getEntry().getKm() + "."); 120 HYKFormation form = forms.get(0);
106
107 // Create respective zones. 121 // Create respective zones.
108 for (HYKFlowZone flowZone: form.getZones()) { 122 for (HYKFlowZone flowZone: form.getZones()) {
109 Zone z = new Zone(flowZone.getA().doubleValue(), 123 Zone z = new Zone(flowZone.getA().doubleValue(),
110 flowZone.getB().doubleValue(), 124 flowZone.getB().doubleValue(),
111 flowZone.getType().getName()); 125 flowZone.getType().getName());

http://dive4elements.wald.intevation.org