teichmann@5844: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5844: * Software engineering by Intevation GmbH teichmann@5844: * teichmann@5992: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5844: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5992: * documentation coming with Dive4Elements River for details. teichmann@5844: */ teichmann@5844: teichmann@5829: package org.dive4elements.river.model; ingo@2825: teichmann@5829: import org.dive4elements.river.backend.SessionHolder; teichmann@5323: ingo@2825: import java.io.Serializable; teichmann@5323: ingo@2825: import java.util.List; ingo@2825: teichmann@5323: import javax.persistence.Column; ingo@2825: import javax.persistence.Entity; teichmann@5323: import javax.persistence.GeneratedValue; teichmann@5323: import javax.persistence.GenerationType; ingo@2825: import javax.persistence.Id; ingo@2825: import javax.persistence.JoinColumn; ingo@2825: import javax.persistence.OneToOne; teichmann@5323: import javax.persistence.SequenceGenerator; teichmann@5323: import javax.persistence.Table; ingo@2871: ingo@2825: import org.apache.log4j.Logger; ingo@2825: teichmann@5323: import org.hibernate.Query; teichmann@5323: import org.hibernate.Session; 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: private Integer id; ingo@2825: ingo@2825: private DischargeZone dischargeZone; ingo@2825: ingo@2825: private String description; ingo@2825: ingo@2825: ingo@2825: public FlowVelocityModel() { ingo@2825: } ingo@2825: ingo@2825: teichmann@5323: public FlowVelocityModel(DischargeZone dischargeZone) { teichmann@5323: this(dischargeZone, null); ingo@2825: } ingo@2825: ingo@2825: ingo@2825: public FlowVelocityModel( ingo@2825: DischargeZone dischargeZone, ingo@2825: String description ingo@2825: ) { 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 = "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: teichmann@5323: public static List getModels(DischargeZone zone) { teichmann@5323: ingo@2871: Session session = SessionHolder.HOLDER.get(); ingo@2871: ingo@2871: Query query = session.createQuery( teichmann@5323: "from FlowVelocityModel where dischargeZone=:zone"); ingo@2871: ingo@2871: query.setParameter("zone", zone); ingo@2871: ingo@2871: return query.list(); ingo@2871: } felix@7286: felix@7371: felix@7371: /** Get a Model by id. */ felix@7286: public static FlowVelocityModel getModel(int id) { felix@7286: felix@7286: Session session = SessionHolder.HOLDER.get(); felix@7286: felix@7286: Query query = session.createQuery( felix@7286: "from FlowVelocityModel where id=:id"); felix@7286: felix@7286: query.setParameter("id", id); felix@7286: felix@7286: return (FlowVelocityModel) query.list().get(0); felix@7286: } felix@7371: felix@7371: felix@7371: /** Get description of a Model by id. */ felix@7371: public static String getModelDescription(int id) { felix@7371: felix@7371: Session session = SessionHolder.HOLDER.get(); felix@7371: felix@7371: Query query = session.createQuery( felix@7371: "from FlowVelocityModel where id=:id"); felix@7371: felix@7371: query.setParameter("id", id); felix@7371: felix@7371: FlowVelocityModel model = (FlowVelocityModel) query.list().get(0); felix@7371: felix@7371: return (model == null) ? null : model.getDescription(); felix@7371: } ingo@2825: } ingo@2825: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :