Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/model/BedHeight.java @ 9074:766890addcb2
state To client communication;
author | gernotbelger |
---|---|
date | Fri, 18 May 2018 17:26:26 +0200 |
parents | 4c5eeaff554c |
children | 02e4a0d983c0 |
comparison
equal
deleted
inserted
replaced
9073:cd650cacc926 | 9074:766890addcb2 |
---|---|
25 | 25 |
26 import org.dive4elements.river.backend.SessionHolder; | 26 import org.dive4elements.river.backend.SessionHolder; |
27 import org.hibernate.Query; | 27 import org.hibernate.Query; |
28 import org.hibernate.Session; | 28 import org.hibernate.Session; |
29 | 29 |
30 | |
31 @Entity | 30 @Entity |
32 @Table(name = "bed_height") | 31 @Table(name = "bed_height") |
33 public class BedHeight implements Serializable { | 32 public class BedHeight implements Serializable { |
34 | 33 |
35 private Integer id; | 34 private Integer id; |
38 private String evaluationBy; | 37 private String evaluationBy; |
39 private String description; | 38 private String description; |
40 | 39 |
41 private River river; | 40 private River river; |
42 | 41 |
43 private BedHeightType type; | 42 private BedHeightType type; |
44 | 43 |
45 private LocationSystem locationSystem; | 44 private LocationSystem locationSystem; |
46 | 45 |
47 private ElevationModel curElevationModel; | 46 private ElevationModel curElevationModel; |
48 | 47 |
53 private String sounding_width_info; | 52 private String sounding_width_info; |
54 private String notes; | 53 private String notes; |
55 | 54 |
56 private List<BedHeightValue> values; | 55 private List<BedHeightValue> values; |
57 | 56 |
58 | |
59 public BedHeight() { | 57 public BedHeight() { |
60 } | 58 } |
61 | 59 |
62 | |
63 public BedHeight(final River river, final Integer year, final BedHeightType type, final LocationSystem locationSystem, | 60 public BedHeight(final River river, final Integer year, final BedHeightType type, final LocationSystem locationSystem, |
64 final ElevationModel curElevationModel, | 61 final ElevationModel curElevationModel, final Range range) { |
65 final Range range) { | |
66 this(river, year, type, locationSystem, curElevationModel, null, range, null, null, null, null); | 62 this(river, year, type, locationSystem, curElevationModel, null, range, null, null, null, null); |
67 } | 63 } |
68 | |
69 | 64 |
70 public BedHeight(final River river, final Integer year, final BedHeightType type, final LocationSystem locationSystem, | 65 public BedHeight(final River river, final Integer year, final BedHeightType type, final LocationSystem locationSystem, |
71 final ElevationModel curElevationModel, final ElevationModel oldElevationModel, final Range range, final String evaluationBy, | 66 final ElevationModel curElevationModel, final ElevationModel oldElevationModel, final Range range, final String evaluationBy, |
72 final String description, final String sounding_width_info, final String notes) { | 67 final String description, final String sounding_width_info, final String notes) { |
73 this.river = river; | 68 this.river = river; |
74 this.year = year; | 69 this.year = year; |
75 this.type = type; | 70 this.type = type; |
76 this.locationSystem = locationSystem; | 71 this.locationSystem = locationSystem; |
77 this.curElevationModel = curElevationModel; | 72 this.curElevationModel = curElevationModel; |
78 this.oldElevationModel = oldElevationModel; | 73 this.oldElevationModel = oldElevationModel; |
79 this.range = range; | 74 this.range = range; |
80 this.evaluationBy = evaluationBy; | 75 this.evaluationBy = evaluationBy; |
81 this.description = description; | 76 this.description = description; |
82 this.sounding_width_info = sounding_width_info; | 77 this.sounding_width_info = sounding_width_info; |
83 this.notes = notes; | 78 this.notes = notes; |
84 } | 79 } |
85 | |
86 | 80 |
87 @Id | 81 @Id |
88 @SequenceGenerator(name = "SEQUENCE_BED_HEIGHT_ID_SEQ", sequenceName = "BED_HEIGHT_ID_SEQ", allocationSize = 1) | 82 @SequenceGenerator(name = "SEQUENCE_BED_HEIGHT_ID_SEQ", sequenceName = "BED_HEIGHT_ID_SEQ", allocationSize = 1) |
89 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_BED_HEIGHT_ID_SEQ") | 83 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_BED_HEIGHT_ID_SEQ") |
90 @Column(name = "id") | 84 @Column(name = "id") |
209 | 203 |
210 public void setValues(final List<BedHeightValue> values) { | 204 public void setValues(final List<BedHeightValue> values) { |
211 this.values = values; | 205 this.values = values; |
212 } | 206 } |
213 | 207 |
214 | 208 public static List<BedHeight> getBedHeights(final River river, final double kmLo, final double kmHi) { |
215 public static List<BedHeight> getBedHeights( | |
216 final River river, | |
217 final double kmLo, | |
218 final double kmHi | |
219 ) { | |
220 final Session session = SessionHolder.HOLDER.get(); | 209 final Session session = SessionHolder.HOLDER.get(); |
221 | 210 |
222 final Query query = session.createQuery( | 211 final Query query = session.createQuery("from BedHeight where river=:river"); |
223 "from BedHeight where river=:river"); | |
224 | 212 |
225 query.setParameter("river", river); | 213 query.setParameter("river", river); |
226 | 214 |
227 // TODO Do km range filtering in SQL statement | 215 // TODO Do km range filtering in SQL statement |
228 | 216 |
229 final List<BedHeight> singles = query.list(); | 217 final List<BedHeight> singles = query.list(); |
230 final List<BedHeight> good = new ArrayList<>(); | 218 final List<BedHeight> good = new ArrayList<>(); |
231 | 219 |
232 for (final BedHeight s: singles) { | 220 for (final BedHeight s : singles) { |
233 for (final BedHeightValue value: s.getValues()) { | 221 for (final BedHeightValue value : s.getValues()) { |
234 final double station = value.getStation().doubleValue(); | 222 final double station = value.getStation().doubleValue(); |
235 | 223 |
236 if (station >= kmLo && station <= kmHi) { | 224 if (station >= kmLo && station <= kmHi) { |
237 good.add(s); | 225 good.add(s); |
238 break; | 226 break; |
241 } | 229 } |
242 | 230 |
243 return good; | 231 return good; |
244 } | 232 } |
245 | 233 |
246 | |
247 public static BedHeight getBedHeightById(final int id) { | 234 public static BedHeight getBedHeightById(final int id) { |
248 final Session session = SessionHolder.HOLDER.get(); | 235 final Session session = SessionHolder.HOLDER.get(); |
249 | 236 |
250 final Query query = session.createQuery( | 237 final Query query = session.createQuery("from BedHeight where id=:id"); |
251 "from BedHeight where id=:id"); | |
252 | 238 |
253 query.setParameter("id", id); | 239 query.setParameter("id", id); |
254 | 240 |
255 final List<BedHeight> singles = query.list(); | 241 final List<BedHeight> singles = query.list(); |
256 | 242 |