view backend/src/main/java/org/dive4elements/river/model/RiverAxis.java @ 6229:3fea9701d58d

Fix gauge determination. If we look upstream ( a > b ) we still have to compare the start value of our range against the gauge and not the end value. The start value is always the relevant value as we handle the direction by checking this against A or B of the gauge. Also: I will never compare doubles with == again. I will never compare doubles with == again. I will never compare doubles with == again. I will never compare doubles with == again. I will never compare doubles with == again.
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 06 Jun 2013 18:23:17 +0200
parents 4c3ccf2b0304
children e9d912c97fa8
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.model;

import com.vividsolutions.jts.geom.MultiLineString;

import java.io.Serializable;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.dive4elements.river.backend.SessionHolder;

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

import org.hibernate.annotations.Type;

/**
 * A river has one axis that is used for calculation.
 * Additional axes of a river can be used to be painted int maps etc.
 * which one is the main river axis can be determined over the axis kind.
 */
@Entity
@Table(name = "river_axes")
public class RiverAxis
implements   Serializable
{
    private Integer    id;
    private AxisKind   kind;
    private River      river;
    private String     name;
    private MultiLineString geom;

    public static final int KIND_UNKOWN = 0;
    public static final int KIND_CURRENT = 1;
    public static final int KIND_OTHER = 2;

    public RiverAxis() {
    }


    @Id
    @Column(name = "id")
    public Integer getId() {
        return id;
    }


    public void setId(Integer id) {
        this.id = id;
    }


    @OneToOne
    @JoinColumn(name = "river_id")
    public River getRiver() {
        return river;
    }


    public void setRiver(River river) {
        this.river = river;
    }

    @Column(name = "name")
    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name;
    }

    /**
     * Get kind.
     *
     * @return kind as AxisKind.
     */
    @OneToOne
    @JoinColumn(name = "kind_id")
    public AxisKind getKind() {
        return kind;
    }

    /**
     * Set kind.
     *
     * @param kind the value to set.
     */
    public void setKind(AxisKind kind) {
        this.kind = kind;
    }


    @Column(name = "geom")
    @Type(type = "org.hibernatespatial.GeometryUserType")
    public MultiLineString getGeom() {
        return geom;
    }


    public void setGeom(MultiLineString geom) {
        this.geom = geom;
    }


    public static List<RiverAxis> getRiverAxis(String river)
    throws IllegalArgumentException {
        return getRiverAxis(river, KIND_CURRENT);
    }

    public static List<RiverAxis> getRiverAxis(String river, String name, int kind)
    throws HibernateException {
        Session session = SessionHolder.HOLDER.get();
        Query query = session.createQuery(
            "from RiverAxis as ax where river.name =:river" +
            " and kind.id =:kind" +
            " and ax.name=:name");
        query.setParameter("river", river);
        query.setParameter("kind", kind);
        query.setParameter("name", name);

        List<RiverAxis> list = query.list();
        return list.isEmpty() ? null : list;
    }

    public static List<RiverAxis> getRiverAxis(String river, int kind)
    throws HibernateException {
        Session session = SessionHolder.HOLDER.get();
        Query query = session.createQuery(
            "from RiverAxis where river.name =:river AND kind.id =:kind");
        query.setParameter("river", river);
        query.setParameter("kind", kind);

        List<RiverAxis> list = query.list();
        return list.isEmpty() ? null : list;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org