Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/model/BedHeightEpoch.java @ 2877:f0a67bc0e777 2.7
merged flys-backend/2.7
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:31 +0200 |
parents | 444e52222941 |
children | b9a99fcc78c3 |
comparison
equal
deleted
inserted
replaced
2793:6310b1582f2d | 2877:f0a67bc0e777 |
---|---|
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_epoch") | |
27 public class BedHeightEpoch implements Serializable { | |
28 | |
29 private Integer id; | |
30 | |
31 private River river; | |
32 | |
33 private TimeInterval timeInterval; | |
34 | |
35 private ElevationModel curElevationModel; | |
36 private ElevationModel oldElevationModel; | |
37 | |
38 private Range range; | |
39 | |
40 private String evaluationBy; | |
41 private String description; | |
42 | |
43 private List<BedHeightEpochValue> values; | |
44 | |
45 | |
46 public BedHeightEpoch() { | |
47 } | |
48 | |
49 | |
50 public BedHeightEpoch( | |
51 River river, | |
52 TimeInterval timeInterval, | |
53 Range range, | |
54 ElevationModel curElevationModel, | |
55 ElevationModel oldElevationModel, | |
56 String evaluationBy, | |
57 String description | |
58 ) { | |
59 this.river = river; | |
60 this.timeInterval = timeInterval; | |
61 this.range = range; | |
62 this.curElevationModel = curElevationModel; | |
63 this.oldElevationModel = oldElevationModel; | |
64 this.evaluationBy = evaluationBy; | |
65 this.description = description; | |
66 this.values = new ArrayList<BedHeightEpochValue>(); | |
67 } | |
68 | |
69 | |
70 @Id | |
71 @SequenceGenerator( | |
72 name = "SEQUENCE_BED_HEIGHT_EPOCH_ID_SEQ", | |
73 sequenceName = "BED_HEIGHT_EPOCH_ID_SEQ", | |
74 allocationSize = 1) | |
75 @GeneratedValue( | |
76 strategy = GenerationType.SEQUENCE, | |
77 generator = "SEQUENCE_BED_HEIGHT_EPOCH_ID_SEQ") | |
78 @Column(name = "id") | |
79 public Integer getId() { | |
80 return id; | |
81 } | |
82 | |
83 public void setId(Integer id) { | |
84 this.id = id; | |
85 } | |
86 | |
87 @OneToOne | |
88 @JoinColumn(name = "river_id" ) | |
89 public River getRiver() { | |
90 return river; | |
91 } | |
92 | |
93 public void setRiver(River river) { | |
94 this.river = river; | |
95 } | |
96 | |
97 @OneToOne | |
98 @JoinColumn(name = "time_interval_id") | |
99 public TimeInterval getTimeInterval() { | |
100 return timeInterval; | |
101 } | |
102 | |
103 public void setTimeInterval(TimeInterval timeInterval) { | |
104 this.timeInterval = timeInterval; | |
105 } | |
106 | |
107 @OneToOne | |
108 @JoinColumn(name = "cur_elevation_model_id") | |
109 public ElevationModel getCurElevationModel() { | |
110 return curElevationModel; | |
111 } | |
112 | |
113 public void setCurElevationModel(ElevationModel curElevationModel) { | |
114 this.curElevationModel = curElevationModel; | |
115 } | |
116 | |
117 @OneToOne | |
118 @JoinColumn(name = "old_elevation_model_id") | |
119 public ElevationModel getOldElevationModel() { | |
120 return oldElevationModel; | |
121 } | |
122 | |
123 public void setOldElevationModel(ElevationModel oldElevationModel) { | |
124 this.oldElevationModel = oldElevationModel; | |
125 } | |
126 | |
127 @OneToOne | |
128 @JoinColumn(name = "range_id") | |
129 public Range getRange() { | |
130 return range; | |
131 } | |
132 | |
133 public void setRange(Range range) { | |
134 this.range = range; | |
135 } | |
136 | |
137 @Column(name = "evaluation_by") | |
138 public String getEvaluationBy() { | |
139 return evaluationBy; | |
140 } | |
141 | |
142 public void setEvaluationBy(String evaluationBy) { | |
143 this.evaluationBy = evaluationBy; | |
144 } | |
145 | |
146 @Column(name = "description") | |
147 public String getDescription() { | |
148 return description; | |
149 } | |
150 | |
151 public void setDescription(String description) { | |
152 this.description = description; | |
153 } | |
154 | |
155 @OneToMany | |
156 @JoinColumn(name = "bed_height_epoch_id") | |
157 public List<BedHeightEpochValue> getValues() { | |
158 return values; | |
159 } | |
160 | |
161 public void setValues(List<BedHeightEpochValue> values) { | |
162 this.values = values; | |
163 } | |
164 | |
165 | |
166 public static List<BedHeightEpoch> getBedHeightEpochs( | |
167 River river, | |
168 double kmLo, | |
169 double kmHi | |
170 ) { | |
171 Session session = SessionHolder.HOLDER.get(); | |
172 | |
173 Query query = session.createQuery( | |
174 "from BedHeightEpoch where river=:river"); | |
175 | |
176 query.setParameter("river", river); | |
177 | |
178 // TODO Do km range filtering in SQL statement | |
179 | |
180 List<BedHeightEpoch> epochs = query.list(); | |
181 List<BedHeightEpoch> good = new ArrayList<BedHeightEpoch>(); | |
182 | |
183 for (BedHeightEpoch e: epochs) { | |
184 OUTER: | |
185 for (BedHeightEpochValue value: e.getValues()) { | |
186 double station = value.getStation().doubleValue(); | |
187 | |
188 if (station >= kmLo && station <= kmHi) { | |
189 good.add(e); | |
190 continue OUTER; | |
191 } | |
192 } | |
193 } | |
194 | |
195 return good; | |
196 } | |
197 | |
198 | |
199 public static BedHeightEpoch getBedHeightEpochById(int id) { | |
200 Session session = SessionHolder.HOLDER.get(); | |
201 | |
202 Query query = session.createQuery( | |
203 "from BedHeightEpoch where id=:id"); | |
204 | |
205 query.setParameter("id", id); | |
206 | |
207 List<BedHeightEpoch> singles = query.list(); | |
208 | |
209 return singles != null ? singles.get(0) : null; | |
210 } | |
211 } | |
212 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |