view backend/src/main/java/org/dive4elements/river/model/sinfo/ChannelValue.java @ 9112:189cc8ededbd

Added datacage select and chart display for river channel sizes loaded from database
author mschaefer
date Mon, 04 Jun 2018 08:36:09 +0200
parents 50416a0df385
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 org.dive4elements.river.backend.SessionHolder;
import org.hibernate.Query;
import org.hibernate.Session;


/**
 * Hibernate binding for the DB table channel_values
 *
 * @author Matthias Schäfer
 *
 */
@Entity
@Table(name = "channel_values")
public class ChannelValue implements Serializable {

    /***** FIELDS *****/

    private static final long serialVersionUID = -3793243094875530557L;

    private Integer id;

    private Channel channel;

    private Double station;

    private Double width;

    private Double depth;


    /***** CONSTRUCTORS *****/

    public ChannelValue() {
    }

    public ChannelValue(final Channel channel, final Double station, final Double width, final Double depth) {
        this.channel = channel;
        this.station = station;
        this.width = width;
        this.depth = depth;
    }

    /**
     * Parameter constructor with primitive parameter types
     */
    public ChannelValue(final Channel channel, final double km, final double width, final double depth) {
        this(channel, Double.valueOf(km), Double.valueOf(width), Double.valueOf(depth));
    }


    /***** METHODS *****/

    @Id
    @SequenceGenerator(name = "SEQUENCE_CHANNEL_VALUE_ID_SEQ", sequenceName = "CHANNEL_VALUES_ID_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_CHANNEL_VALUE_ID_SEQ")
    @Column(name = "id")
    public Integer getId() {
        return this.id;
    }

    public void setId(final Integer id) {
        this.id = id;
    }

    @OneToOne
    @JoinColumn(name = "channel_id")
    public Channel getChannel() {
        return this.channel;
    }

    public void setChannel(final Channel channel) {
        this.channel = channel;
    }

    @Column(name = "station")
    public Double getStation() {
        return this.station;
    }

    public void setStation(final Double station) {
        this.station = station;
    }

    @Column(name = "width")
    public Double getWidth() {
        return this.width;
    }

    public void setWidth(final Double width) {
        this.width = width;
    }

    @Column(name = "depth")
    public Double getDepth() {
        return this.depth;
    }

    public void setDepth(final Double depth) {
        this.depth = depth;
    }

    /**
     * Selects the channel size values of a data series in a km range from the database
     */
    public static List<ChannelValue> getValues(final Channel parent, final double kmLo, final double kmHi) {
        final Session session = SessionHolder.HOLDER.get();
        final Query query = session.createQuery("FROM ChannelValue WHERE (channel=: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();
    }
}

http://dive4elements.wald.intevation.org