# HG changeset patch # User Sascha L. Teichmann # Date 1325785578 0 # Node ID 7bddd4601707b24a065d882d3e7c2e47cee29437 # Parent b3fc044f75ba7c700e562b8b7064a4183ded7bf6 Copy over W/Q values from AFT to FLYS for new discharge tables. flys-aft/trunk@3603 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b3fc044f75ba -r 7bddd4601707 flys-aft/ChangeLog --- a/flys-aft/ChangeLog Thu Jan 05 17:06:29 2012 +0000 +++ b/flys-aft/ChangeLog Thu Jan 05 17:46:18 2012 +0000 @@ -1,4 +1,4 @@ -2012-01-04 Sascha L. Teichmann +2012-01-05 Sascha L. Teichmann * src/main/java/de/intevation/aft/DischargeTable.java: Store W/Q values to FLYS. @@ -6,7 +6,7 @@ * src/main/resources/sql/flys-common.properties: Added statements to store W/Q values into FLYS database. -2012-01-04 Sascha L. Teichmann +2012-01-05 Sascha L. Teichmann * src/main/java/de/intevation/aft/WQ.java: New. W/Q model used for AFT and FLYS. diff -r b3fc044f75ba -r 7bddd4601707 flys-aft/src/main/java/de/intevation/aft/DischargeTable.java --- a/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java Thu Jan 05 17:06:29 2012 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java Thu Jan 05 17:46:18 2012 +0000 @@ -73,6 +73,10 @@ this.description = description; } + public void clearValues() { + values.clear(); + } + protected void loadValues(SymbolicStatement.Instance query) throws SQLException { diff -r b3fc044f75ba -r 7bddd4601707 flys-aft/src/main/java/de/intevation/aft/River.java --- a/flys-aft/src/main/java/de/intevation/aft/River.java Thu Jan 05 17:06:29 2012 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/River.java Thu Jan 05 17:46:18 2012 +0000 @@ -191,16 +191,36 @@ { log.info("create discharge tables"); - boolean debug = log.isDebugEnabled(); + // Load the discharge tables from AFT. + List dts = loadAftDischargeTables( + context, officialNumber, gauge); - ConnectedStatements flysStatements = context.getFlysStatements(); - ConnectedStatements aftStatements = context.getAftStatements(); + // Persist the time intervals. + persistFlysTimeIntervals(context, dts); + + // Persist the discharge tables + int [] flysDTIds = persistFlysDischargeTables(context, dts); + + // Copy over the W/Q values + copyWQsFromAftToFlys(context, dts, flysDTIds); + } + + protected List loadAftDischargeTables( + SyncContext context, + Long officialNumber, + DIPSGauge gauge + ) + throws SQLException + { + boolean debug = log.isDebugEnabled(); List dts = new ArrayList(); ResultSet rs = null; try { - rs = aftStatements.getStatement("select.abflusstafel") + rs = context + .getAftStatements() + .getStatement("select.abflusstafel") .clearParameters() .setString("number", "%" + officialNumber). executeQuery(); @@ -230,6 +250,7 @@ : new TimeInterval(from, to); DischargeTable dt = new DischargeTable( + dtId, gauge.getFlysId(), timeInterval, description); @@ -243,7 +264,15 @@ } } - // Persist the time intervals. + return dts; + } + + protected void persistFlysTimeIntervals( + SyncContext context, + List dts + ) + throws SQLException + { for (DischargeTable dt: dts) { TimeInterval timeInterval = dt.getTimeInterval(); if (timeInterval != null) { @@ -251,21 +280,37 @@ context.fetchOrCreateFLYSTimeInterval(timeInterval)); } } + } - // Persist the discharge tables + protected int [] persistFlysDischargeTables( + SyncContext context, + List dts + ) + throws SQLException + { + boolean debug = log.isDebugEnabled(); + + 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 (DischargeTable dt: dts) { + 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()) @@ -291,6 +336,23 @@ rs = null; } } + + return flysDTIds; + } + + protected void copyWQsFromAftToFlys( + SyncContext context, + List dts, + int [] flysDTIds + ) + throws SQLException + { + for (int i = 0; i < flysDTIds.length; ++i) { + DischargeTable dt = dts.get(i); + dt.loadAftValues(context); + dt.storeFlysValues(context, flysDTIds[i]); + dt.clearValues(); // To save memory. + } } public String toString() {