view backend/src/main/java/org/dive4elements/river/model/sinfo/DepthEvolutionValue.java @ 9032:1f63e9d3b0ec

New columns for bed_height, tkh and depth_evolution, a few syntactic corrections for Oracle
author mschaefer
date Fri, 27 Apr 2018 17:35: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 javax.persistence.Transient;

import org.dive4elements.river.backend.SessionHolder;
import org.hibernate.Query;
import org.hibernate.Session;


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

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

    private static final long serialVersionUID = 3164888119107103560L;

    private Integer id;

    private DepthEvolution depth_evolution;

    private Double station;

    private Double total_change;

    private Double change_per_year;


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

    public DepthEvolutionValue() {
    }

    public DepthEvolutionValue(final DepthEvolution depth_evolution, final Double station, final Double total_change, final Double change_per_year) {
        this.depth_evolution = depth_evolution;
        this.station = station;
        this.total_change = total_change;
        this.change_per_year = change_per_year;
    }

    /**
     * Parameter constructor with primitive parameter types
     */
    public DepthEvolutionValue(final DepthEvolution depth_evolution, final double km, final double total_change, final double change_per_year) {
        this(depth_evolution, Double.valueOf(km), Double.valueOf(total_change), Double.valueOf(change_per_year));
    }


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

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

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

    @OneToOne
    @JoinColumn(name = "depth_evolution_id")
    public DepthEvolution getDepthEvolution() {
        return this.depth_evolution;
    }

    public void setDepthEvolution(final DepthEvolution depth_evolution) {
        this.depth_evolution = depth_evolution;
    }

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

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

    @Column(name = "total_change")
    public Double getTotal_change() {
        return this.total_change;
    }

    public void setTotal_change(final Double total_change) {
        this.total_change = total_change;
    }

    @Transient
    public Double getTotalChangeCm() {
        if (getTotal_change() != null)
            return getTotal_change() * 100;
        else
            return null;
    }

    @Column(name = "change_per_year")
    public Double getChange_per_year() {
        return this.change_per_year;
    }

    public void setChange_per_year(final Double change_per_year) {
        this.change_per_year = change_per_year;
    }

    @Transient
    public Double getPerYearChangeCm() {
        if (getChange_per_year() != null)
            return getChange_per_year() * 100;
        else
            return null;
    }

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