ingo@2825: package de.intevation.flys.model;
ingo@2825: 
ingo@2825: import java.io.Serializable;
ingo@2825: 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@2871: import org.hibernate.Session;
ingo@2871: import org.hibernate.Query;
ingo@2871: 
ingo@2825: import org.apache.log4j.Logger;
ingo@2825: 
ingo@2871: import de.intevation.flys.backend.SessionHolder;
ingo@2871: 
ingo@2825: 
ingo@2825: @Entity
ingo@2825: @Table(name = "flow_velocity_model")
ingo@2825: public class FlowVelocityModel
ingo@2825: implements   Serializable
ingo@2825: {
ingo@2825:     private static Logger logger = Logger.getLogger(FlowVelocityModel.class);
ingo@2825: 
ingo@2825: 
ingo@2825:     private Integer id;
ingo@2825: 
ingo@2825:     private River river;
ingo@2825: 
ingo@2825:     private DischargeZone dischargeZone;
ingo@2825: 
ingo@2825:     private List<FlowVelocityModelValue> values;
ingo@2825: 
ingo@2825:     private String description;
ingo@2825: 
ingo@2825: 
ingo@2825:     public FlowVelocityModel() {
ingo@2825:     }
ingo@2825: 
ingo@2825: 
ingo@2825:     public FlowVelocityModel(River river, DischargeZone dischargeZone) {
ingo@2825:         this(river, dischargeZone, null);
ingo@2825:     }
ingo@2825: 
ingo@2825: 
ingo@2825:     public FlowVelocityModel(
ingo@2825:         River         river,
ingo@2825:         DischargeZone dischargeZone,
ingo@2825:         String        description
ingo@2825:     ) {
ingo@2825:         this.river         = river;
ingo@2825:         this.dischargeZone = dischargeZone;
ingo@2825:         this.description   = description;
ingo@2825:     }
ingo@2825: 
ingo@2825:     @Id
ingo@2825:     @SequenceGenerator(
ingo@2825:         name           = "SEQUENCE_FLOW_VELOCITY_MODEL_ID_SEQ",
ingo@2825:         sequenceName   = "FLOW_VELOCITY_MODEL_ID_SEQ",
ingo@2825:         allocationSize = 1)
ingo@2825:     @GeneratedValue(
ingo@2825:         strategy  = GenerationType.SEQUENCE,
ingo@2825:         generator = "SEQUENCE_FLOW_VELOCITY_MODEL_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@2825:     @OneToOne
ingo@2825:     @JoinColumn(name = "discharge_zone_id")
ingo@2825:     public DischargeZone getDischargeZone() {
ingo@2825:         return dischargeZone;
ingo@2825:     }
ingo@2825: 
ingo@2825:     public void setDischargeZone(DischargeZone dischargeZone) {
ingo@2825:         this.dischargeZone = dischargeZone;
ingo@2825:     }
ingo@2825: 
ingo@2825:     @Column(name = "description")
ingo@2825:     public String getDescription() {
ingo@2825:         return description;
ingo@2825:     }
ingo@2825: 
ingo@2825:     public void setDescription(String description) {
ingo@2825:         this.description = description;
ingo@2825:     }
ingo@2871: 
ingo@2871: 
ingo@2871:     public static List<FlowVelocityModel> getModels(
ingo@2871:         River         river,
ingo@2871:         DischargeZone zone
ingo@2871:     ) {
ingo@2871:         Session session = SessionHolder.HOLDER.get();
ingo@2871: 
ingo@2871:         Query query = session.createQuery(
ingo@2871:             "from FlowVelocityModel where river=:river and dischargeZone=:zone");
ingo@2871: 
ingo@2871:         query.setParameter("river", river);
ingo@2871:         query.setParameter("zone", zone);
ingo@2871: 
ingo@2871:         return query.list();
ingo@2871:     }
ingo@2825: }
ingo@2825: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :