Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/model/sinfo/TkhValue.java @ 9709:b74f817435fe
comment removed
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 27 Jan 2021 11:47:38 +0100 |
parents | 1f63e9d3b0ec |
children |
line wrap: on
line source
/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.model.sinfo; import java.io.Serializable; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Transient; import org.dive4elements.river.backend.SessionHolder; import org.hibernate.Query; import org.hibernate.Session; /** * Hibernate binding for the DB table tkh_values * * @author Matthias Schäfer * */ @Entity @Table(name = "tkh_values") public class TkhValue implements Serializable { /***** FIELDS *****/ private static final long serialVersionUID = 4514054828340199384L; private Integer id; private TkhColumn tkhColumn; private Double station; /** * TKH in m */ private Double tkheight; /***** CONSTRUCTORS *****/ public TkhValue() { } public TkhValue(final TkhColumn tkhColumn, final Double station, final Double tkheight) { this.tkhColumn = tkhColumn; this.station = station; this.tkheight = tkheight; } /** * Constructor with primitive parameter types */ public TkhValue(final TkhColumn tkhColumn, final double km, final double tkheight) { this(tkhColumn, Double.valueOf(km), Double.valueOf(tkheight)); } /***** METHODS *****/ @Id @SequenceGenerator(name = "SEQUENCE_TKH_VALUE_ID_SEQ", sequenceName = "TKH_VALUES_ID_SEQ", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_TKH_VALUE_ID_SEQ") @Column(name = "id") public Integer getId() { return this.id; } public void setId(final Integer id) { this.id = id; } @OneToOne @JoinColumn(name = "tkh_column_id") public TkhColumn getTkhColumn() { return this.tkhColumn; } public void setTkhColumn(final TkhColumn tkh) { this.tkhColumn = tkh; } @Column(name = "station") public Double getStation() { return this.station; } public void setStation(final Double station) { this.station = station; } @Column(name = "tkheight") public Double getTkheight() { return this.tkheight; } public void setTkheight(final Double tkheight) { this.tkheight = tkheight; } @Transient public double getTkhCm() { if (getTkheight() != null) return getTkheight().doubleValue() * 100; else return Double.NaN; } @Transient public double getTkhUpCm(final boolean bedMoving) { if (bedMoving) return getTkhCm() / 2; else return getTkhCm(); } @Transient public double getTkhDownCm(final boolean bedMoving) { if (bedMoving) return -getTkhCm() / 2; else return 0.0; } /** * Selects the tkh values of a tkh series column in a km range from the database */ public static List<TkhValue> getTkhValues(final TkhColumn parent, final double kmLo, final double kmHi) { final Session session = SessionHolder.HOLDER.get(); final Query query = session.createQuery("FROM TkhValue WHERE (tkhColumn=:parent)" + " AND (station >= :kmLo - 0.0001) AND (station <= :kmHi + 0.0001)"); query.setParameter("parent", parent); query.setParameter("kmLo", new Double(kmLo)); query.setParameter("kmHi", new Double(kmHi)); return query.list(); } }