Mercurial > dive4elements > river
diff 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 diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadValue.java Thu Jul 10 16:57:32 2014 +0200 @@ -0,0 +1,69 @@ +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 :