Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/AnnotationsFactory.java @ 1839:c3b44da22a3a
Minor refactoring in preparation of generation of interpolators (WstValueTable) for static WQKms.
flys-artifacts/trunk@3175 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 07 Nov 2011 12:37:41 +0000 |
parents | bcef54a563ea |
children | 57b03b3ab15c |
line wrap: on
line source
package de.intevation.flys.artifacts.model; import java.math.BigDecimal; import java.util.List; import java.util.Iterator; import de.intevation.flys.backend.SessionHolder; import de.intevation.flys.model.Annotation; import de.intevation.flys.model.Range; import de.intevation.flys.model.River; import org.hibernate.Session; import org.hibernate.Query; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class AnnotationsFactory { public static List<Annotation> getAnnotations(River river) { return getAnnotations(river.getName()); } /** * Get Annotations which do not have a "b" ("to")-value set. * * @param river name of the river of interest. * * @return List of Annotations for river which have only "a" ("from") * value set. */ public static List<Annotation> getPointAnnotations(String river) { Session session = SessionHolder.HOLDER.get(); Query rangesQuery = session.createQuery( "from Range where river.name=:name and b = null"); rangesQuery.setParameter("name", river); List<Range> ranges = rangesQuery.list(); Query query = session.createQuery( "from Annotation where range in (:ranges) order by range.a"); query.setParameterList("ranges", ranges); return query.list(); } public static List<Annotation> getAnnotations(String river) { Session session = SessionHolder.HOLDER.get(); Query rangesQuery = session.createQuery( "from Range where river.name=:name"); rangesQuery.setParameter("name", river); List<Range> ranges = rangesQuery.list(); Query query = session.createQuery( "from Annotation where range in (:ranges) order by range.a"); query.setParameterList("ranges", ranges); return query.list(); } /** * Get minimal "a" ("from") and maximal "b" ("to") value of annotations' * ranges of a river. * * @param river name of the river of interest. * * @return Array containing minimal "a" and max "b" value of any * annotation stored for the given river. */ public static double[] getAnnotationsBreadth(String river) { Session session = SessionHolder.HOLDER.get(); Query minAQuery = session.createQuery( "select min(a), max(b) from Range where river.name=:name"); minAQuery.setParameter("name", river); double[] minAmaxB = {0.0f, 0.0f}; Object[] row = (Object[]) minAQuery.list().iterator().next(); minAmaxB[0] = ((BigDecimal) row[0]).doubleValue(); minAmaxB[1] = ((BigDecimal) row[1]).doubleValue(); return minAmaxB; } public static Iterator<Annotation> getAnnotationsIterator(String river) { Session session = SessionHolder.HOLDER.get(); Query rangesQuery = session.createQuery( "from Range where river.name=:name"); rangesQuery.setParameter("name", river); List<Range> ranges = rangesQuery.list(); Query query = session.createQuery( "from Annotation where range in (:ranges) order by range.a"); query.setParameterList("ranges", ranges); return (Iterator<Annotation>)query.iterate(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :