ingo@2810: package de.intevation.flys.model; ingo@2810: ingo@2810: import java.io.Serializable; ingo@2810: ingo@2810: import java.util.ArrayList; ingo@2810: import java.util.List; ingo@2810: ingo@2810: import javax.persistence.Entity; ingo@2810: import javax.persistence.Id; ingo@2810: import javax.persistence.Table; ingo@2810: import javax.persistence.GeneratedValue; ingo@2810: import javax.persistence.Column; ingo@2810: import javax.persistence.SequenceGenerator; ingo@2810: import javax.persistence.GenerationType; ingo@2810: import javax.persistence.JoinColumn; ingo@2810: import javax.persistence.OneToOne; ingo@2810: import javax.persistence.OneToMany; ingo@2810: 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@2810: ingo@2810: @Entity ingo@2810: @Table(name = "bed_height_epoch") ingo@2810: public class BedHeightEpoch implements Serializable { ingo@2810: ingo@2810: private Integer id; ingo@2810: ingo@2810: private River river; ingo@2810: ingo@2810: private TimeInterval timeInterval; ingo@2810: ingo@2810: private ElevationModel curElevationModel; ingo@2810: private ElevationModel oldElevationModel; ingo@2810: ingo@2810: private Range range; ingo@2810: ingo@2810: private String evaluationBy; ingo@2810: private String description; ingo@2810: ingo@2810: private List values; ingo@2810: ingo@2810: ingo@2810: public BedHeightEpoch() { ingo@2810: } ingo@2810: ingo@2810: ingo@2810: public BedHeightEpoch( ingo@2810: River river, ingo@2810: TimeInterval timeInterval, ingo@2810: Range range, ingo@2810: ElevationModel curElevationModel, ingo@2810: ElevationModel oldElevationModel, ingo@2810: String evaluationBy, ingo@2810: String description ingo@2810: ) { ingo@2810: this.river = river; ingo@2810: this.timeInterval = timeInterval; ingo@2810: this.range = range; ingo@2810: this.curElevationModel = curElevationModel; ingo@2810: this.oldElevationModel = oldElevationModel; ingo@2810: this.evaluationBy = evaluationBy; ingo@2810: this.description = description; ingo@2810: this.values = new ArrayList(); ingo@2810: } ingo@2810: ingo@2810: ingo@2810: @Id ingo@2810: @SequenceGenerator( ingo@2810: name = "SEQUENCE_BED_HEIGHT_EPOCH_ID_SEQ", ingo@2810: sequenceName = "BED_HEIGHT_EPOCH_ID_SEQ", ingo@2810: allocationSize = 1) ingo@2810: @GeneratedValue( ingo@2810: strategy = GenerationType.SEQUENCE, ingo@2810: generator = "SEQUENCE_BED_HEIGHT_EPOCH_ID_SEQ") ingo@2810: @Column(name = "id") ingo@2810: public Integer getId() { ingo@2810: return id; ingo@2810: } ingo@2810: ingo@2810: public void setId(Integer id) { ingo@2810: this.id = id; ingo@2810: } ingo@2810: ingo@2810: @OneToOne ingo@2810: @JoinColumn(name = "river_id" ) ingo@2810: public River getRiver() { ingo@2810: return river; ingo@2810: } ingo@2810: ingo@2810: public void setRiver(River river) { ingo@2810: this.river = river; ingo@2810: } ingo@2810: ingo@2810: @OneToOne ingo@2810: @JoinColumn(name = "time_interval_id") ingo@2810: public TimeInterval getTimeInterval() { ingo@2810: return timeInterval; ingo@2810: } ingo@2810: ingo@2810: public void setTimeInterval(TimeInterval timeInterval) { ingo@2810: this.timeInterval = timeInterval; ingo@2810: } ingo@2810: ingo@2810: @OneToOne ingo@2810: @JoinColumn(name = "cur_elevation_model_id") ingo@2810: public ElevationModel getCurElevationModel() { ingo@2810: return curElevationModel; ingo@2810: } ingo@2810: ingo@2810: public void setCurElevationModel(ElevationModel curElevationModel) { ingo@2810: this.curElevationModel = curElevationModel; ingo@2810: } ingo@2810: ingo@2810: @OneToOne ingo@2810: @JoinColumn(name = "old_elevation_model_id") ingo@2810: public ElevationModel getOldElevationModel() { ingo@2810: return oldElevationModel; ingo@2810: } ingo@2810: ingo@2810: public void setOldElevationModel(ElevationModel oldElevationModel) { ingo@2810: this.oldElevationModel = oldElevationModel; ingo@2810: } ingo@2810: ingo@2810: @OneToOne ingo@2810: @JoinColumn(name = "range_id") ingo@2810: public Range getRange() { ingo@2810: return range; ingo@2810: } ingo@2810: ingo@2810: public void setRange(Range range) { ingo@2810: this.range = range; ingo@2810: } ingo@2810: ingo@2810: @Column(name = "evaluation_by") ingo@2810: public String getEvaluationBy() { ingo@2810: return evaluationBy; ingo@2810: } ingo@2810: ingo@2810: public void setEvaluationBy(String evaluationBy) { ingo@2810: this.evaluationBy = evaluationBy; ingo@2810: } ingo@2810: ingo@2810: @Column(name = "description") ingo@2810: public String getDescription() { ingo@2810: return description; ingo@2810: } ingo@2810: ingo@2810: public void setDescription(String description) { ingo@2810: this.description = description; ingo@2810: } ingo@2810: ingo@2810: @OneToMany ingo@2810: @JoinColumn(name = "bed_height_epoch_id") ingo@2810: public List getValues() { ingo@2810: return values; ingo@2810: } ingo@2810: ingo@2810: public void setValues(List values) { ingo@2810: this.values = values; ingo@2810: } ingo@2872: ingo@2872: ingo@2875: public static List getBedHeightEpochs( 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 BedHeightEpoch 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 epochs = query.list(); ingo@2875: List good = new ArrayList(); ingo@2875: ingo@3799: OUTER: for (BedHeightEpoch e: epochs) { ingo@2875: for (BedHeightEpochValue value: e.getValues()) { ingo@2875: double station = value.getStation().doubleValue(); ingo@2875: ingo@2875: if (station >= kmLo && station <= kmHi) { ingo@2875: good.add(e); ingo@2875: continue OUTER; ingo@2875: } ingo@2875: } ingo@2875: } ingo@2875: ingo@2875: return good; ingo@2872: } ingo@2872: ingo@2872: ingo@2872: public static BedHeightEpoch getBedHeightEpochById(int id) { ingo@2872: Session session = SessionHolder.HOLDER.get(); ingo@2872: ingo@2872: Query query = session.createQuery( ingo@2872: "from BedHeightEpoch 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@2810: } ingo@2810: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :