Mercurial > dive4elements > river
comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4097:83c72bc07591
Load all discharge tables from AFT and FLYS of a gauge which needs updating.
flys-aft/trunk@3618 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 06 Jan 2012 18:32:08 +0000 |
parents | b20b710aa86f |
children | 9215253ad0be |
comparison
equal
deleted
inserted
replaced
4096:82f5266f881b | 4097:83c72bc07591 |
---|---|
2 | 2 |
3 import java.util.List; | 3 import java.util.List; |
4 import java.util.ArrayList; | 4 import java.util.ArrayList; |
5 import java.util.HashMap; | 5 import java.util.HashMap; |
6 import java.util.Map; | 6 import java.util.Map; |
7 import java.util.Date; | |
8 | 7 |
9 import java.sql.ResultSet; | 8 import java.sql.ResultSet; |
10 import java.sql.SQLException; | 9 import java.sql.SQLException; |
11 import java.sql.Types; | 10 import java.sql.Types; |
12 | 11 |
74 "' is assigned to river '" + gaugeRiver + | 73 "' is assigned to river '" + gaugeRiver + |
75 "'. Needs to be on '" + riverName + "'."); | 74 "'. Needs to be on '" + riverName + "'."); |
76 continue; | 75 continue; |
77 } | 76 } |
78 dipsGauge.setAftName(name); | 77 dipsGauge.setAftName(name); |
78 dipsGauge.setOfficialNumber(number); | |
79 aftDIPSGauges.put(number, dipsGauge); | 79 aftDIPSGauges.put(number, dipsGauge); |
80 } | 80 } |
81 | 81 |
82 messstellenRs.close(); | 82 messstellenRs.close(); |
83 | 83 |
110 updateGauges.add(aftDIPSGauge); | 110 updateGauges.add(aftDIPSGauge); |
111 } | 111 } |
112 gaugesRs.close(); | 112 gaugesRs.close(); |
113 | 113 |
114 boolean modified = createGauges(context, aftDIPSGauges); | 114 boolean modified = createGauges(context, aftDIPSGauges); |
115 | |
116 modified |= updateGauges(context, updateGauges); | |
117 | |
118 return modified; | |
119 } | |
120 | |
121 protected boolean updateGauges( | |
122 SyncContext context, | |
123 List<DIPSGauge> gauges | |
124 ) | |
125 throws SQLException | |
126 { | |
127 boolean modified = false; | |
128 | |
129 for (DIPSGauge gauge: gauges) { | |
130 modified |= updateGauge(context, gauge); | |
131 } | |
132 | |
133 return modified; | |
134 } | |
135 | |
136 protected boolean updateGauge( | |
137 SyncContext context, | |
138 DIPSGauge gauge | |
139 ) | |
140 throws SQLException | |
141 { | |
142 // We need to load all discharge tables from both database | |
143 // of the gauge and do some pairing based on their descriptions. | |
144 | |
145 boolean modified = false; | |
146 | |
147 List<DischargeTable> flysDTs = | |
148 DischargeTable.loadFlysDischargeTables( | |
149 context, gauge.getFlysId()); | |
150 | |
151 List<DischargeTable> aftDTs = | |
152 DischargeTable.loadAftDischargeTables( | |
153 context, gauge.getOfficialNumber()); | |
154 | |
155 // TODO: Do pairing | |
115 | 156 |
116 return modified; | 157 return modified; |
117 } | 158 } |
118 | 159 |
119 protected boolean createGauges( | 160 protected boolean createGauges( |
214 Long officialNumber, | 255 Long officialNumber, |
215 DIPSGauge gauge | 256 DIPSGauge gauge |
216 ) | 257 ) |
217 throws SQLException | 258 throws SQLException |
218 { | 259 { |
219 boolean debug = log.isDebugEnabled(); | 260 return DischargeTable.loadAftDischargeTables( |
220 | 261 context, officialNumber, gauge.getFlysId()); |
221 List<DischargeTable> dts = new ArrayList<DischargeTable>(); | |
222 | |
223 ResultSet rs = null; | |
224 try { | |
225 rs = context | |
226 .getAftStatements() | |
227 .getStatement("select.abflusstafel") | |
228 .clearParameters() | |
229 .setString("number", "%" + officialNumber). | |
230 executeQuery(); | |
231 | |
232 while (rs.next()) { | |
233 int dtId = rs.getInt("ABFLUSSTAFEL_NR"); | |
234 Date from = rs.getDate("GUELTIG_VON"); | |
235 Date to = rs.getDate("GUELTIG_BIS"); | |
236 String description = rs.getString("ABFLUSSTAFEL_BEZ"); | |
237 if (description == null) { | |
238 description = String.valueOf(officialNumber); | |
239 } | |
240 | |
241 double datumValue = rs.getDouble("PEGELNULLPUNKT"); | |
242 Double datum = rs.wasNull() ? null : datumValue; | |
243 | |
244 if (debug) { | |
245 log.debug("id: " + dtId); | |
246 log.debug("valid from: " + from); | |
247 log.debug("valid to: " + to); | |
248 log.debug("datum: " + datum); | |
249 log.debug("description: " + description); | |
250 } | |
251 | |
252 TimeInterval timeInterval = from == null | |
253 ? null | |
254 : new TimeInterval(from, to); | |
255 | |
256 DischargeTable dt = new DischargeTable( | |
257 dtId, | |
258 gauge.getFlysId(), | |
259 timeInterval, | |
260 description); | |
261 dts.add(dt); | |
262 } | |
263 } | |
264 finally { | |
265 if (rs != null) { | |
266 rs.close(); | |
267 rs = null; | |
268 } | |
269 } | |
270 | |
271 return dts; | |
272 } | 262 } |
273 | 263 |
274 protected void persistFlysTimeIntervals( | 264 protected void persistFlysTimeIntervals( |
275 SyncContext context, | 265 SyncContext context, |
276 List<DischargeTable> dts | 266 List<DischargeTable> dts |