Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/MainValuesFactory.java @ 999:b0218f21c664
Wire datacage with backend of artifact database.
flys-artifacts/trunk@2438 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 01 Aug 2011 14:58:15 +0000 |
parents | 478940d06876 |
children | 3e1149adc8b9 |
line wrap: on
line source
package de.intevation.flys.artifacts.model; import java.math.BigDecimal; import java.util.List; import org.apache.log4j.Logger; import org.hibernate.Session; import org.hibernate.Query; import de.intevation.flys.backend.SessionHolder; import de.intevation.flys.model.Gauge; import de.intevation.flys.model.MainValue; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class MainValuesFactory { private static Logger logger = Logger.getLogger(MainValuesFactory.class); public static List<MainValue> getMainValues(Gauge gauge) { Session session = SessionHolder.HOLDER.get(); Query query = session.createQuery( "from MainValue where gauge=:gauge"); query.setParameter("gauge", gauge); return query.list(); } /** * Returns an array of [days, qs] necessary to create duration curves. * * @param gauge The selected gauge. * * @return a 2dim array of [days, qs] where days is an int[] and qs is * an double[]. */ public static Object[] getDurationCurveData(Gauge gauge) { Session session = SessionHolder.HOLDER.get(); Query query = session.createQuery( "select cast(nmv.name as integer) as days, mv.value as q " + "from MainValue as mv " + "join mv.mainValue as nmv " + "join nmv.type mvt " + "where mvt.name = 'D' and mv.gauge.id = :gauge_id " + "order by days"); query.setParameter("gauge_id", gauge.getId()); List<Object> results = query.list(); int[] days = new int[results.size()]; double[] qs = new double[results.size()]; int idx = 0; for (Object obj: results) { Object[] arr = (Object[]) obj; try { int day = ((Integer) arr[0]).intValue(); double q = ((BigDecimal) arr[1]).doubleValue(); days[idx] = day; qs[idx++] = q; } catch (NumberFormatException nfe) { logger.warn(nfe, nfe); } } return new Object[] { days, qs }; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :