changeset 4092:b3fc044f75ba

Added code to store W/Q values into FLYS database. flys-aft/trunk@3602 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 05 Jan 2012 17:06:29 +0000
parents a91c7e982c32
children 7bddd4601707
files flys-aft/ChangeLog flys-aft/src/main/java/de/intevation/aft/DischargeTable.java flys-aft/src/main/resources/sql/flys-common.properties
diffstat 3 files changed, 47 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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	<sascha.teichmann@inteavtion.de>
+
+	* 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	<sascha.teichmann@inteavtion.de>
 
 	* src/main/java/de/intevation/aft/WQ.java: New. W/Q model used
--- 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 :
--- 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)

http://dive4elements.wald.intevation.org