mschaefer@8971: /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde mschaefer@8971: * Software engineering by mschaefer@8971: * Björnsen Beratende Ingenieure GmbH mschaefer@8971: * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt mschaefer@8971: * mschaefer@8971: * This file is Free Software under the GNU AGPL (>=v3) mschaefer@8971: * and comes with ABSOLUTELY NO WARRANTY! Check out the mschaefer@8971: * documentation coming with Dive4Elements River for details. mschaefer@8971: */ mschaefer@8971: mschaefer@8971: package org.dive4elements.river.importer.sinfo.importitem; mschaefer@8971: mschaefer@8971: import java.util.List; mschaefer@8971: mschaefer@8971: import org.dive4elements.river.importer.ImportAttribute; mschaefer@8971: import org.dive4elements.river.importer.common.AbstractKmLineImport; mschaefer@8971: import org.dive4elements.river.model.sinfo.Infrastructure; mschaefer@8971: import org.dive4elements.river.model.sinfo.InfrastructureValue; mschaefer@8971: import org.hibernate.Query; mschaefer@8971: import org.hibernate.Session; mschaefer@8971: mschaefer@8971: /** mschaefer@8971: * Imported infrastructure of a river station. mschaefer@8971: * mschaefer@8971: * @author Matthias Schäfer mschaefer@8971: * mschaefer@8971: */ mschaefer@8971: public class InfrastructureKmLineImport extends AbstractKmLineImport { mschaefer@8971: mschaefer@8971: /***** FIELDS *****/ mschaefer@8971: mschaefer@8971: private double height; mschaefer@8971: mschaefer@8971: private final ImportAttribute bankAttribute; mschaefer@8971: mschaefer@8971: mschaefer@8971: /***** CONSTRUCTOR *****/ mschaefer@8971: mschaefer@8971: public InfrastructureKmLineImport(final Double km, final double height, final ImportAttribute bankAttribute) { mschaefer@8971: super(km.doubleValue()); mschaefer@8971: this.height = height; mschaefer@8971: this.bankAttribute = bankAttribute; mschaefer@8971: } mschaefer@8971: mschaefer@8971: mschaefer@8971: /***** METHODS *****/ mschaefer@8971: mschaefer@8971: public void setHeight(final double height) { mschaefer@8971: this.height = height; mschaefer@8971: } mschaefer@8971: mschaefer@9659: public ImportAttribute getBankAttribute() { mschaefer@9659: return this.bankAttribute; mschaefer@9659: } mschaefer@9659: mschaefer@8971: @Override mschaefer@8971: protected InfrastructureValue queryValueItem(final Session session, final Infrastructure parent) { mschaefer@8971: final Query query = session.createQuery("FROM InfrastructureValue WHERE (infrastructure=:parent) AND (attribute=:bank)" mschaefer@8971: + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))"); mschaefer@8971: query.setParameter("parent", parent); mschaefer@8971: query.setParameter("station", this.station); mschaefer@8971: query.setParameter("bank", this.bankAttribute.getPeer()); mschaefer@8971: final List rows = query.list(); mschaefer@8971: if (!rows.isEmpty()) mschaefer@8971: return (InfrastructureValue) rows.get(0); mschaefer@8971: else mschaefer@8971: return null; mschaefer@8971: } mschaefer@8971: mschaefer@8971: mschaefer@8971: @Override mschaefer@8971: protected InfrastructureValue createValueItem(final Infrastructure parent) { mschaefer@8971: return new InfrastructureValue(parent, this.station, this.bankAttribute.getPeer(), this.height); mschaefer@8971: } mschaefer@8971: } mschaefer@8971: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :