Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/model/sinfo/CollisionValue.java @ 9117:623b51bf03d7
Added datacage select and chart display for river bed collision counts loaded from database
author | mschaefer |
---|---|
date | Mon, 04 Jun 2018 17:31:51 +0200 |
parents | 50416a0df385 |
children | 38e8febd11b6 |
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.Date; 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 org.dive4elements.river.backend.SessionHolder; import org.hibernate.Query; import org.hibernate.Session; /** * Hibernate binding for the DB table collision_values * * @author Matthias Schäfer * */ @Entity @Table(name = "collision_values") public class CollisionValue implements Serializable { /***** FIELDS *****/ private static final long serialVersionUID = -1157324854470346513L; private Integer id; private Collision collision; private Double station; private CollisionType collisionType; private Date eventDate; private String gaugeName; private Double gaugeW; /***** CONSTRUCTORS *****/ public CollisionValue() { } public CollisionValue(final Collision collision, final Double station, final CollisionType collisionType, final Date eventDate, final String gaugeName, final Double gaugeW) { this.collision = collision; this.station = station; this.collisionType = collisionType; this.eventDate = eventDate; this.gaugeName = gaugeName; this.gaugeW = gaugeW; } /** * Constructor with primitive parameter types */ public CollisionValue(final Collision collision, final double km, final CollisionType collisionType, final Date eventDate, final String gaugeName, final double gaugeW) { this(collision, Double.valueOf(km), collisionType, eventDate, gaugeName, Double.valueOf(gaugeW)); } /***** METHODS *****/ @Id @SequenceGenerator(name = "SEQUENCE_COLLISION_VALUE_ID_SEQ", sequenceName = "COLLISION_VALUES_ID_SEQ", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_COLLISION_VALUE_ID_SEQ") @Column(name = "id") public Integer getId() { return this.id; } public void setId(final Integer id) { this.id = id; } @OneToOne @JoinColumn(name = "collision_id") public Collision getCollision() { return this.collision; } public void setCollision(final Collision collision) { this.collision = collision; } @Column(name = "station") public Double getStation() { return this.station; } public void setStation(final Double station) { this.station = station; } @OneToOne @JoinColumn(name = "collision_type_id") public CollisionType getCollisionType() { return this.collisionType; } public void setCollisionType(final CollisionType collisionType) { this.collisionType = collisionType; } @Column(name = "event_date") public Date getEventDate() { return this.eventDate; } public void setEventDate(final Date eventDate) { this.eventDate = eventDate; } @Column(name = "gauge_name") public String getGaugeName() { return this.gaugeName; } public void setGaugeName(final String gaugeName) { this.gaugeName = gaugeName; } @Column(name = "gauge_w") public Double getGaugeW() { return this.gaugeW; } public void setGaugeW(final Double gaugeW) { this.gaugeW = gaugeW; } /** * Selects the collision values of a data series in a km range from the database */ public static List<CollisionValue> getValues(final Collision parent, final double kmLo, final double kmHi) { final Session session = SessionHolder.HOLDER.get(); final Query query = session.createQuery("FROM CollisionValue WHERE (collision=: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(); } }