teichmann@8028: package org.dive4elements.river.importer; teichmann@8028: teichmann@8028: import java.util.List; teichmann@8028: teichmann@8028: import org.dive4elements.river.model.MeasurementStation; teichmann@8028: import org.dive4elements.river.model.River; teichmann@8028: import org.dive4elements.river.model.SedimentLoad; teichmann@8028: import org.dive4elements.river.model.SedimentLoadValue; teichmann@8028: import org.hibernate.Query; teichmann@8028: import org.hibernate.Session; teichmann@8028: teichmann@8028: public class ImportSedimentLoadValue { teichmann@8028: teichmann@8028: private SedimentLoadValue peer; teichmann@8028: teichmann@8028: private ImportMeasurementStation station; teichmann@8028: private ImportSedimentLoad sedimentLoad; teichmann@8028: private Double value; teichmann@8028: teichmann@8028: public ImportSedimentLoadValue() { teichmann@8028: } teichmann@8028: teichmann@8028: public ImportSedimentLoadValue( teichmann@8028: ImportMeasurementStation station, teichmann@8028: ImportSedimentLoad sedimentLoad, teichmann@8028: Double value teichmann@8028: ) { teichmann@8028: this.station = station; teichmann@8028: this.sedimentLoad = sedimentLoad; teichmann@8028: this.value = value; teichmann@8028: } teichmann@8028: teichmann@8028: protected SedimentLoadValue getPeer(River river) { teichmann@8028: teichmann@8028: if (peer == null) { teichmann@8028: Session session = ImporterSession.getInstance().getDatabaseSession(); teichmann@8028: Query query = session.createQuery( teichmann@8028: "from SedimentLoadValue where " + teichmann@8028: " station = :station and " + teichmann@8028: " sedimentLoad = :sedimentLoad and " + teichmann@8028: " value = :value"); teichmann@8028: teichmann@8028: MeasurementStation ms = station.getPeer(river); teichmann@8028: SedimentLoad sl = sedimentLoad.getPeer(); teichmann@8028: teichmann@8028: query.setParameter("station", ms); teichmann@8028: query.setParameter("sedimentLoad", sl); teichmann@8028: query.setParameter("value", value); teichmann@8028: teichmann@8028: List values = query.list(); teichmann@8028: if (values.isEmpty()) { teichmann@8028: peer = new SedimentLoadValue(sl, ms, value); teichmann@8028: session.save(peer); teichmann@8028: } teichmann@8028: else { teichmann@8028: peer = values.get(0); teichmann@8028: } teichmann@8028: } teichmann@8028: teichmann@8028: return peer; teichmann@8028: } teichmann@8028: teichmann@8028: public void storeDependencies(River river) { teichmann@8028: station.storeDependencies(river); teichmann@8028: sedimentLoad.storeDependencies(); teichmann@8028: getPeer(river); teichmann@8028: } teichmann@8028: } teichmann@8028: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :