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.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: tom@8056: private MeasurementStation station; tom@8056: private Double value; teichmann@8028: teichmann@8028: public ImportSedimentLoadValue() { teichmann@8028: } teichmann@8028: teichmann@8028: public ImportSedimentLoadValue( tom@8056: MeasurementStation station, tom@8056: Double value teichmann@8028: ) { teichmann@8028: this.station = station; teichmann@8028: this.value = value; teichmann@8028: } teichmann@8028: tom@8056: protected SedimentLoadValue getPeer(SedimentLoad sedimentLoad) { 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 " + tom@8056: " measurementStation = :station and " + teichmann@8028: " sedimentLoad = :sedimentLoad and " + teichmann@8028: " value = :value"); teichmann@8028: tom@8056: query.setParameter("station", station); tom@8056: query.setParameter("sedimentLoad", sedimentLoad); teichmann@8028: query.setParameter("value", value); teichmann@8028: teichmann@8028: List values = query.list(); teichmann@8028: if (values.isEmpty()) { tom@8056: peer = new SedimentLoadValue(sedimentLoad, station, 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: tom@8056: public void storeDependencies(SedimentLoad sedimentLoad) { tom@8056: getPeer(sedimentLoad); teichmann@8028: } teichmann@8028: } teichmann@8028: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :