Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/model/MainValue.java @ 9159:64e56a51db3f
Added methods to select a gauge's discharge table and main value list; added a main value type key enum
author | mschaefer |
---|---|
date | Tue, 19 Jun 2018 14:23:15 +0200 |
parents | 4c3ccf2b0304 |
children | 1614cb14308f |
comparison
equal
deleted
inserted
replaced
9158:4a41b7fba4da | 9159:64e56a51db3f |
---|---|
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.model; | 9 package org.dive4elements.river.model; |
10 | 10 |
11 import java.io.Serializable; | 11 import java.io.Serializable; |
12 import java.math.BigDecimal; | |
13 import java.util.List; | |
12 | 14 |
15 import javax.persistence.Column; | |
13 import javax.persistence.Entity; | 16 import javax.persistence.Entity; |
17 import javax.persistence.GeneratedValue; | |
18 import javax.persistence.GenerationType; | |
14 import javax.persistence.Id; | 19 import javax.persistence.Id; |
20 import javax.persistence.JoinColumn; | |
21 import javax.persistence.OneToOne; | |
22 import javax.persistence.SequenceGenerator; | |
15 import javax.persistence.Table; | 23 import javax.persistence.Table; |
16 import javax.persistence.GeneratedValue; | |
17 import javax.persistence.Column; | |
18 import javax.persistence.SequenceGenerator; | |
19 import javax.persistence.OneToOne; | |
20 import javax.persistence.JoinColumn; | |
21 import javax.persistence.GenerationType; | |
22 | 24 |
23 import java.math.BigDecimal; | 25 import org.dive4elements.river.backend.SessionHolder; |
26 import org.dive4elements.river.model.MainValueType.MainValueTypeKey; | |
27 import org.hibernate.Query; | |
28 import org.hibernate.Session; | |
24 | 29 |
25 | 30 |
26 /** A Main or Extreme value of a rivers gauge. */ | 31 /** A Main or Extreme value of a rivers gauge. */ |
27 @Entity | 32 @Entity |
28 @Table(name = "main_values") | 33 @Table(name = "main_values") |
41 | 46 |
42 public MainValue() { | 47 public MainValue() { |
43 } | 48 } |
44 | 49 |
45 public MainValue( | 50 public MainValue( |
46 Gauge gauge, | 51 final Gauge gauge, |
47 NamedMainValue mainValue, | 52 final NamedMainValue mainValue, |
48 BigDecimal value, | 53 final BigDecimal value, |
49 TimeInterval timeInterval | 54 final TimeInterval timeInterval |
50 ) { | 55 ) { |
51 this.gauge = gauge; | 56 this.gauge = gauge; |
52 this.mainValue = mainValue; | 57 this.mainValue = mainValue; |
53 this.value = value; | 58 this.value = value; |
54 this.timeInterval = timeInterval; | 59 this.timeInterval = timeInterval; |
55 } | 60 } |
56 | 61 |
57 @Id | 62 @Id |
58 @SequenceGenerator( | 63 @SequenceGenerator( |
59 name = "SEQUENCE_MAIN_VALUES_ID_SEQ", | 64 name = "SEQUENCE_MAIN_VALUES_ID_SEQ", |
60 sequenceName = "MAIN_VALUES_ID_SEQ", | 65 sequenceName = "MAIN_VALUES_ID_SEQ", |
61 allocationSize = 1) | 66 allocationSize = 1) |
62 @GeneratedValue( | 67 @GeneratedValue( |
63 strategy = GenerationType.SEQUENCE, | 68 strategy = GenerationType.SEQUENCE, |
64 generator = "SEQUENCE_MAIN_VALUES_ID_SEQ") | 69 generator = "SEQUENCE_MAIN_VALUES_ID_SEQ") |
65 @Column(name = "id") | 70 @Column(name = "id") |
66 public Integer getId() { | 71 public Integer getId() { |
67 return id; | 72 return this.id; |
68 } | 73 } |
69 | 74 |
70 public void setId(Integer id) { | 75 public void setId(final Integer id) { |
71 this.id = id; | 76 this.id = id; |
72 } | 77 } |
73 | 78 |
74 @OneToOne | 79 @OneToOne |
75 @JoinColumn(name = "gauge_id") | 80 @JoinColumn(name = "gauge_id") |
76 public Gauge getGauge() { | 81 public Gauge getGauge() { |
77 return gauge; | 82 return this.gauge; |
78 } | 83 } |
79 | 84 |
80 public void setGauge(Gauge gauge) { | 85 public void setGauge(final Gauge gauge) { |
81 this.gauge = gauge; | 86 this.gauge = gauge; |
82 } | 87 } |
83 | 88 |
84 @OneToOne | 89 @OneToOne |
85 @JoinColumn(name = "named_value_id") | 90 @JoinColumn(name = "named_value_id") |
86 public NamedMainValue getMainValue() { | 91 public NamedMainValue getMainValue() { |
87 return mainValue; | 92 return this.mainValue; |
88 } | 93 } |
89 | 94 |
90 public void setMainValue(NamedMainValue mainValue) { | 95 public void setMainValue(final NamedMainValue mainValue) { |
91 this.mainValue = mainValue; | 96 this.mainValue = mainValue; |
92 } | 97 } |
93 | 98 |
94 @Column(name = "value") // FIXME: type mapping needed? | 99 @Column(name = "value") // FIXME: type mapping needed? |
95 public BigDecimal getValue() { | 100 public BigDecimal getValue() { |
96 return value; | 101 return this.value; |
97 } | 102 } |
98 | 103 |
99 public void setValue(BigDecimal value) { | 104 public void setValue(final BigDecimal value) { |
100 this.value = value; | 105 this.value = value; |
101 } | 106 } |
102 | 107 |
103 @OneToOne | 108 @OneToOne |
104 @JoinColumn(name = "time_interval_id") | 109 @JoinColumn(name = "time_interval_id") |
105 public TimeInterval getTimeInterval() { | 110 public TimeInterval getTimeInterval() { |
106 return timeInterval; | 111 return this.timeInterval; |
107 } | 112 } |
108 | 113 |
109 public void setTimeInterval(TimeInterval timeInterval) { | 114 public void setTimeInterval(final TimeInterval timeInterval) { |
110 this.timeInterval = timeInterval; | 115 this.timeInterval = timeInterval; |
116 } | |
117 | |
118 /** | |
119 * Selects from the database the main values of a gauge and a type, in ascending value order | |
120 */ | |
121 public static List<MainValue> getValuesOfGaugeAndType(final Gauge gauge, final MainValueTypeKey typekey) { | |
122 final Session session = SessionHolder.HOLDER.get(); | |
123 final Query query = session.createQuery("SELECT mv" | |
124 + " FROM MainValue AS mv JOIN mv.mainValue AS nmv" | |
125 + " WHERE mv.gauge.id=:gaugeid AND nmv.type.id=:typeid" | |
126 + " ORDER BY value"); | |
127 query.setParameter("gaugeid", gauge.getId()); | |
128 query.setParameter("typeid", typekey.getId()); | |
129 return query.list(); | |
111 } | 130 } |
112 } | 131 } |
113 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 132 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |