ingo@2809: package de.intevation.flys.model; ingo@2809: ingo@2809: import java.io.Serializable; ingo@2809: ingo@2875: import java.util.ArrayList; ingo@2809: import java.util.List; ingo@2809: ingo@2809: import javax.persistence.Entity; ingo@2809: import javax.persistence.Id; ingo@2809: import javax.persistence.Table; ingo@2809: import javax.persistence.GeneratedValue; ingo@2809: import javax.persistence.Column; ingo@2809: import javax.persistence.SequenceGenerator; ingo@2809: import javax.persistence.GenerationType; ingo@2809: import javax.persistence.JoinColumn; ingo@2809: import javax.persistence.OneToOne; ingo@2809: import javax.persistence.OneToMany; ingo@2809: ingo@2872: import org.hibernate.Session; ingo@2872: import org.hibernate.Query; ingo@2872: ingo@2872: import de.intevation.flys.backend.SessionHolder; ingo@2872: ingo@2809: ingo@2809: @Entity ingo@2809: @Table(name = "bed_height_single") ingo@2809: public class BedHeightSingle implements Serializable { ingo@2809: ingo@2809: private Integer id; ingo@2809: private Integer year; ingo@2809: private Integer soundingWidth; ingo@2809: ingo@2809: private String evaluationBy; ingo@2809: private String description; ingo@2809: ingo@2809: private River river; ingo@2809: ingo@2809: private BedHeightType type; ingo@2809: ingo@2809: private LocationSystem locationSystem; ingo@2809: ingo@2809: private ElevationModel curElevationModel; ingo@2809: ingo@2809: private ElevationModel oldElevationModel; ingo@2809: ingo@2809: private Range range; ingo@2809: ingo@2809: private List values; ingo@2809: ingo@2809: ingo@2809: public BedHeightSingle() { ingo@2809: } ingo@2809: ingo@2809: ingo@2809: public BedHeightSingle( ingo@2809: River river, ingo@2809: Integer year, ingo@2809: Integer soundingWidth, ingo@2809: BedHeightType type, ingo@2809: LocationSystem locationSystem, ingo@2809: ElevationModel curElevationModel, ingo@2809: Range range ingo@2809: ) { ingo@2809: this( ingo@2809: river, ingo@2809: year, ingo@2809: soundingWidth, ingo@2809: type, ingo@2809: locationSystem, ingo@2809: curElevationModel, ingo@2809: null, ingo@2809: range, ingo@2809: null, ingo@2809: null); ingo@2809: } ingo@2809: ingo@2809: ingo@2809: public BedHeightSingle( ingo@2809: River river, ingo@2809: Integer year, ingo@2809: Integer soundingWidth, ingo@2809: BedHeightType type, ingo@2809: LocationSystem locationSystem, ingo@2809: ElevationModel curElevationModel, ingo@2809: ElevationModel oldElevationModel, ingo@2809: Range range, ingo@2809: String evaluationBy, ingo@2809: String description ingo@2809: ) { ingo@2809: this.river = river; ingo@2809: this.year = year; ingo@2809: this.soundingWidth = soundingWidth; ingo@2809: this.type = type; ingo@2809: this.locationSystem = locationSystem; ingo@2809: this.curElevationModel = curElevationModel; ingo@2809: this.oldElevationModel = oldElevationModel; ingo@2809: this.range = range; ingo@2809: this.evaluationBy = evaluationBy; ingo@2809: this.description = description; ingo@2809: } ingo@2809: ingo@2809: ingo@2809: @Id ingo@2809: @SequenceGenerator( ingo@2809: name = "SEQUENCE_BED_HEIGHT_SINGLE_ID_SEQ", ingo@2809: sequenceName = "BED_HEIGHT_SINGLE_ID_SEQ", ingo@2809: allocationSize = 1) ingo@2809: @GeneratedValue( ingo@2809: strategy = GenerationType.SEQUENCE, ingo@2809: generator = "SEQUENCE_BED_HEIGHT_SINGLE_ID_SEQ") ingo@2809: @Column(name = "id") ingo@2809: public Integer getId() { ingo@2809: return id; ingo@2809: } ingo@2809: ingo@2809: public void setId(Integer id) { ingo@2809: this.id = id; ingo@2809: } ingo@2809: ingo@2809: @OneToOne ingo@2809: @JoinColumn(name = "river_id" ) ingo@2809: public River getRiver() { ingo@2809: return river; ingo@2809: } ingo@2809: ingo@2809: public void setRiver(River river) { ingo@2809: this.river = river; ingo@2809: } ingo@2809: ingo@2809: @Column(name = "year") ingo@2809: public Integer getYear() { ingo@2809: return year; ingo@2809: } ingo@2809: ingo@2809: public void setYear(Integer year) { ingo@2809: this.year = year; ingo@2809: } ingo@2809: ingo@2809: @Column(name = "sounding_width") ingo@2809: public Integer getSoundingWidth() { ingo@2809: return soundingWidth; ingo@2809: } ingo@2809: ingo@2809: public void setSoundingWidth(Integer soundingWidth) { ingo@2809: this.soundingWidth = soundingWidth; ingo@2809: } ingo@2809: ingo@2809: @OneToOne ingo@2809: @JoinColumn(name = "type_id") ingo@2809: public BedHeightType getType() { ingo@2809: return type; ingo@2809: } ingo@2809: ingo@2809: public void setType(BedHeightType type) { ingo@2809: this.type = type; ingo@2809: } ingo@2809: ingo@2809: @OneToOne ingo@2809: @JoinColumn(name = "location_system_id") ingo@2809: public LocationSystem getLocationSystem() { ingo@2809: return locationSystem; ingo@2809: } ingo@2809: ingo@2809: public void setLocationSystem(LocationSystem locationSystem) { ingo@2809: this.locationSystem = locationSystem; ingo@2809: } ingo@2809: ingo@2809: @OneToOne ingo@2809: @JoinColumn(name = "cur_elevation_model_id") ingo@2809: public ElevationModel getCurElevationModel() { ingo@2809: return curElevationModel; ingo@2809: } ingo@2809: ingo@2809: public void setCurElevationModel(ElevationModel curElevationModel) { ingo@2809: this.curElevationModel = curElevationModel; ingo@2809: } ingo@2809: ingo@2809: @OneToOne ingo@2809: @JoinColumn(name = "old_elevation_model_id") ingo@2809: public ElevationModel getOldElevationModel() { ingo@2809: return oldElevationModel; ingo@2809: } ingo@2809: ingo@2809: public void setOldElevationModel(ElevationModel oldElevationModel) { ingo@2809: this.oldElevationModel = oldElevationModel; ingo@2809: } ingo@2809: ingo@2809: @OneToOne ingo@2809: @JoinColumn(name = "range_id") ingo@2809: public Range getRange() { ingo@2809: return range; ingo@2809: } ingo@2809: ingo@2809: public void setRange(Range range) { ingo@2809: this.range = range; ingo@2809: } ingo@2809: ingo@2809: @Column(name = "evaluation_by") ingo@2809: public String getEvaluationBy() { ingo@2809: return evaluationBy; ingo@2809: } ingo@2809: ingo@2809: public void setEvaluationBy(String evaluationBy) { ingo@2809: this.evaluationBy = evaluationBy; ingo@2809: } ingo@2809: ingo@2809: @Column(name = "description") ingo@2809: public String getDescription() { ingo@2809: return description; ingo@2809: } ingo@2809: ingo@2809: public void setDescription(String description) { ingo@2809: this.description = description; ingo@2809: } ingo@2809: ingo@2809: @OneToMany ingo@2809: @JoinColumn(name = "bed_height_single_id") ingo@2809: public List getValues() { ingo@2809: return values; ingo@2809: } ingo@2809: ingo@2809: public void setValues(List values) { ingo@2809: this.values = values; ingo@2809: } ingo@2872: ingo@2872: ingo@2875: public static List getBedHeightSingles( ingo@2875: River river, ingo@2875: double kmLo, ingo@2875: double kmHi ingo@2875: ) { ingo@2872: Session session = SessionHolder.HOLDER.get(); ingo@2872: ingo@2872: Query query = session.createQuery( ingo@2872: "from BedHeightSingle where river=:river"); ingo@2872: ingo@2872: query.setParameter("river", river); ingo@2872: ingo@2875: // TODO Do km range filtering in SQL statement ingo@2875: ingo@2875: List singles = query.list(); ingo@2875: List good = new ArrayList(); ingo@2875: sascha@3952: for (BedHeightSingle s: singles) { ingo@2875: for (BedHeightSingleValue value: s.getValues()) { ingo@2875: double station = value.getStation().doubleValue(); ingo@2875: ingo@2875: if (station >= kmLo && station <= kmHi) { ingo@2875: good.add(s); sascha@3952: break; ingo@2875: } ingo@2875: } ingo@2875: } ingo@2875: ingo@2875: return good; ingo@2872: } ingo@2872: ingo@2872: ingo@2872: public static BedHeightSingle getBedHeightSingleById(int id) { ingo@2872: Session session = SessionHolder.HOLDER.get(); ingo@2872: ingo@2872: Query query = session.createQuery( ingo@2872: "from BedHeightSingle where id=:id"); ingo@2872: ingo@2872: query.setParameter("id", id); ingo@2872: ingo@2872: List singles = query.list(); ingo@2872: ingo@2872: return singles != null ? singles.get(0) : null; ingo@2872: } ingo@2809: } ingo@2809: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :