view backend/src/main/java/org/dive4elements/river/model/sinfo/FlowDepthValue.java @ 9035:c16e90a0baf7

Added datacage select and chart display for modelled flow depth series loaded from database
author mschaefer
date Mon, 30 Apr 2018 16:00:12 +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 flow_depth_values
 *
 * @author Matthias Schäfer
 *
 */
@Entity
@Table(name = "flow_depth_values")
public class FlowDepthValue implements Serializable {

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

    private static final long serialVersionUID = -7465899199734466657L;

    private Integer id;

    private FlowDepthColumn flowDepthColumn;

    private Double station;

    /**
     * Flow depth in m
     */
    private Double depth;


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

    public FlowDepthValue() {
    }

    public FlowDepthValue(final FlowDepthColumn flowDepthColumn, final Double station, final Double depth) {
        this.flowDepthColumn = flowDepthColumn;
        this.station = station;
        this.depth = depth;
    }

    /**
     * Constructor with primitive parameter types
     */
    public FlowDepthValue(final FlowDepthColumn flow_depthColumn, final double km, final double depth) {
        this(flow_depthColumn, Double.valueOf(km), Double.valueOf(depth));
    }


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

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

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

    @OneToOne
    @JoinColumn(name = "flow_depth_column_id")
    public FlowDepthColumn getFlowDepthColumn() {
        return this.flowDepthColumn;
    }

    public void setFlowDepthColumn(final FlowDepthColumn flow_depth) {
        this.flowDepthColumn = flow_depth;
    }

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

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

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

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

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