Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadValue.java @ 8032:fd3a24336e6a
SCHEMA CHANGE and Importer (only longitudinal section data so far): only grain fractions given now in schema are valid. We are handling sediment loads, not yields.
author | "Tom Gottfried <tom@intevation.de>" |
---|---|
date | Mon, 14 Jul 2014 15:36:44 +0200 |
parents | aa054f72e887 |
children | d86cc6a17b7a |
line wrap: on
line source
package org.dive4elements.river.importer; import java.util.List; import org.dive4elements.river.model.MeasurementStation; import org.dive4elements.river.model.River; import org.dive4elements.river.model.SedimentLoad; import org.dive4elements.river.model.SedimentLoadValue; import org.hibernate.Query; import org.hibernate.Session; public class ImportSedimentLoadValue { private SedimentLoadValue peer; private ImportMeasurementStation station; private ImportSedimentLoad sedimentLoad; private Double value; public ImportSedimentLoadValue() { } public ImportSedimentLoadValue( ImportMeasurementStation station, ImportSedimentLoad sedimentLoad, Double value ) { this.station = station; this.sedimentLoad = sedimentLoad; this.value = value; } protected SedimentLoadValue getPeer(River river) { if (peer == null) { Session session = ImporterSession.getInstance().getDatabaseSession(); Query query = session.createQuery( "from SedimentLoadValue where " + " station = :station and " + " sedimentLoad = :sedimentLoad and " + " value = :value"); MeasurementStation ms = station.getPeer(river); SedimentLoad sl = sedimentLoad.getPeer(); query.setParameter("station", ms); query.setParameter("sedimentLoad", sl); query.setParameter("value", value); List<SedimentLoadValue> values = query.list(); if (values.isEmpty()) { peer = new SedimentLoadValue(sl, ms, value); session.save(peer); } else { peer = values.get(0); } } return peer; } public void storeDependencies(River river) { station.storeDependencies(river); sedimentLoad.storeDependencies(); getPeer(river); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :