Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/model/Wst.java @ 8973:35afa0349782
New field wsts.sinfo_selection
author | mschaefer |
---|---|
date | Tue, 03 Apr 2018 10:29:57 +0200 |
parents | 5e38e2924c07 |
children |
comparison
equal
deleted
inserted
replaced
8972:26c4415a360a | 8973:35afa0349782 |
---|---|
10 | 10 |
11 import java.io.Serializable; | 11 import java.io.Serializable; |
12 import java.math.BigDecimal; | 12 import java.math.BigDecimal; |
13 import java.util.List; | 13 import java.util.List; |
14 | 14 |
15 import javax.persistence.Column; | |
15 import javax.persistence.Entity; | 16 import javax.persistence.Entity; |
17 import javax.persistence.GeneratedValue; | |
18 import javax.persistence.GenerationType; | |
16 import javax.persistence.Id; | 19 import javax.persistence.Id; |
20 import javax.persistence.JoinColumn; | |
21 import javax.persistence.OneToMany; | |
22 import javax.persistence.OneToOne; | |
23 import javax.persistence.SequenceGenerator; | |
17 import javax.persistence.Table; | 24 import javax.persistence.Table; |
18 import javax.persistence.GeneratedValue; | |
19 import javax.persistence.Column; | |
20 import javax.persistence.SequenceGenerator; | |
21 import javax.persistence.GenerationType; | |
22 import javax.persistence.JoinColumn; | |
23 import javax.persistence.OneToOne; | |
24 import javax.persistence.OneToMany; | |
25 | 25 |
26 import org.apache.log4j.Logger; | 26 import org.apache.log4j.Logger; |
27 | 27 import org.dive4elements.river.backend.SessionHolder; |
28 import org.hibernate.Query; | |
29 import org.hibernate.SQLQuery; | |
28 import org.hibernate.Session; | 30 import org.hibernate.Session; |
29 import org.hibernate.SQLQuery; | |
30 import org.hibernate.Query; | |
31 import org.hibernate.type.StandardBasicTypes; | 31 import org.hibernate.type.StandardBasicTypes; |
32 | |
33 import org.dive4elements.river.backend.SessionHolder; | |
34 | 32 |
35 | 33 |
36 /** DB-mapped WST. */ | 34 /** DB-mapped WST. */ |
37 @Entity | 35 @Entity |
38 @Table(name = "wsts") | 36 @Table(name = "wsts") |
43 | 41 |
44 private Integer id; | 42 private Integer id; |
45 private River river; | 43 private River river; |
46 private String description; | 44 private String description; |
47 private Integer kind; | 45 private Integer kind; |
46 private String sinfo_selection; | |
48 | 47 |
49 private List<WstColumn> columns; | 48 private List<WstColumn> columns; |
50 | 49 |
51 | 50 |
52 public static final String SQL_SELECT_MINMAX = | 51 public static final String SQL_SELECT_MINMAX = |
53 "select min(q) as minQ, max(q) as maxQ from wst_q_values " + | 52 "select min(q) as minQ, max(q) as maxQ from wst_q_values " + |
54 "where wst_id = :wst and not (a > :km or b < :km)"; | 53 "where wst_id = :wst and not (a > :km or b < :km)"; |
55 | 54 |
56 public Wst() { | 55 public Wst() { |
57 } | 56 } |
58 | 57 |
59 public Wst(River river, String description) { | 58 public Wst(final River river, final String description) { |
60 this(river, description, 0); | 59 this(river, description, 0); |
61 } | 60 } |
62 | 61 |
63 public Wst(River river, String description, Integer kind) { | 62 public Wst(final River river, final String description, final Integer kind) { |
64 this.river = river; | 63 this.river = river; |
65 this.description = description; | 64 this.description = description; |
66 this.kind = kind; | 65 this.kind = kind; |
67 } | 66 } |
68 | 67 |
69 @Id | 68 @Id |
70 @SequenceGenerator( | 69 @SequenceGenerator( |
71 name = "SEQUENCE_WSTS_ID_SEQ", | 70 name = "SEQUENCE_WSTS_ID_SEQ", |
72 sequenceName = "WSTS_ID_SEQ", | 71 sequenceName = "WSTS_ID_SEQ", |
73 allocationSize = 1) | 72 allocationSize = 1) |
74 @GeneratedValue( | 73 @GeneratedValue( |
75 strategy = GenerationType.SEQUENCE, | 74 strategy = GenerationType.SEQUENCE, |
76 generator = "SEQUENCE_WSTS_ID_SEQ") | 75 generator = "SEQUENCE_WSTS_ID_SEQ") |
77 @Column(name = "id") | 76 @Column(name = "id") |
78 public Integer getId() { | 77 public Integer getId() { |
79 return id; | 78 return this.id; |
80 } | 79 } |
81 | 80 |
82 public void setId(Integer id) { | 81 public void setId(final Integer id) { |
83 this.id = id; | 82 this.id = id; |
84 } | 83 } |
85 | 84 |
86 @OneToOne | 85 @OneToOne |
87 @JoinColumn(name = "river_id" ) | 86 @JoinColumn(name = "river_id" ) |
88 public River getRiver() { | 87 public River getRiver() { |
89 return river; | 88 return this.river; |
90 } | 89 } |
91 | 90 |
92 public void setRiver(River river) { | 91 public void setRiver(final River river) { |
93 this.river = river; | 92 this.river = river; |
94 } | 93 } |
95 | 94 |
96 @Column(name = "description") | 95 @Column(name = "description") |
97 public String getDescription() { | 96 public String getDescription() { |
98 return description; | 97 return this.description; |
99 } | 98 } |
100 | 99 |
101 public void setDescription(String description) { | 100 public void setDescription(final String description) { |
102 this.description = description; | 101 this.description = description; |
103 } | 102 } |
104 | 103 |
105 @Column(name = "kind") | 104 @Column(name = "kind") |
106 public Integer getKind() { | 105 public Integer getKind() { |
107 return kind; | 106 return this.kind; |
108 } | 107 } |
109 | 108 |
110 public void setKind(Integer kind) { | 109 public void setKind(final Integer kind) { |
111 this.kind = kind; | 110 this.kind = kind; |
111 } | |
112 | |
113 @Column(name = "sinfo_selection") | |
114 public String getSInfoSelection() { | |
115 return this.sinfo_selection; | |
116 } | |
117 | |
118 public void setSInfoSelection(final String sinfoSelection) { | |
119 this.sinfo_selection = sinfoSelection; | |
112 } | 120 } |
113 | 121 |
114 @OneToMany | 122 @OneToMany |
115 @JoinColumn(name="wst_id") | 123 @JoinColumn(name="wst_id") |
116 public List<WstColumn> getColumns() { | 124 public List<WstColumn> getColumns() { |
117 return columns; | 125 return this.columns; |
118 } | 126 } |
119 | 127 |
120 public void setColumns(List<WstColumn> columns) { | 128 public void setColumns(final List<WstColumn> columns) { |
121 this.columns = columns; | 129 this.columns = columns; |
122 } | 130 } |
123 | 131 |
124 | 132 |
125 /** | 133 /** |
128 * the second field. | 136 * the second field. |
129 * | 137 * |
130 * @return the min and max Q values of this WST. | 138 * @return the min and max Q values of this WST. |
131 */ | 139 */ |
132 public double[] determineMinMaxQ() { | 140 public double[] determineMinMaxQ() { |
133 double[] ab = river.determineMinMaxDistance(); | 141 final double[] ab = this.river.determineMinMaxDistance(); |
134 return determineMinMaxQ(new Range(ab[0], ab[1], river)); | 142 return determineMinMaxQ(new Range(ab[0], ab[1], this.river)); |
135 } | 143 } |
136 | 144 |
137 | 145 |
138 /** | 146 /** |
139 * Determines the min and max Q values of this WST in the given range. The | 147 * Determines the min and max Q values of this WST in the given range. The |
142 * | 150 * |
143 * @param range The range used for querying the Q values. | 151 * @param range The range used for querying the Q values. |
144 * | 152 * |
145 * @return the min and max Q values of this WST. | 153 * @return the min and max Q values of this WST. |
146 */ | 154 */ |
147 public double[] determineMinMaxQ(Range range) { | 155 public double[] determineMinMaxQ(final Range range) { |
148 if (range != null) { | 156 if (range != null) { |
149 return determineMinMaxQ( | 157 return determineMinMaxQ( |
150 range.getA().doubleValue(), | 158 range.getA().doubleValue(), |
151 range.getB().doubleValue()); | 159 range.getB().doubleValue()); |
152 } | 160 } |
153 | 161 |
154 return null; | 162 return null; |
155 } | 163 } |
156 | 164 |
163 * @param fromKm the lower km value. | 171 * @param fromKm the lower km value. |
164 * @param toKm the upper km value. | 172 * @param toKm the upper km value. |
165 * | 173 * |
166 * @return the min and max Q values of this WST. | 174 * @return the min and max Q values of this WST. |
167 */ | 175 */ |
168 public double[] determineMinMaxQ(double fromKm, double toKm) { | 176 public double[] determineMinMaxQ(final double fromKm, final double toKm) { |
169 Session session = SessionHolder.HOLDER.get(); | 177 final Session session = SessionHolder.HOLDER.get(); |
170 | 178 |
171 Query query = session.createQuery( | 179 final Query query = session.createQuery( |
172 "select min(q), max(q) from WstQRange where " | 180 "select min(q), max(q) from WstQRange where " |
173 + "id in " | 181 + "id in " |
174 + " (select wstQRange.id from WstColumnQRange where " | 182 + " (select wstQRange.id from WstColumnQRange where " |
175 + " wstColumn.id in (select id from WstColumn where wst.id = :wst)) " | 183 + " wstColumn.id in (select id from WstColumn where wst.id = :wst)) " |
176 + "and range.id in " | 184 + "and range.id in " |
177 + " (select id from Range where not (a > :end or b < :start))"); | 185 + " (select id from Range where not (a > :end or b < :start))"); |
178 | 186 |
179 query.setParameter("wst", getId()); | 187 query.setParameter("wst", getId()); |
180 query.setParameter("start", new BigDecimal(fromKm)); | 188 query.setParameter("start", new BigDecimal(fromKm)); |
181 query.setParameter("end", new BigDecimal(toKm)); | 189 query.setParameter("end", new BigDecimal(toKm)); |
182 | 190 |
183 List<Object []> results = query.list(); | 191 final List<Object []> results = query.list(); |
184 | 192 |
185 if (results.isEmpty()) { | 193 if (results.isEmpty()) { |
186 return null; | 194 return null; |
187 } | 195 } |
188 | 196 |
189 if (results.get(0)[0] == null || results.get(0)[1] == null) { | 197 if (results.get(0)[0] == null || results.get(0)[1] == null) { |
190 log.warn("Could not process result from min/maxQ query."); | 198 log.warn("Could not process result from min/maxQ query."); |
191 return null; | 199 return null; |
192 } | 200 } |
193 | 201 |
194 Object [] result = results.get(0); | 202 final Object [] result = results.get(0); |
195 | 203 |
196 return new double [] { | 204 return new double [] { |
197 ((BigDecimal)result[0]).doubleValue(), | 205 ((BigDecimal)result[0]).doubleValue(), |
198 ((BigDecimal)result[1]).doubleValue() }; | 206 ((BigDecimal)result[1]).doubleValue() }; |
199 } | 207 } |
200 | 208 |
201 | 209 |
202 public double[] determineMinMaxQFree(double km) { | 210 public double[] determineMinMaxQFree(final double km) { |
203 Session session = SessionHolder.HOLDER.get(); | 211 final Session session = SessionHolder.HOLDER.get(); |
204 | 212 |
205 SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_MINMAX) | 213 final SQLQuery sqlQuery = session.createSQLQuery(SQL_SELECT_MINMAX) |
206 .addScalar("minQ", StandardBasicTypes.DOUBLE) | 214 .addScalar("minQ", StandardBasicTypes.DOUBLE) |
207 .addScalar("maxQ", StandardBasicTypes.DOUBLE); | 215 .addScalar("maxQ", StandardBasicTypes.DOUBLE); |
208 | 216 |
209 sqlQuery.setInteger("wst", getId()); | 217 sqlQuery.setInteger("wst", getId()); |
210 sqlQuery.setDouble("km", km); | 218 sqlQuery.setDouble("km", km); |
211 | 219 |
212 List<Object[]> minmaxQ = sqlQuery.list(); | 220 final List<Object[]> minmaxQ = sqlQuery.list(); |
213 | 221 |
214 | 222 |
215 if (minmaxQ.isEmpty()) { | 223 if (minmaxQ.isEmpty()) { |
216 return null; | 224 return null; |
217 } | 225 } |
218 | 226 |
219 Object[] mm = minmaxQ.get(0); | 227 final Object[] mm = minmaxQ.get(0); |
220 | 228 |
221 if (mm[0] == null || mm[1] == null) { | 229 if (mm[0] == null || mm[1] == null) { |
222 log.warn("No min/max Q for km " + km + " found."); | 230 log.warn("No min/max Q for km " + km + " found."); |
223 return null; | 231 return null; |
224 } | 232 } |