view backend/src/main/java/org/dive4elements/river/importer/ImportHYKFlowZone.java @ 9709:b74f817435fe

comment removed
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Wed, 27 Jan 2021 11:47:38 +0100
parents 392bbcd8a88b
children
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.importer;

import java.math.BigDecimal;
import java.util.List;

import org.dive4elements.river.importer.common.StoreMode;
import org.dive4elements.river.model.HYKFlowZone;
import org.dive4elements.river.model.HYKFlowZoneType;
import org.dive4elements.river.model.HYKFormation;
import org.hibernate.Query;
import org.hibernate.Session;

public class ImportHYKFlowZone
{
    protected ImportHYKFormation    formation;
    protected ImportHYKFlowZoneType type;
    protected BigDecimal            a;
    protected BigDecimal            b;

    protected HYKFlowZone peer;

    public ImportHYKFlowZone() {
    }

    public ImportHYKFlowZone(
            final ImportHYKFormation    formation,
            final ImportHYKFlowZoneType type,
            final BigDecimal            a,
            final BigDecimal            b
            ) {
        this.formation = formation;
        this.type      = type;
        this.a         = a;
        this.b         = b;
    }

    public ImportHYKFormation getFormation() {
        return this.formation;
    }

    public void setFormation(final ImportHYKFormation formation) {
        this.formation = formation;
    }

    public void storeDependencies() {
        getPeer();
    }

    public HYKFlowZone getPeer() {
        if (this.peer == null) {
            final HYKFormation    f = this.formation.getPeer();
            final HYKFlowZoneType t = this.type.getPeer();
            final Session session = ImporterSession.getInstance()
                    .getDatabaseSession();
            List<HYKFlowZone> zones;
            if (this.formation.storeMode == StoreMode.INSERT)
                zones = null;
            {
                final Query query = session.createQuery(
                        "from HYKFlowZone where formation=:formation " +
                        "and type=:type and a=:a and b=:b");
                query.setParameter("formation", f);
                query.setParameter("type", t);
                query.setParameter("a", this.a);
                query.setParameter("b", this.b);
                zones = query.list();
            }
            if ((zones == null) || zones.isEmpty()) {
                this.peer = new HYKFlowZone(f, t, this.a, this.b);
                session.save(this.peer);
            }
            else {
                this.peer = zones.get(0);
            }

        }
        return this.peer;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org