teichmann@5844: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5844: * Software engineering by Intevation GmbH teichmann@5844: * teichmann@5992: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5844: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5992: * documentation coming with Dive4Elements River for details. teichmann@5844: */ teichmann@5844: teichmann@5829: package org.dive4elements.river.importer; ingo@2827: ingo@2827: import java.math.BigDecimal; teichmann@5446: ingo@2827: import java.util.List; ingo@2827: ingo@2827: import org.hibernate.Session; ingo@2827: import org.hibernate.Query; ingo@2827: teichmann@5829: import org.dive4elements.river.model.FlowVelocityModel; teichmann@5829: import org.dive4elements.river.model.FlowVelocityModelValue; ingo@2827: ingo@2827: ingo@2827: public class ImportFlowVelocityModelValue { ingo@2827: ingo@2827: private BigDecimal station; ingo@2828: private BigDecimal q; ingo@2827: private BigDecimal totalChannel; ingo@2827: private BigDecimal mainChannel; ingo@2827: private BigDecimal shearStress; ingo@2827: ingo@2827: private FlowVelocityModelValue peer; ingo@2827: ingo@2827: ingo@2827: public ImportFlowVelocityModelValue( ingo@2827: BigDecimal station, ingo@2828: BigDecimal q, ingo@2827: BigDecimal totalChannel, ingo@2827: BigDecimal mainChannel, ingo@2827: BigDecimal shearStress ingo@2827: ) { ingo@2827: this.station = station; ingo@2828: this.q = q; ingo@2827: this.totalChannel = totalChannel; ingo@2827: this.mainChannel = mainChannel; ingo@2827: this.shearStress = shearStress; ingo@2827: } ingo@2827: ingo@2827: tom@5416: public void storeDependencies(FlowVelocityModel model) { ingo@2827: getPeer(model); ingo@2827: } ingo@2827: ingo@2827: ingo@2827: public FlowVelocityModelValue getPeer(FlowVelocityModel model) { ingo@2827: if (peer == null) { ingo@2827: Session session = ImporterSession.getInstance().getDatabaseSession(); ingo@2827: ingo@2827: Query query = session.createQuery( ingo@2827: "from FlowVelocityModelValue where " + ingo@2833: " flowVelocity=:model and " + teichmann@5707: " station between :station - 0.00001 and :station + 0.00001" ingo@2827: ); ingo@2827: ingo@2827: query.setParameter("model", model); tom@5713: query.setParameter("station", station.doubleValue()); ingo@2827: ingo@2827: List values = query.list(); ingo@2827: ingo@2827: if (values.isEmpty()) { ingo@2827: peer = new FlowVelocityModelValue( ingo@2828: model, station, q, totalChannel, mainChannel, shearStress); ingo@2827: ingo@2827: session.save(peer); ingo@2827: } ingo@2827: else { ingo@2827: peer = values.get(0); ingo@2827: } ingo@2827: } ingo@2827: ingo@2827: return peer; ingo@2827: } ingo@2827: } ingo@2827: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :