Mercurial > dive4elements > river
view backend/src/main/java/org/dive4elements/river/model/uinfo/VegetationZone.java @ 9464:c77255da734b
cross-section logs removed
author | gernotbelger |
---|---|
date | Thu, 30 Aug 2018 10:53:40 +0200 |
parents | 361de818f76e |
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.uinfo; 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.dive4elements.river.model.River; import org.hibernate.Query; import org.hibernate.Session; /** * Hibernate binding for the DB table vegetation_zone * * @author Matthias Schäfer * */ @Entity @Table(name = "vegetation_zone") public class VegetationZone implements Serializable { /***** FIELDS *****/ private static final long serialVersionUID = -6579828019873800147L; private Integer id; private Vegetation vegetation; private VegetationType vegetationType; private Integer min_overflow_days; private Integer max_overflow_days; private Integer color_r; private Integer color_g; private Integer color_b; /***** CONSTRUCTORS *****/ public VegetationZone() { } public VegetationZone(final Vegetation vegetation, final VegetationType vegetationType, final Integer min_overflow_days, final Integer max_overflow_days, final Integer color_r, final Integer color_g, final Integer color_b) { this.vegetation = vegetation; this.vegetationType = vegetationType; this.min_overflow_days = min_overflow_days; this.max_overflow_days = max_overflow_days; this.color_r = color_r; this.color_g = color_g; this.color_b = color_b; } /***** METHODS *****/ @Id @SequenceGenerator(name = "SEQUENCE_VEGETATION_ZONE_ID_SEQ", sequenceName = "VEGETATION_ZONE_ID_SEQ", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_VEGETATION_ZONE_ID_SEQ") @Column(name = "id") public Integer getId() { return this.id; } public void setId(final Integer id) { this.id = id; } @OneToOne @JoinColumn(name = "vegetation_id") public Vegetation getVegetation() { return this.vegetation; } public void setVegetation(final Vegetation vegetation) { this.vegetation = vegetation; } @OneToOne @JoinColumn(name = "vegetation_type_id") public VegetationType getVegetationType() { return this.vegetationType; } public void setVegetationType(final VegetationType vegetationType) { this.vegetationType = vegetationType; } @Column(name = "min_overflow_days") public Integer getMin_overflow_days() { return this.min_overflow_days; } public void setMin_overflow_days(final Integer min_overflow_days) { this.min_overflow_days = min_overflow_days; } @Column(name = "max_overflow_days") public Integer getMax_overflow_days() { return this.max_overflow_days; } public void setMax_overflow_days(final Integer max_overflow_days) { this.max_overflow_days = max_overflow_days; } @Column(name = "color_r") public Integer getColor_r() { return this.color_r; } public void setColor_r(final Integer color_r) { this.color_r = color_r; } @Column(name = "color_g") public Integer getColor_g() { return this.color_g; } public void setColor_g(final Integer color_g) { this.color_g = color_g; } @Column(name = "color_b") public Integer getColor_b() { return this.color_b; } public void setColor_b(final Integer color_b) { this.color_b = color_b; } @Transient public String getColor() { return String.format("#%02x%02x%02x", getColor_r(), getColor_g(), getColor_b()); } /** * Selects from the database the vegetation zones of a river */ public static List<VegetationZone> getValues(final River river) { final Session session = SessionHolder.HOLDER.get(); final Query query = session.createQuery("SELECT v" + " FROM VegetationZone AS v JOIN v.vegetation AS s" + " WHERE (s.river.id=:riverid)" + " ORDER BY v.vegetationType.id"); query.setParameter("riverid", river.getId()); return query.list(); } }