Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/ImportSQRelationValue.java @ 8621:1125e598df0e
Fix handling of multiple entries in SQPeriodSelect default start/end calculation
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Wed, 25 Mar 2015 19:37:44 +0100 |
parents | 17db08570637 |
children | bfca77cbf353 |
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.importer; import java.math.BigDecimal; import java.sql.SQLException; import java.util.List; import org.apache.log4j.Logger; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.exception.ConstraintViolationException; import org.dive4elements.river.model.MeasurementStation; import org.dive4elements.river.model.SQRelation; import org.dive4elements.river.model.SQRelationValue; public class ImportSQRelationValue { private static Logger log = Logger.getLogger(ImportSQRelationValue.class); private SQRelationValue peer; private String parameter; private MeasurementStation station; private Double a; private Double b; private Double qMax; private Double rSQ; private Integer nTot; private Integer nOutlier; private Double cFerguson; private Double cDuan; public ImportSQRelationValue( String parameter, MeasurementStation station, Double a, Double b, Double qMax, Double rSQ, Integer nTot, Integer nOutlier, Double cFerguson, Double cDuan ) { this.parameter = parameter; this.station = station; this.a = a; this.b = b; this.qMax = qMax; this.rSQ = rSQ; this.nTot = nTot; this.nOutlier = nOutlier; this.cFerguson = cFerguson; this.cDuan = cDuan; } public void storeDependencies(SQRelation owner) throws SQLException, ConstraintViolationException { getPeer(owner); } public SQRelationValue getPeer(SQRelation owner) { if (peer == null) { Session session = ImporterSession.getInstance().getDatabaseSession(); Query query2 = session.createQuery( "from SQRelationValue " + " where sqRelation=:owner " + " and parameter=:parameter" + " and measurementStation=:measurementStation" + " and a=:a" + " and b=:b" + " and qMax=:qMax" + " and rSQ=:rSQ" + " and cFerguson=:cFerguson" + " and cDuan=:cDuan"); query2.setParameter("owner", owner); query2.setString("parameter", parameter); query2.setParameter("measurementStation", station); query2.setBigDecimal("a", toBigDecimal(a)); query2.setBigDecimal("b", toBigDecimal(b)); query2.setBigDecimal("qMax", toBigDecimal(qMax)); query2.setBigDecimal("rSQ", toBigDecimal(rSQ)); query2.setBigDecimal("cFerguson", toBigDecimal(cFerguson)); query2.setBigDecimal("cDuan", toBigDecimal(cDuan)); List<SQRelationValue> values = query2.list(); if (values.isEmpty()) { peer = new SQRelationValue( owner, parameter, station, a, b, qMax, rSQ, nTot, nOutlier, cFerguson, cDuan ); session.save(peer); } else { peer = values.get(0); } } return peer; } private static final BigDecimal toBigDecimal(Double x) { if (x == null) return null; return new BigDecimal(x); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :