Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadValue.java @ 8028:aa054f72e887
Added importer models for sediment load and sediment load values.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 10 Jul 2014 16:57:32 +0200 |
parents | |
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 :