view flys-backend/src/main/java/de/intevation/flys/model/DGM.java @ 5152:b26465581abf

Add a configurable path prefix to relative DGM path to allways have an absolute path.
author Raimund Renkert <rrenkert@intevation.de>
date Fri, 01 Mar 2013 10:35:38 +0100
parents a2600507761e
children 908848b74d7e
line wrap: on
line source
package de.intevation.flys.model;

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

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.SequenceGenerator;

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

import de.intevation.flys.backend.SessionHolder;


@Entity
@Table(name = "dem")
public class DGM implements Serializable {

    private Integer    id;
    private Integer    srid;

    private River      river;

    private BigDecimal lower;
    private BigDecimal upper;

    private String     path;


    public DGM() {
    }


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

    @Id
    @SequenceGenerator(
        name           = "SEQUENCE_DEM_ID_SEQ",
        sequenceName   = "DEM_ID_SEQ",
        allocationSize = 1)
    @GeneratedValue(
        strategy  = GenerationType.SEQUENCE,
        generator = "SEQUENCE_DEM_ID_SEQ")
    @Column(name = "id")
    public Integer getId() {
        return id;
    }

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

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

    public void setLower(BigDecimal lower) {
        this.lower = lower;
    }

    @Column(name = "lower")
    public BigDecimal getLower() {
        return lower;
    }

    public void setUpper(BigDecimal upper) {
        this.upper = upper;
    }

    @Column(name = "upper")
    public BigDecimal getUpper() {
        return upper;
    }

    public void setPath(String path) {
        this.path = path;
    }

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

    public void setSrid(int srid) {
        this.srid = srid;
    }

    @Column(name = "srid")
    public int getSrid() {
        return srid;
    }

    public static DGM getDGM(int id) {
        Session session = SessionHolder.HOLDER.get();

        Query query = session.createQuery(
            "from DGM where Id =:id");
        query.setParameter("id", id);

        List<DGM> result = query.list();

        return result.isEmpty() ? null : result.get(0);
    }


    public static DGM getDGM(String river, double lower, double upper) {
        Session session = SessionHolder.HOLDER.get();

        Query query = session.createQuery(
            "from DGM where river.name =:river and " +
            "lower <=:lower and upper >=:lower and " +
            "lower <=:upper and upper >=:upper");
        query.setParameter("river", river);
        query.setParameter("lower", new BigDecimal(lower));
        query.setParameter("upper", new BigDecimal(upper));

        List<DGM> result = query.list();

        return result.isEmpty() ? null : result.get(0);
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org