Mercurial > dive4elements > river
comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4090:d556e29592f5
Create new discharge tables if needed.
flys-aft/trunk@3590 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 04 Jan 2012 17:59:26 +0000 |
parents | 52cde7fe742a |
children | 7bddd4601707 |
comparison
equal
deleted
inserted
replaced
4089:859b4781554a | 4090:d556e29592f5 |
---|---|
6 import java.util.Map; | 6 import java.util.Map; |
7 import java.util.Date; | 7 import java.util.Date; |
8 | 8 |
9 import java.sql.ResultSet; | 9 import java.sql.ResultSet; |
10 import java.sql.SQLException; | 10 import java.sql.SQLException; |
11 import java.sql.Types; | |
11 | 12 |
12 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
13 | 14 |
14 import de.intevation.db.ConnectedStatements; | 15 import de.intevation.db.ConnectedStatements; |
15 import de.intevation.db.SymbolicStatement; | 16 import de.intevation.db.SymbolicStatement; |
193 boolean debug = log.isDebugEnabled(); | 194 boolean debug = log.isDebugEnabled(); |
194 | 195 |
195 ConnectedStatements flysStatements = context.getFlysStatements(); | 196 ConnectedStatements flysStatements = context.getFlysStatements(); |
196 ConnectedStatements aftStatements = context.getAftStatements(); | 197 ConnectedStatements aftStatements = context.getAftStatements(); |
197 | 198 |
199 List<DischargeTable> dts = new ArrayList<DischargeTable>(); | |
200 | |
198 ResultSet rs = null; | 201 ResultSet rs = null; |
199 try { | 202 try { |
200 rs = aftStatements.getStatement("select.abflusstafel") | 203 rs = aftStatements.getStatement("select.abflusstafel") |
201 .clearParameters() | 204 .clearParameters() |
202 .setString("number", "%" + officialNumber). | 205 .setString("number", "%" + officialNumber). |
203 executeQuery(); | 206 executeQuery(); |
204 | 207 |
205 while (rs.next()) { | 208 while (rs.next()) { |
206 int dtId = rs.getInt("ABFLUSSTAFEL_NR"); | 209 int dtId = rs.getInt("ABFLUSSTAFEL_NR"); |
207 Date from = rs.getDate("GUELTIG_VON"); | 210 Date from = rs.getDate("GUELTIG_VON"); |
208 Date to = rs.getDate("GUELTIG_BIS"); | 211 Date to = rs.getDate("GUELTIG_BIS"); |
212 String description = rs.getString("ABFLUSSTAFEL_BEZ"); | |
213 if (description == null) { | |
214 description = String.valueOf(officialNumber); | |
215 } | |
209 | 216 |
210 double datumValue = rs.getDouble("PEGELNULLPUNKT"); | 217 double datumValue = rs.getDouble("PEGELNULLPUNKT"); |
211 Double datum = rs.wasNull() ? null : datumValue; | 218 Double datum = rs.wasNull() ? null : datumValue; |
212 | 219 |
213 if (debug) { | 220 if (debug) { |
214 log.debug("id: " + dtId); | 221 log.debug("id: " + dtId); |
215 log.debug("valid from: " + from); | 222 log.debug("valid from: " + from); |
216 log.debug("valid to: " + to); | 223 log.debug("valid to: " + to); |
217 log.debug("datum: " + datum); | 224 log.debug("datum: " + datum); |
218 } | 225 log.debug("description: " + description); |
226 } | |
227 | |
228 TimeInterval timeInterval = from == null | |
229 ? null | |
230 : new TimeInterval(from, to); | |
231 | |
232 DischargeTable dt = new DischargeTable( | |
233 gauge.getFlysId(), | |
234 timeInterval, | |
235 description); | |
236 dts.add(dt); | |
219 } | 237 } |
220 } | 238 } |
221 finally { | 239 finally { |
222 if (rs != null) { | 240 if (rs != null) { |
223 rs.close(); | 241 rs.close(); |
242 rs = null; | |
243 } | |
244 } | |
245 | |
246 // Persist the time intervals. | |
247 for (DischargeTable dt: dts) { | |
248 TimeInterval timeInterval = dt.getTimeInterval(); | |
249 if (timeInterval != null) { | |
250 dt.setTimeInterval( | |
251 context.fetchOrCreateFLYSTimeInterval(timeInterval)); | |
252 } | |
253 } | |
254 | |
255 // Persist the discharge tables | |
256 try { | |
257 SymbolicStatement.Instance nextId = | |
258 flysStatements.getStatement("next.discharge.id"); | |
259 | |
260 SymbolicStatement.Instance insertDT = | |
261 flysStatements.getStatement("insert.dischargetable"); | |
262 | |
263 for (DischargeTable dt: dts) { | |
264 rs = nextId.executeQuery(); | |
265 rs.next(); | |
266 int id = rs.getInt("discharge_table_id"); | |
267 rs.close(); rs = null; | |
268 | |
269 insertDT.clearParameters() | |
270 .setInt("id", id) | |
271 .setInt("gauge_id", dt.getGaugeId()) | |
272 .setString("description", dt.getDescription()); | |
273 | |
274 TimeInterval timeInterval = dt.getTimeInterval(); | |
275 if (timeInterval != null) { | |
276 insertDT.setInt("time_interval_id", timeInterval.getId()); | |
277 } | |
278 else { | |
279 insertDT.setNull("time_interval_id", Types.INTEGER); | |
280 } | |
281 | |
282 insertDT.execute(); | |
283 if (debug) { | |
284 log.debug("FLYS: Created discharge table id: " + id); | |
285 } | |
286 } | |
287 } | |
288 finally { | |
289 if (rs != null) { | |
290 rs.close(); | |
291 rs = null; | |
224 } | 292 } |
225 } | 293 } |
226 } | 294 } |
227 | 295 |
228 public String toString() { | 296 public String toString() { |