teichmann@8028: package org.dive4elements.river.importer; teichmann@8028: teichmann@8028: import java.util.List; teichmann@8028: teichmann@8028: import org.dive4elements.river.model.GrainFraction; teichmann@8028: import org.dive4elements.river.model.SedimentLoad; teichmann@8028: import org.dive4elements.river.model.TimeInterval; teichmann@8028: import org.hibernate.Query; teichmann@8028: import org.hibernate.Session; teichmann@8028: teichmann@8028: public class ImportSedimentLoad teichmann@8028: { teichmann@8028: private SedimentLoad peer; teichmann@8028: teichmann@8028: private ImportGrainFraction grainFraction; teichmann@8028: private ImportTimeInterval timeInterval; teichmann@8028: private ImportTimeInterval sqTimeInterval; teichmann@8028: private String description; teichmann@8028: private Integer kind; teichmann@8028: teichmann@8028: public ImportSedimentLoad() { teichmann@8028: } teichmann@8028: teichmann@8028: public void storeDependencies() { teichmann@8028: grainFraction.getPeer(); teichmann@8028: timeInterval.getPeer(); teichmann@8028: sqTimeInterval.getPeer(); teichmann@8028: teichmann@8028: getPeer(); teichmann@8028: } teichmann@8028: teichmann@8028: public SedimentLoad getPeer() { teichmann@8028: teichmann@8028: if (peer == null) { teichmann@8028: Session session = ImporterSession.getInstance().getDatabaseSession(); teichmann@8028: Query query = session.createQuery( teichmann@8028: "from SedimentLoad where " + teichmann@8028: " grainFraction = :grainFraction and " + teichmann@8028: " timeInterval = :timeInterval and " + teichmann@8028: " sqTimeInterval = :sqTimeInterval and " + teichmann@8028: " description = :description and " + teichmann@8028: " kind = :kind"); teichmann@8028: teichmann@8028: GrainFraction gf = grainFraction.getPeer(); teichmann@8028: TimeInterval ti = timeInterval.getPeer(); teichmann@8028: teichmann@8028: TimeInterval sqti = sqTimeInterval != null teichmann@8028: ? sqTimeInterval.getPeer() teichmann@8028: : null; teichmann@8028: teichmann@8028: query.setParameter("grainFraction", gf); teichmann@8028: query.setParameter("timeInterval", ti); teichmann@8028: query.setParameter("sqTimeInterval", sqti); teichmann@8028: query.setParameter("description", description); teichmann@8028: query.setParameter("kind", kind); teichmann@8028: teichmann@8028: List loads = query.list(); teichmann@8028: if (loads.isEmpty()) { teichmann@8028: peer = new SedimentLoad(gf, ti, sqti, description, kind); teichmann@8028: session.save(peer); teichmann@8028: } teichmann@8028: else { teichmann@8028: peer = loads.get(0); teichmann@8028: } teichmann@8028: } teichmann@8028: teichmann@8028: return peer; teichmann@8028: } teichmann@8028: } teichmann@8028: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :