Mercurial > dive4elements > river
diff flys-aft/src/main/java/de/intevation/aft/River.java @ 4102:e8967ee1cb05
Fixed logic bug when writing discharge tables of an gauge existing in both dbs.
flys-aft/trunk@3631 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 09 Jan 2012 16:43:14 +0000 |
parents | 981de0b77c6b |
children | cdcf98245e36 |
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/River.java Mon Jan 09 15:34:19 2012 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/River.java Mon Jan 09 16:43:14 2012 +0000 @@ -7,7 +7,6 @@ import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Types; import org.apache.log4j.Logger; @@ -139,6 +138,7 @@ ) throws SQLException { + log.info("FLYS: Updating gauge '" + gauge.getAftName() + "'."); // We need to load all discharge tables from both database // of the gauge and do some pairing based on their descriptions. @@ -189,9 +189,12 @@ + "' found in FLYS but not in AFT. -> ignore"); } + log.info("FLYS: Copy " + createDTs.size() + + " discharge tables over from AFT."); + // Create the new discharge tables. for (DischargeTable aftDT: createDTs) { - createDischargeTables(context, gauge); + createDischargeTable(context, aftDT, gauge.getFlysId()); modified = true; } @@ -285,13 +288,28 @@ return modified; } + protected void createDischargeTable( + SyncContext context, + DischargeTable aftDT, + int flysGaugeId + ) + throws SQLException + { + aftDT.persistFlysTimeInterval(context); + int flysId = aftDT.persistFlysDischargeTable(context, flysGaugeId); + + aftDT.loadAftValues(context); + aftDT.storeFlysValues(context, flysId); + } + protected void createDischargeTables( SyncContext context, DIPSGauge gauge ) throws SQLException { - log.info("create discharge tables"); + log.info("FLYS: Create discharge tables for '" + + gauge.getAftName() + "'."); // Load the discharge tables from AFT. List<DischargeTable> dts = loadAftDischargeTables( @@ -301,7 +319,8 @@ persistFlysTimeIntervals(context, dts); // Persist the discharge tables - int [] flysDTIds = persistFlysDischargeTables(context, dts); + int [] flysDTIds = persistFlysDischargeTables( + context, dts, gauge.getFlysId()); // Copy over the W/Q values copyWQsFromAftToFlys(context, dts, flysDTIds); @@ -324,17 +343,14 @@ throws SQLException { for (DischargeTable dt: dts) { - TimeInterval timeInterval = dt.getTimeInterval(); - if (timeInterval != null) { - dt.setTimeInterval( - context.fetchOrCreateFLYSTimeInterval(timeInterval)); - } + dt.persistFlysTimeInterval(context); } } protected int [] persistFlysDischargeTables( SyncContext context, - List<DischargeTable> dts + List<DischargeTable> dts, + int flysGaugeId ) throws SQLException { @@ -342,49 +358,9 @@ int [] flysDTIds = new int[dts.size()]; - ResultSet rs = null; - try { - ConnectedStatements flysStatements = - context.getFlysStatements(); - - SymbolicStatement.Instance nextId = - flysStatements.getStatement("next.discharge.id"); - - SymbolicStatement.Instance insertDT = - flysStatements.getStatement("insert.dischargetable"); - - for (int i = 0; i < flysDTIds.length; ++i) { - rs = nextId.executeQuery(); - rs.next(); - int id = rs.getInt("discharge_table_id"); - flysDTIds[i] = id; - rs.close(); rs = null; - - DischargeTable dt = dts.get(i); - insertDT.clearParameters() - .setInt("id", id) - .setInt("gauge_id", dt.getGaugeId()) - .setString("description", dt.getDescription()); - - TimeInterval timeInterval = dt.getTimeInterval(); - if (timeInterval != null) { - insertDT.setInt("time_interval_id", timeInterval.getId()); - } - else { - insertDT.setNull("time_interval_id", Types.INTEGER); - } - - insertDT.execute(); - if (debug) { - log.debug("FLYS: Created discharge table id: " + id); - } - } - } - finally { - if (rs != null) { - rs.close(); - rs = null; - } + for (int i = 0; i < flysDTIds.length; ++i) { + flysDTIds[i] = dts.get(i) + .persistFlysDischargeTable(context, flysGaugeId); } return flysDTIds; @@ -408,6 +384,5 @@ public String toString() { return "[River: name=" + name + ", " + super.toString() + "]"; } - } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :