ingo@2825: package de.intevation.flys.model;
ingo@2825: 
ingo@2825: import java.io.Serializable;
ingo@2825: import java.math.BigDecimal;
ingo@2870: import java.util.List;
ingo@2825: 
ingo@2825: import javax.persistence.Entity;
ingo@2825: import javax.persistence.Id;
ingo@2825: import javax.persistence.Table;
ingo@2825: import javax.persistence.GeneratedValue;
ingo@2825: import javax.persistence.Column;
ingo@2825: import javax.persistence.SequenceGenerator;
ingo@2825: import javax.persistence.GenerationType;
ingo@2825: import javax.persistence.JoinColumn;
ingo@2825: import javax.persistence.OneToOne;
ingo@2825: 
ingo@2870: import org.hibernate.Session;
ingo@2870: import org.hibernate.Query;
ingo@2870: 
ingo@2825: import org.apache.log4j.Logger;
ingo@2825: 
ingo@2870: import de.intevation.flys.backend.SessionHolder;
ingo@2870: 
ingo@2825: 
ingo@2825: @Entity
ingo@2825: @Table(name = "discharge_zone")
ingo@2825: public class DischargeZone
ingo@2825: implements   Serializable
ingo@2825: {
ingo@2825:     private static Logger logger = Logger.getLogger(DischargeZone.class);
ingo@2825: 
ingo@2825: 
ingo@2825:     private Integer id;
ingo@2825: 
ingo@2825:     private River river;
ingo@2825: 
ingo@2833:     private String gaugeName;
ingo@2825: 
ingo@2833:     private BigDecimal value;
ingo@2825: 
ingo@2833:     private String lowerDischarge;
ingo@2833:     private String upperDischarge;
ingo@2825: 
ingo@2825: 
ingo@2825:     public DischargeZone() {
ingo@2825:     }
ingo@2825: 
ingo@2825: 
ingo@2825:     public DischargeZone(
ingo@2833:         River       river,
ingo@2833:         String      gaugeName,
ingo@2833:         BigDecimal  value,
ingo@2833:         String      lowerDischarge,
ingo@2833:         String      upperDischarge
ingo@2825:     ) {
ingo@2833:         this.river          = river;
ingo@2833:         this.gaugeName      = gaugeName;
ingo@2833:         this.value          = value;
ingo@2833:         this.lowerDischarge = lowerDischarge;
ingo@2833:         this.upperDischarge = upperDischarge;
ingo@2825:     }
ingo@2825: 
ingo@2825:     @Id
ingo@2825:     @SequenceGenerator(
ingo@2825:         name           = "SEQUENCE_DISCHARGE_ZONE_ID_SEQ",
ingo@2825:         sequenceName   = "DISCHARGE_ZONE_ID_SEQ",
ingo@2825:         allocationSize = 1)
ingo@2825:     @GeneratedValue(
ingo@2825:         strategy  = GenerationType.SEQUENCE,
ingo@2825:         generator = "SEQUENCE_DISCHARGE_ZONE_ID_SEQ")
ingo@2825:     @Column(name = "id")
ingo@2825:     public Integer getId() {
ingo@2825:         return id;
ingo@2825:     }
ingo@2825: 
ingo@2825:     public void setId(Integer id) {
ingo@2825:         this.id = id;
ingo@2825:     }
ingo@2825: 
ingo@2825:     @OneToOne
ingo@2825:     @JoinColumn(name = "river_id" )
ingo@2825:     public River getRiver() {
ingo@2825:         return river;
ingo@2825:     }
ingo@2825: 
ingo@2825:     public void setRiver(River river) {
ingo@2825:         this.river = river;
ingo@2825:     }
ingo@2825: 
ingo@2833:     @Column(name = "value")
ingo@2833:     public BigDecimal getValue() {
ingo@2833:         return value;
ingo@2825:     }
ingo@2825: 
ingo@2833:     public void setValue(BigDecimal value) {
ingo@2833:         this.value = value;
ingo@2825:     }
ingo@2825: 
ingo@2825:     @Column(name = "gauge_name")
ingo@2825:     public String getGaugeName() {
ingo@2825:         return gaugeName;
ingo@2825:     }
ingo@2825: 
ingo@2825:     public void setGaugeName(String gaugeName) {
ingo@2825:         this.gaugeName = gaugeName;
ingo@2825:     }
ingo@2825: 
ingo@2833:     @Column(name = "lower_discharge")
ingo@2833:     public String getLowerDischarge() {
ingo@2833:         return lowerDischarge;
ingo@2825:     }
ingo@2825: 
ingo@2833:     public void setLowerDischarge(String lowerDischarge) {
ingo@2833:         this.lowerDischarge = lowerDischarge;
ingo@2825:     }
ingo@2825: 
ingo@2833:     @Column(name = "upper_discharge")
ingo@2833:     public String getUpperDischarge() {
ingo@2833:         return upperDischarge;
ingo@2825:     }
ingo@2825: 
ingo@2833:     public void setUpperDischarge(String upperDischarge) {
ingo@2833:         this.upperDischarge = upperDischarge;
ingo@2825:     }
ingo@2870: 
ingo@2870: 
ingo@2870:     public static List<DischargeZone> getDischargeZones(River river) {
ingo@2870:         Session session = SessionHolder.HOLDER.get();
ingo@2870: 
ingo@2870:         Query query = session.createQuery(
ingo@2870:             "from DischargeZone where river=:river");
ingo@2870: 
ingo@2870:         query.setParameter("river", river);
ingo@2870: 
ingo@2870:         return query.list();
ingo@2870:     }
ingo@2871: 
ingo@2871: 
ingo@2871:     public static DischargeZone getDischargeZoneById(int id) {
ingo@2871:         Session session = SessionHolder.HOLDER.get();
ingo@2871: 
ingo@2871:         Query query = session.createQuery(
ingo@2871:             "from DischargeZone where id=:id");
ingo@2871: 
ingo@2871:         query.setParameter("id", id);
ingo@2871: 
ingo@2871:         List<DischargeZone> zones = query.list();
ingo@2871: 
ingo@2871:         return zones.isEmpty() ? null : zones.get(0);
ingo@2871:     }
ingo@2825: }
ingo@2825: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :