teichmann@5844: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5844: * Software engineering by Intevation GmbH teichmann@5844: * teichmann@5992: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5844: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5992: * documentation coming with Dive4Elements River for details. teichmann@5844: */ teichmann@5844: teichmann@5829: package org.dive4elements.river.importer; sascha@1218: mschaefer@8986: import java.math.BigDecimal; mschaefer@8986: import java.util.List; mschaefer@8986: mschaefer@8986: import org.dive4elements.river.importer.common.StoreMode; teichmann@5829: import org.dive4elements.river.model.HYKFlowZone; teichmann@5829: import org.dive4elements.river.model.HYKFlowZoneType; mschaefer@8986: import org.dive4elements.river.model.HYKFormation; sascha@1218: import org.hibernate.Query; mschaefer@8986: import org.hibernate.Session; sascha@1218: sascha@1218: public class ImportHYKFlowZone sascha@1218: { sascha@1218: protected ImportHYKFormation formation; sascha@1218: protected ImportHYKFlowZoneType type; sascha@1218: protected BigDecimal a; sascha@1218: protected BigDecimal b; sascha@1218: sascha@1218: protected HYKFlowZone peer; sascha@1218: sascha@1218: public ImportHYKFlowZone() { sascha@1218: } sascha@1218: sascha@1218: public ImportHYKFlowZone( mschaefer@8986: final ImportHYKFormation formation, mschaefer@8986: final ImportHYKFlowZoneType type, mschaefer@8986: final BigDecimal a, mschaefer@8986: final BigDecimal b mschaefer@8986: ) { sascha@1218: this.formation = formation; sascha@1218: this.type = type; sascha@1218: this.a = a; sascha@1218: this.b = b; sascha@1218: } sascha@1218: sascha@1218: public ImportHYKFormation getFormation() { mschaefer@8986: return this.formation; sascha@1218: } sascha@1218: mschaefer@8986: public void setFormation(final ImportHYKFormation formation) { sascha@1218: this.formation = formation; sascha@1218: } sascha@1218: sascha@1221: public void storeDependencies() { sascha@1221: getPeer(); sascha@1221: } sascha@1221: sascha@1218: public HYKFlowZone getPeer() { mschaefer@8986: if (this.peer == null) { mschaefer@8986: final HYKFormation f = this.formation.getPeer(); mschaefer@8986: final HYKFlowZoneType t = this.type.getPeer(); mschaefer@8986: final Session session = ImporterSession.getInstance() mschaefer@8986: .getDatabaseSession(); mschaefer@8986: List zones; mschaefer@8986: if (this.formation.storeMode == StoreMode.INSERT) mschaefer@8986: zones = null; mschaefer@8986: { mschaefer@8986: final Query query = session.createQuery( mschaefer@8986: "from HYKFlowZone where formation=:formation " + mschaefer@8986: "and type=:type and a=:a and b=:b"); mschaefer@8986: query.setParameter("formation", f); mschaefer@8986: query.setParameter("type", t); mschaefer@8986: query.setParameter("a", this.a); mschaefer@8986: query.setParameter("b", this.b); mschaefer@8986: zones = query.list(); mschaefer@8986: } mschaefer@8986: if ((zones == null) || zones.isEmpty()) { mschaefer@8986: this.peer = new HYKFlowZone(f, t, this.a, this.b); mschaefer@8986: session.save(this.peer); sascha@1218: } sascha@1218: else { mschaefer@8986: this.peer = zones.get(0); sascha@1218: } sascha@3334: sascha@1218: } mschaefer@8986: return this.peer; sascha@1218: } sascha@1218: } sascha@1218: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :