teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.model.minfo; felix@4463: felix@6944: import java.util.Date; felix@4463: import java.util.List; felix@4463: felix@4463: import org.apache.log4j.Logger; felix@4463: import org.hibernate.SQLQuery; felix@4463: import org.hibernate.Session; felix@4463: felix@6944: import org.hibernate.type.StandardBasicTypes; felix@6944: teichmann@5831: import org.dive4elements.river.model.FlowVelocityMeasurementValue; teichmann@5831: import org.dive4elements.river.backend.SessionHolder; felix@4463: felix@4463: felix@4463: public class FlowVelocityMeasurementFactory felix@4463: { felix@4463: /** Private logger to use here. */ felix@4463: private static Logger log = Logger.getLogger(FlowVelocityMeasurementFactory.class); felix@4463: felix@4463: /** Query to get description and start year, given name and a km range. */ felix@4463: public static final String SQL_SELECT_ONE = felix@4463: "SELECT station, datetime, w, q, v, description " + felix@4463: " FROM flow_velocity_measure_values" + felix@4463: " WHERE id = :id"; felix@4463: felix@4463: felix@4463: private FlowVelocityMeasurementFactory() { felix@4463: } felix@4463: felix@4463: felix@4463: public static FlowVelocityMeasurementValue.FastFlowVelocityMeasurementValue felix@4463: getFlowVelocityMeasurement(int id) felix@4463: { felix@4463: log.debug("FlowVelocityMeasurementFactory.getFlowVelocityMeasurementValue"); felix@4463: Session session = SessionHolder.HOLDER.get(); felix@4463: SQLQuery sqlQuery = null; felix@6944: sqlQuery = session.createSQLQuery(SQL_SELECT_ONE) felix@6944: .addScalar("station", StandardBasicTypes.DOUBLE) felix@6944: .addScalar("datetime", StandardBasicTypes.DATE) felix@6944: .addScalar("w", StandardBasicTypes.DOUBLE) felix@6944: .addScalar("q", StandardBasicTypes.DOUBLE) felix@6944: .addScalar("v", StandardBasicTypes.DOUBLE) felix@6944: .addScalar("description", StandardBasicTypes.STRING); felix@4463: sqlQuery.setParameter("id", id); felix@4463: felix@4463: List results = sqlQuery.list(); felix@4463: if (results.size() > 0) { felix@4463: Object[] row = results.get(0); felix@4463: if (row == null || row.length < 6) { felix@4463: return null; felix@4463: } felix@4463: return FlowVelocityMeasurementValue.getUnmapped( felix@6945: (Double) row[0], felix@6945: (Double) row[2], felix@6945: (Double) row[3], felix@6945: (Double) row[4], felix@6945: (Date) row[1], felix@6945: (String) row[5]); felix@4463: } felix@4463: return null; felix@4463: } felix@4463: } felix@4463: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :