Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/model/BedHeightSingle.java @ 3962:d609fd83310a
merged flys-backend
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:15:04 +0200 |
parents | 5d8db3349b77 |
children |
comparison
equal
deleted
inserted
replaced
3938:c0cab28ba1ea | 3962:d609fd83310a |
---|---|
1 package de.intevation.flys.model; | |
2 | |
3 import java.io.Serializable; | |
4 | |
5 import java.util.ArrayList; | |
6 import java.util.List; | |
7 | |
8 import javax.persistence.Entity; | |
9 import javax.persistence.Id; | |
10 import javax.persistence.Table; | |
11 import javax.persistence.GeneratedValue; | |
12 import javax.persistence.Column; | |
13 import javax.persistence.SequenceGenerator; | |
14 import javax.persistence.GenerationType; | |
15 import javax.persistence.JoinColumn; | |
16 import javax.persistence.OneToOne; | |
17 import javax.persistence.OneToMany; | |
18 | |
19 import org.hibernate.Session; | |
20 import org.hibernate.Query; | |
21 | |
22 import de.intevation.flys.backend.SessionHolder; | |
23 | |
24 | |
25 @Entity | |
26 @Table(name = "bed_height_single") | |
27 public class BedHeightSingle implements Serializable { | |
28 | |
29 private Integer id; | |
30 private Integer year; | |
31 private Integer soundingWidth; | |
32 | |
33 private String evaluationBy; | |
34 private String description; | |
35 | |
36 private River river; | |
37 | |
38 private BedHeightType type; | |
39 | |
40 private LocationSystem locationSystem; | |
41 | |
42 private ElevationModel curElevationModel; | |
43 | |
44 private ElevationModel oldElevationModel; | |
45 | |
46 private Range range; | |
47 | |
48 private List<BedHeightSingleValue> values; | |
49 | |
50 | |
51 public BedHeightSingle() { | |
52 } | |
53 | |
54 | |
55 public BedHeightSingle( | |
56 River river, | |
57 Integer year, | |
58 Integer soundingWidth, | |
59 BedHeightType type, | |
60 LocationSystem locationSystem, | |
61 ElevationModel curElevationModel, | |
62 Range range | |
63 ) { | |
64 this( | |
65 river, | |
66 year, | |
67 soundingWidth, | |
68 type, | |
69 locationSystem, | |
70 curElevationModel, | |
71 null, | |
72 range, | |
73 null, | |
74 null); | |
75 } | |
76 | |
77 | |
78 public BedHeightSingle( | |
79 River river, | |
80 Integer year, | |
81 Integer soundingWidth, | |
82 BedHeightType type, | |
83 LocationSystem locationSystem, | |
84 ElevationModel curElevationModel, | |
85 ElevationModel oldElevationModel, | |
86 Range range, | |
87 String evaluationBy, | |
88 String description | |
89 ) { | |
90 this.river = river; | |
91 this.year = year; | |
92 this.soundingWidth = soundingWidth; | |
93 this.type = type; | |
94 this.locationSystem = locationSystem; | |
95 this.curElevationModel = curElevationModel; | |
96 this.oldElevationModel = oldElevationModel; | |
97 this.range = range; | |
98 this.evaluationBy = evaluationBy; | |
99 this.description = description; | |
100 } | |
101 | |
102 | |
103 @Id | |
104 @SequenceGenerator( | |
105 name = "SEQUENCE_BED_HEIGHT_SINGLE_ID_SEQ", | |
106 sequenceName = "BED_HEIGHT_SINGLE_ID_SEQ", | |
107 allocationSize = 1) | |
108 @GeneratedValue( | |
109 strategy = GenerationType.SEQUENCE, | |
110 generator = "SEQUENCE_BED_HEIGHT_SINGLE_ID_SEQ") | |
111 @Column(name = "id") | |
112 public Integer getId() { | |
113 return id; | |
114 } | |
115 | |
116 public void setId(Integer id) { | |
117 this.id = id; | |
118 } | |
119 | |
120 @OneToOne | |
121 @JoinColumn(name = "river_id" ) | |
122 public River getRiver() { | |
123 return river; | |
124 } | |
125 | |
126 public void setRiver(River river) { | |
127 this.river = river; | |
128 } | |
129 | |
130 @Column(name = "year") | |
131 public Integer getYear() { | |
132 return year; | |
133 } | |
134 | |
135 public void setYear(Integer year) { | |
136 this.year = year; | |
137 } | |
138 | |
139 @Column(name = "sounding_width") | |
140 public Integer getSoundingWidth() { | |
141 return soundingWidth; | |
142 } | |
143 | |
144 public void setSoundingWidth(Integer soundingWidth) { | |
145 this.soundingWidth = soundingWidth; | |
146 } | |
147 | |
148 @OneToOne | |
149 @JoinColumn(name = "type_id") | |
150 public BedHeightType getType() { | |
151 return type; | |
152 } | |
153 | |
154 public void setType(BedHeightType type) { | |
155 this.type = type; | |
156 } | |
157 | |
158 @OneToOne | |
159 @JoinColumn(name = "location_system_id") | |
160 public LocationSystem getLocationSystem() { | |
161 return locationSystem; | |
162 } | |
163 | |
164 public void setLocationSystem(LocationSystem locationSystem) { | |
165 this.locationSystem = locationSystem; | |
166 } | |
167 | |
168 @OneToOne | |
169 @JoinColumn(name = "cur_elevation_model_id") | |
170 public ElevationModel getCurElevationModel() { | |
171 return curElevationModel; | |
172 } | |
173 | |
174 public void setCurElevationModel(ElevationModel curElevationModel) { | |
175 this.curElevationModel = curElevationModel; | |
176 } | |
177 | |
178 @OneToOne | |
179 @JoinColumn(name = "old_elevation_model_id") | |
180 public ElevationModel getOldElevationModel() { | |
181 return oldElevationModel; | |
182 } | |
183 | |
184 public void setOldElevationModel(ElevationModel oldElevationModel) { | |
185 this.oldElevationModel = oldElevationModel; | |
186 } | |
187 | |
188 @OneToOne | |
189 @JoinColumn(name = "range_id") | |
190 public Range getRange() { | |
191 return range; | |
192 } | |
193 | |
194 public void setRange(Range range) { | |
195 this.range = range; | |
196 } | |
197 | |
198 @Column(name = "evaluation_by") | |
199 public String getEvaluationBy() { | |
200 return evaluationBy; | |
201 } | |
202 | |
203 public void setEvaluationBy(String evaluationBy) { | |
204 this.evaluationBy = evaluationBy; | |
205 } | |
206 | |
207 @Column(name = "description") | |
208 public String getDescription() { | |
209 return description; | |
210 } | |
211 | |
212 public void setDescription(String description) { | |
213 this.description = description; | |
214 } | |
215 | |
216 @OneToMany | |
217 @JoinColumn(name = "bed_height_single_id") | |
218 public List<BedHeightSingleValue> getValues() { | |
219 return values; | |
220 } | |
221 | |
222 public void setValues(List<BedHeightSingleValue> values) { | |
223 this.values = values; | |
224 } | |
225 | |
226 | |
227 public static List<BedHeightSingle> getBedHeightSingles( | |
228 River river, | |
229 double kmLo, | |
230 double kmHi | |
231 ) { | |
232 Session session = SessionHolder.HOLDER.get(); | |
233 | |
234 Query query = session.createQuery( | |
235 "from BedHeightSingle where river=:river"); | |
236 | |
237 query.setParameter("river", river); | |
238 | |
239 // TODO Do km range filtering in SQL statement | |
240 | |
241 List<BedHeightSingle> singles = query.list(); | |
242 List<BedHeightSingle> good = new ArrayList<BedHeightSingle>(); | |
243 | |
244 for (BedHeightSingle s: singles) { | |
245 for (BedHeightSingleValue value: s.getValues()) { | |
246 double station = value.getStation().doubleValue(); | |
247 | |
248 if (station >= kmLo && station <= kmHi) { | |
249 good.add(s); | |
250 break; | |
251 } | |
252 } | |
253 } | |
254 | |
255 return good; | |
256 } | |
257 | |
258 | |
259 public static BedHeightSingle getBedHeightSingleById(int id) { | |
260 Session session = SessionHolder.HOLDER.get(); | |
261 | |
262 Query query = session.createQuery( | |
263 "from BedHeightSingle where id=:id"); | |
264 | |
265 query.setParameter("id", id); | |
266 | |
267 List<BedHeightSingle> singles = query.list(); | |
268 | |
269 return singles != null ? singles.get(0) : null; | |
270 } | |
271 } | |
272 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |