view flys-backend/src/main/java/de/intevation/flys/model/RiverAxis.java @ 5192:1b6d4edeeb4c

Fix variable assignments after rename
author Andre Heinecke <aheinecke@intevation.de>
date Thu, 07 Mar 2013 16:06:44 +0100
parents 9d36ddf7dbd3
children ae60bb7b8085
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 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;
    }


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