Mercurial > dive4elements > river
comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4093:7bddd4601707
Copy over W/Q values from AFT to FLYS for new discharge tables.
flys-aft/trunk@3603 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 05 Jan 2012 17:46:18 +0000 |
parents | d556e29592f5 |
children | b20b710aa86f |
comparison
equal
deleted
inserted
replaced
4092:b3fc044f75ba | 4093:7bddd4601707 |
---|---|
189 ) | 189 ) |
190 throws SQLException | 190 throws SQLException |
191 { | 191 { |
192 log.info("create discharge tables"); | 192 log.info("create discharge tables"); |
193 | 193 |
194 // Load the discharge tables from AFT. | |
195 List<DischargeTable> dts = loadAftDischargeTables( | |
196 context, officialNumber, gauge); | |
197 | |
198 // Persist the time intervals. | |
199 persistFlysTimeIntervals(context, dts); | |
200 | |
201 // Persist the discharge tables | |
202 int [] flysDTIds = persistFlysDischargeTables(context, dts); | |
203 | |
204 // Copy over the W/Q values | |
205 copyWQsFromAftToFlys(context, dts, flysDTIds); | |
206 } | |
207 | |
208 protected List<DischargeTable> loadAftDischargeTables( | |
209 SyncContext context, | |
210 Long officialNumber, | |
211 DIPSGauge gauge | |
212 ) | |
213 throws SQLException | |
214 { | |
194 boolean debug = log.isDebugEnabled(); | 215 boolean debug = log.isDebugEnabled(); |
195 | |
196 ConnectedStatements flysStatements = context.getFlysStatements(); | |
197 ConnectedStatements aftStatements = context.getAftStatements(); | |
198 | 216 |
199 List<DischargeTable> dts = new ArrayList<DischargeTable>(); | 217 List<DischargeTable> dts = new ArrayList<DischargeTable>(); |
200 | 218 |
201 ResultSet rs = null; | 219 ResultSet rs = null; |
202 try { | 220 try { |
203 rs = aftStatements.getStatement("select.abflusstafel") | 221 rs = context |
222 .getAftStatements() | |
223 .getStatement("select.abflusstafel") | |
204 .clearParameters() | 224 .clearParameters() |
205 .setString("number", "%" + officialNumber). | 225 .setString("number", "%" + officialNumber). |
206 executeQuery(); | 226 executeQuery(); |
207 | 227 |
208 while (rs.next()) { | 228 while (rs.next()) { |
228 TimeInterval timeInterval = from == null | 248 TimeInterval timeInterval = from == null |
229 ? null | 249 ? null |
230 : new TimeInterval(from, to); | 250 : new TimeInterval(from, to); |
231 | 251 |
232 DischargeTable dt = new DischargeTable( | 252 DischargeTable dt = new DischargeTable( |
253 dtId, | |
233 gauge.getFlysId(), | 254 gauge.getFlysId(), |
234 timeInterval, | 255 timeInterval, |
235 description); | 256 description); |
236 dts.add(dt); | 257 dts.add(dt); |
237 } | 258 } |
241 rs.close(); | 262 rs.close(); |
242 rs = null; | 263 rs = null; |
243 } | 264 } |
244 } | 265 } |
245 | 266 |
246 // Persist the time intervals. | 267 return dts; |
268 } | |
269 | |
270 protected void persistFlysTimeIntervals( | |
271 SyncContext context, | |
272 List<DischargeTable> dts | |
273 ) | |
274 throws SQLException | |
275 { | |
247 for (DischargeTable dt: dts) { | 276 for (DischargeTable dt: dts) { |
248 TimeInterval timeInterval = dt.getTimeInterval(); | 277 TimeInterval timeInterval = dt.getTimeInterval(); |
249 if (timeInterval != null) { | 278 if (timeInterval != null) { |
250 dt.setTimeInterval( | 279 dt.setTimeInterval( |
251 context.fetchOrCreateFLYSTimeInterval(timeInterval)); | 280 context.fetchOrCreateFLYSTimeInterval(timeInterval)); |
252 } | 281 } |
253 } | 282 } |
254 | 283 } |
255 // Persist the discharge tables | 284 |
285 protected int [] persistFlysDischargeTables( | |
286 SyncContext context, | |
287 List<DischargeTable> dts | |
288 ) | |
289 throws SQLException | |
290 { | |
291 boolean debug = log.isDebugEnabled(); | |
292 | |
293 int [] flysDTIds = new int[dts.size()]; | |
294 | |
295 ResultSet rs = null; | |
256 try { | 296 try { |
297 ConnectedStatements flysStatements = | |
298 context.getFlysStatements(); | |
299 | |
257 SymbolicStatement.Instance nextId = | 300 SymbolicStatement.Instance nextId = |
258 flysStatements.getStatement("next.discharge.id"); | 301 flysStatements.getStatement("next.discharge.id"); |
259 | 302 |
260 SymbolicStatement.Instance insertDT = | 303 SymbolicStatement.Instance insertDT = |
261 flysStatements.getStatement("insert.dischargetable"); | 304 flysStatements.getStatement("insert.dischargetable"); |
262 | 305 |
263 for (DischargeTable dt: dts) { | 306 for (int i = 0; i < flysDTIds.length; ++i) { |
264 rs = nextId.executeQuery(); | 307 rs = nextId.executeQuery(); |
265 rs.next(); | 308 rs.next(); |
266 int id = rs.getInt("discharge_table_id"); | 309 int id = rs.getInt("discharge_table_id"); |
310 flysDTIds[i] = id; | |
267 rs.close(); rs = null; | 311 rs.close(); rs = null; |
268 | 312 |
313 DischargeTable dt = dts.get(i); | |
269 insertDT.clearParameters() | 314 insertDT.clearParameters() |
270 .setInt("id", id) | 315 .setInt("id", id) |
271 .setInt("gauge_id", dt.getGaugeId()) | 316 .setInt("gauge_id", dt.getGaugeId()) |
272 .setString("description", dt.getDescription()); | 317 .setString("description", dt.getDescription()); |
273 | 318 |
289 if (rs != null) { | 334 if (rs != null) { |
290 rs.close(); | 335 rs.close(); |
291 rs = null; | 336 rs = null; |
292 } | 337 } |
293 } | 338 } |
339 | |
340 return flysDTIds; | |
341 } | |
342 | |
343 protected void copyWQsFromAftToFlys( | |
344 SyncContext context, | |
345 List<DischargeTable> dts, | |
346 int [] flysDTIds | |
347 ) | |
348 throws SQLException | |
349 { | |
350 for (int i = 0; i < flysDTIds.length; ++i) { | |
351 DischargeTable dt = dts.get(i); | |
352 dt.loadAftValues(context); | |
353 dt.storeFlysValues(context, flysDTIds[i]); | |
354 dt.clearValues(); // To save memory. | |
355 } | |
294 } | 356 } |
295 | 357 |
296 public String toString() { | 358 public String toString() { |
297 return "[River: name=" + name + ", " + super.toString() + "]"; | 359 return "[River: name=" + name + ", " + super.toString() + "]"; |
298 } | 360 } |