comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 5258:da1e897c7224

Set the BFG_ID for current discharge tables in FLYS.
author Sascha L. Teichmann <teichmann@intevation.de>
date Tue, 12 Mar 2013 19:15:18 +0100
parents 2b7f44c80857
children 7a68967ca72a
comparison
equal deleted inserted replaced
5257:46e984a3d576 5258:da1e897c7224
85 while (messstellenRs.next()) { 85 while (messstellenRs.next()) {
86 String name = messstellenRs.getString("NAME"); 86 String name = messstellenRs.getString("NAME");
87 String num = messstellenRs.getString("MESSSTELLE_NR"); 87 String num = messstellenRs.getString("MESSSTELLE_NR");
88 double station = messstellenRs.getDouble("STATIONIERUNG"); 88 double station = messstellenRs.getDouble("STATIONIERUNG");
89 89
90 if (!messstellenRs.wasNull() && station < from && station > to) { 90 if (!messstellenRs.wasNull() && !inside(station)) {
91 log.warn("Station found in AFT but in range: " + station); 91 log.warn("Station found in AFT but in not range: " + station);
92 continue; 92 continue;
93 } 93 }
94 94
95 Long number = SyncContext.numberToLong(num); 95 Long number = SyncContext.numberToLong(num);
96 if (number == null) { 96 if (number == null) {
169 throws SQLException 169 throws SQLException
170 { 170 {
171 boolean modified = false; 171 boolean modified = false;
172 172
173 for (DIPSGauge gauge: gauges) { 173 for (DIPSGauge gauge: gauges) {
174 modified |= updateBfGIdOnMasterDischargeTable(context, gauge);
174 modified |= updateGauge(context, gauge); 175 modified |= updateGauge(context, gauge);
175 } 176 }
176 177
177 return modified; 178 return modified;
179 }
180
181 protected boolean updateBfGIdOnMasterDischargeTable(
182 SyncContext context,
183 DIPSGauge gauge
184 ) throws SQLException {
185 log.info(
186 "FLYS: Updating master discharge table bfg_id for '" +
187 gauge.getAftName() + "'");
188 ConnectedStatements flysStatements = context.getFlysStatements();
189
190 ResultSet rs = flysStatements
191 .getStatement("select.gauge.master.discharge.table")
192 .clearParameters()
193 .setInt("gauge_id", gauge.getFlysId())
194 .executeQuery();
195
196 int flysId;
197
198 try {
199 if (rs.next()) {
200 log.error(
201 "FLYS: No master discharge table found for gauge '" +
202 gauge.getAftName() + "'");
203 return false;
204 }
205 String bfgId = rs.getString("bfg_id");
206 if (!rs.wasNull()) { // already has BFG_ID
207 return false;
208 }
209 flysId = rs.getInt("id");
210 } finally {
211 rs.close();
212 }
213
214 // We need to find out the BFG_ID of the current discharge table
215 // for this gauge in AFT.
216
217 ConnectedStatements aftStatements = context.getAftStatements();
218
219 rs = aftStatements
220 .getStatement("select.bfg.id.current")
221 .clearParameters()
222 .setString("number", "%" + gauge.getOfficialNumber())
223 .executeQuery();
224
225 String bfgId = null;
226
227 try {
228 if (rs.next()) {
229 bfgId = rs.getString("BFG_ID");
230 }
231 } finally {
232 rs.close();
233 }
234
235 if (bfgId == null) {
236 log.warn(
237 "No BFG_ID found for current discharge table of gauge '" +
238 gauge + "'");
239 return false;
240 }
241
242 // Set the BFG_ID in FLYS.
243 flysStatements.beginTransaction();
244 try {
245 flysStatements
246 .getStatement("update.bfg.id.discharge.table")
247 .clearParameters()
248 .setInt("id", flysId)
249 .setString("bfg_id", bfgId)
250 .executeUpdate();
251 flysStatements.commitTransaction();
252 } catch (SQLException sqle) {
253 flysStatements.rollbackTransaction();
254 log.error(sqle, sqle);
255 return false;
256 }
257
258 return true;
178 } 259 }
179 260
180 protected boolean updateGauge( 261 protected boolean updateGauge(
181 SyncContext context, 262 SyncContext context,
182 DIPSGauge gauge 263 DIPSGauge gauge

http://dive4elements.wald.intevation.org