ingo@1236: package de.intevation.flys.model; ingo@1236: ingo@1236: import java.io.Serializable; ingo@1236: import java.util.List; ingo@1236: import java.math.BigDecimal; ingo@1236: ingo@1236: import javax.persistence.Column; ingo@1236: import javax.persistence.Entity; ingo@1236: import javax.persistence.Id; ingo@1236: import javax.persistence.JoinColumn; ingo@1236: import javax.persistence.OneToOne; ingo@1236: import javax.persistence.Table; ingo@1236: ingo@1236: import org.hibernate.Session; ingo@1236: import org.hibernate.Query; ingo@1236: ingo@1236: import de.intevation.flys.backend.SessionHolder; ingo@1236: ingo@1236: ingo@1236: @Entity ingo@1240: @Table(name = "dem") ingo@1236: public class DGM implements Serializable { ingo@1236: ingo@1236: private Integer id; ingo@1236: ingo@1236: private River river; ingo@1236: ingo@1236: private BigDecimal lower; ingo@1236: private BigDecimal upper; ingo@1236: ingo@1236: private String path; ingo@1236: ingo@1236: ingo@1236: public DGM() { ingo@1236: } ingo@1236: ingo@1236: ingo@1236: public void setId(Integer id) { ingo@1236: this.id = id; ingo@1236: } ingo@1236: ingo@1236: @Id ingo@1236: @Column(name = "id") ingo@1236: public Integer getId() { ingo@1236: return id; ingo@1236: } ingo@1236: ingo@1236: public void setRiver(River river) { ingo@1236: this.river = river; ingo@1236: } ingo@1236: ingo@1236: @OneToOne ingo@1236: @JoinColumn(name = "river_id") ingo@1236: public River getRiver() { ingo@1236: return river; ingo@1236: } ingo@1236: ingo@1236: public void setLower(BigDecimal lower) { ingo@1236: this.lower = lower; ingo@1236: } ingo@1236: ingo@1236: @Column(name = "lower") ingo@1236: public BigDecimal getLower() { ingo@1236: return lower; ingo@1236: } ingo@1236: ingo@1236: public void setUpper(BigDecimal upper) { ingo@1236: this.upper = upper; ingo@1236: } ingo@1236: ingo@1236: @Column(name = "upper") ingo@1236: public BigDecimal getUpper() { ingo@1236: return upper; ingo@1236: } ingo@1236: ingo@1236: public void setPath(String path) { ingo@1236: this.path = path; ingo@1236: } ingo@1236: ingo@1236: @Column(name = "path") ingo@1236: public String getPath() { ingo@1236: return path; ingo@1236: } ingo@1236: ingo@1236: ingo@1236: public static DGM getDGM(String river, double lower, double upper) { ingo@1236: Session session = SessionHolder.HOLDER.get(); ingo@1236: ingo@1236: Query query = session.createQuery( ingo@1236: "from DGM where river.name =:river and " + ingo@1236: "lower <=:lower and upper >=:lower and " + ingo@1236: "lower <=:upper and upper >=:upper"); ingo@1236: query.setParameter("river", river); ingo@1236: query.setParameter("lower", new BigDecimal(lower)); ingo@1236: query.setParameter("upper", new BigDecimal(upper)); ingo@1236: ingo@1236: List result = query.list(); ingo@1236: ingo@1236: return result.isEmpty() ? null : result.get(0); ingo@1236: } ingo@1236: } ingo@1236: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :