view flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java @ 5510:d4bee6d5c866

merged
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 28 Mar 2013 16:51:32 +0100
parents ae60bb7b8085
children
line wrap: on
line source
package de.intevation.flys.model;

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.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Query;
import org.hibernate.annotations.Type;

import com.vividsolutions.jts.geom.MultiLineString;

import de.intevation.flys.backend.SessionHolder;
import de.intevation.flys.model.AxisKind;


/**
 * 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