view backend/src/main/java/org/dive4elements/river/model/sinfo/FlowDepthColumn.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 32dd7e761e4e
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.OneToMany;
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 flow_depth_column
 *
 * @author Matthias Schäfer
 *
 */
@Entity
@Table(name = "flow_depth_column")
public class FlowDepthColumn implements Serializable {

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

    private static final long serialVersionUID = -8164345503234852700L;

    private Integer id;

    private FlowDepth parent;

    private String  name;

    private List<FlowDepthValue> values;


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

    public FlowDepthColumn() {
    }

    public FlowDepthColumn(final FlowDepth parent, final String name) {
        this.parent = parent;
        this.name = name;
    }

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

    @Id
    @SequenceGenerator(name = "SEQUENCE_FLOW_DEPTH_COLUMN_ID_SEQ", sequenceName = "FLOW_DEPTH_COLUMN_ID_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_FLOW_DEPTH_COLUMN_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_id")
    public FlowDepth getFlowDepth() {
        return this.parent;
    }

    @Transient
    public FlowDepth getSeries() {
        return getFlowDepth();
    }

    public void setFlowDepth(final FlowDepth flow_depth) {
        this.parent = flow_depth;
    }

    @Column(name = "name")
    public String getName() {
        return this.name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    @OneToMany
    @JoinColumn(name = "flow_depth_column_id")
    public List<FlowDepthValue> getValues() {
        return this.values;
    }

    public void setValues(final List<FlowDepthValue> values) {
        this.values = values;
    }

    public void addValue(final FlowDepthValue value) {
        this.values.add(value);
    }

    /**
     * Selects a flow depth series column by id from the database
     */
    public static FlowDepthColumn getColumnById(final int id) {
        final Session session = SessionHolder.HOLDER.get();
        final Query query = session.createQuery("FROM FlowDepthColumn WHERE id=:id");
        query.setParameter("id", id);
        final List<FlowDepthColumn> rows = query.list();
        return (rows != null) ? rows.get(0) : null;
    }
}

http://dive4elements.wald.intevation.org