Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HYKFactory.java Thu Jan 19 11:00:27 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/HYKFactory.java Thu Jan 19 12:52:44 2012 +0000 @@ -39,7 +39,7 @@ /** * Get List of Zones for given river and km. */ - public static Object getHYKs(int riverId, double km) { + public static Object getHYKs(int hykid, double km) { logger.debug("HYKFactory.getHYKs"); Cache cache = CacheFactory.getCache(HYK_CACHE_NAME); @@ -47,7 +47,7 @@ String cacheKey; if (cache != null) { - cacheKey = "" + riverId + "_" + km; + cacheKey = "" + hykid + "_" + km; Element element = cache.get(cacheKey); if (element != null) { logger.debug("Got hyk from cache"); @@ -58,7 +58,7 @@ cacheKey = null; } - List<Zone> zones = getZonesUncached(riverId, km); + List<Zone> zones = getZonesUncached(hykid, km); if (zones != null && cacheKey != null) { logger.debug("Store hykzones in cache."); @@ -70,6 +70,21 @@ } + public static String getHykName(int hykid) { + logger.debug("HYKFactory.getHykName " + hykid); + + Session session = SessionHolder.HOLDER.get(); + + // TODO respect interval better. respect multiples (sort, limit), + // TODO respect flow direction of river. + Query query = session.createQuery( + "select description from HYK where id = :hykid "); + query.setParameter("hykid", hykid); + + return (String) query.uniqueResult(); + } + + /** * * @param column the position columns value @@ -78,10 +93,10 @@ */ // TODO we also need to know the HYK-id to specify which set we are // inspecting. - public static List<Zone> getZonesUncached(int riverId, double km) { + public static List<Zone> getZonesUncached(int hykid, double km) { if (logger.isDebugEnabled()) { - logger.debug("HYKFactory.getZoneUncached " + riverId + " km " + km); + logger.debug("HYKFactory.getZoneUncached " + hykid + " km " + km); } Session session = SessionHolder.HOLDER.get(); @@ -89,21 +104,20 @@ // TODO respect interval better. respect multiples (sort, limit), // TODO respect flow direction of river. Query query = session.createQuery( - "from HYKFormation where entry.HYK.river.id = :riverid " + - " and entry.km between " + - ":km - cast(distance_vl/1000.0 - 0.001 as big_decimal) and " + - ":km + cast(distance_vl/1000.0 + 0.001 as big_decimal)"); - query.setParameter("riverid", riverId); + "from HYKFormation where entry.HYK.id = :hykid " + + " and :km between entry.km - cast(distance_vl/1000.0 + 0.001 as big_decimal) and " + + " entry.km + cast(distance_vl/1000.0 + 0.001 as big_decimal)" + + " order by entry.km asc"); + query.setParameter("hykid", hykid); query.setParameter("km", new BigDecimal(km)); logger.debug("Big km " + new BigDecimal(km)); List<HYKFormation> forms = query.list(); List<Zone> zones = new ArrayList<Zone>(); - for (HYKFormation form : forms) { - logger.debug("One HYKFormation found (entry: " - + form.getEntry().getId() - + ") /km " + form.getEntry().getKm() + "."); - + // TODO limit query by one; sensible sorting. + // Take the first one. + if (forms.size() >= 1) { + HYKFormation form = forms.get(0); // Create respective zones. for (HYKFlowZone flowZone: form.getZones()) { Zone z = new Zone(flowZone.getA().doubleValue(),