# HG changeset patch # User Sascha L. Teichmann # Date 1325783189 0 # Node ID b3fc044f75ba7c700e562b8b7064a4183ded7bf6 # Parent a91c7e982c32208e37840cb0fe2119a5dae9a42f Added code to store W/Q values into FLYS database. flys-aft/trunk@3602 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a91c7e982c32 -r b3fc044f75ba flys-aft/ChangeLog --- a/flys-aft/ChangeLog Thu Jan 05 16:41:26 2012 +0000 +++ b/flys-aft/ChangeLog Thu Jan 05 17:06:29 2012 +0000 @@ -1,3 +1,11 @@ +2012-01-04 Sascha L. Teichmann + + * src/main/java/de/intevation/aft/DischargeTable.java: Store + W/Q values to FLYS. + + * src/main/resources/sql/flys-common.properties: Added statements + to store W/Q values into FLYS database. + 2012-01-04 Sascha L. Teichmann * src/main/java/de/intevation/aft/WQ.java: New. W/Q model used diff -r a91c7e982c32 -r b3fc044f75ba flys-aft/src/main/java/de/intevation/aft/DischargeTable.java --- a/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java Thu Jan 05 16:41:26 2012 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java Thu Jan 05 17:06:29 2012 +0000 @@ -7,6 +7,7 @@ import java.sql.ResultSet; import de.intevation.db.SymbolicStatement; +import de.intevation.db.ConnectedStatements; public class DischargeTable { @@ -98,5 +99,41 @@ .clearParameters() .setInt("table_id", getId())); } + + public void storeFlysValues( + SyncContext context, + int dischargeTableId + ) + throws SQLException + { + ConnectedStatements flysStatements = context.getFlysStatements(); + + // Create the ids. + SymbolicStatement.Instance nextId = flysStatements + .getStatement("next.discharge.table.values.id"); + + int [] ids = new int[values.size()]; + for (int i = 0; i < ids.length; ++i) { + ResultSet rs = nextId.executeQuery(); + rs.next(); + ids[i] = rs.getInt("discharge_table_values_id"); + rs.close(); + } + + // Insert the values. + SymbolicStatement.Instance insertDTV = flysStatements + .getStatement("insert.discharge.table.value"); + + for (int i = 0; i < ids.length; ++i) { + WQ wq = values.get(i); + insertDTV + .clearParameters() + .setInt("id", ids[i]) + .setInt("table_id", dischargeTableId) + .setDouble("w", wq.getW()) + .setDouble("q", wq.getQ()) + .execute(); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r a91c7e982c32 -r b3fc044f75ba flys-aft/src/main/resources/sql/flys-common.properties --- a/flys-aft/src/main/resources/sql/flys-common.properties Thu Jan 05 16:41:26 2012 +0000 +++ b/flys-aft/src/main/resources/sql/flys-common.properties Thu Jan 05 17:06:29 2012 +0000 @@ -10,3 +10,5 @@ insert.dischargetable = INSERT INTO discharge_tables (id, gauge_id, description, kind, time_interval_id) \ VALUES (:id, :gauge_id, :description, 0, :time_interval_id) select.discharge.table.values = SELECT id, w, q FROM discharge_table_values WHERE table_id = :table_id +next.discharge.table.values.id = SELECT NEXTVAL('DISCHARGE_TABLE_VALUES_ID_SEQ') AS discharge_table_values_id +insert.discharge.table.value = INSERT INTO discharge_tables (id, table_id, w, q) VALUES (:id, :table_id, :w, :q)