view flys-backend/src/main/java/de/intevation/flys/importer/ImportHYKFlowZone.java @ 4173:7d4480c0e68e

Allow users to select the current relevant discharge table in historical discharge table calculattion. In addition to this, the discharge tables in the helper panel displayed in the client is ordered in time.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 18 Oct 2012 12:13:48 +0200
parents 2ae732e2c65c
children
line wrap: on
line source
package de.intevation.flys.importer;

import de.intevation.flys.model.HYKFormation;
import de.intevation.flys.model.HYKFlowZone;
import de.intevation.flys.model.HYKFlowZoneType;

import org.hibernate.Session;
import org.hibernate.Query;

import java.util.List;

import java.math.BigDecimal;

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

    protected HYKFlowZone peer;

    public ImportHYKFlowZone() {
    }

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

    public ImportHYKFormation getFormation() {
        return formation;
    }

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

    public void storeDependencies() {
        getPeer();
    }

    public HYKFlowZone getPeer() {
        if (peer == null) {
            HYKFormation    f = formation.getPeer();
            HYKFlowZoneType t = type.getPeer();
            Session session = ImporterSession.getInstance()
                .getDatabaseSession();
            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", a);
            query.setParameter("b", b);
            List<HYKFlowZone> zones = query.list();
            if (zones.isEmpty()) {
                peer = new HYKFlowZone(f, t, a, b);
                session.save(peer);
            }
            else {
                peer = zones.get(0);
            }

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

http://dive4elements.wald.intevation.org