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; aheinecke@5098: import javax.persistence.GeneratedValue; aheinecke@5098: import javax.persistence.GenerationType; ingo@1236: import javax.persistence.Id; ingo@1236: import javax.persistence.JoinColumn; ingo@1236: import javax.persistence.OneToOne; ingo@1236: import javax.persistence.Table; aheinecke@5098: import javax.persistence.SequenceGenerator; 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: aheinecke@5210: private Integer id; aheinecke@5210: private Integer srid; ingo@1236: aheinecke@5210: private River river; ingo@1236: aheinecke@5210: private Range range; aheinecke@5210: private TimeInterval time_interval; ingo@1236: aheinecke@5210: 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 aheinecke@5098: @SequenceGenerator( aheinecke@5098: name = "SEQUENCE_DEM_ID_SEQ", aheinecke@5098: sequenceName = "DEM_ID_SEQ", aheinecke@5098: allocationSize = 1) aheinecke@5098: @GeneratedValue( aheinecke@5098: strategy = GenerationType.SEQUENCE, aheinecke@5098: generator = "SEQUENCE_DEM_ID_SEQ") 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 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: aheinecke@5059: public void setSrid(int srid) { aheinecke@5059: this.srid = srid; aheinecke@5059: } aheinecke@5059: aheinecke@5059: @Column(name = "srid") aheinecke@5059: public int getSrid() { aheinecke@5059: return srid; aheinecke@5059: } ingo@1236: ingo@1257: public static DGM getDGM(int id) { ingo@1257: Session session = SessionHolder.HOLDER.get(); ingo@1257: ingo@1257: Query query = session.createQuery( ingo@1257: "from DGM where Id =:id"); ingo@1257: query.setParameter("id", id); ingo@1257: ingo@1257: List result = query.list(); ingo@1257: ingo@1257: return result.isEmpty() ? null : result.get(0); ingo@1257: } ingo@1257: ingo@1257: 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 " + aheinecke@5210: "range.a <=:lower and range.b >=:lower and " + aheinecke@5210: "range.a <=:upper and range.b >=: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: } aheinecke@5210: aheinecke@5210: @OneToOne aheinecke@5210: @JoinColumn(name = "range_id") aheinecke@5210: public Range getRange() { aheinecke@5210: return range; aheinecke@5210: } aheinecke@5210: aheinecke@5210: public void setRange(Range range) { aheinecke@5210: this.range = range; aheinecke@5210: } aheinecke@5210: aheinecke@5210: @OneToOne aheinecke@5210: @JoinColumn(name = "time_interval_id") aheinecke@5210: public TimeInterval getTimeInterval() { aheinecke@5210: return time_interval; aheinecke@5210: } aheinecke@5210: aheinecke@5210: public void setTimeInterval(TimeInterval time_interval) { aheinecke@5210: this.time_interval = time_interval; aheinecke@5210: } aheinecke@5210: aheinecke@5210: ingo@1236: } ingo@1236: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :