Mercurial > dive4elements > river
view flys-aft/src/main/java/de/intevation/aft/DischargeTable.java @ 4093:7bddd4601707
Copy over W/Q values from AFT to FLYS for new discharge tables.
flys-aft/trunk@3603 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 05 Jan 2012 17:46:18 +0000 |
parents | b3fc044f75ba |
children | 83c72bc07591 |
line wrap: on
line source
package de.intevation.aft; import java.util.List; import java.util.ArrayList; import java.sql.SQLException; import java.sql.ResultSet; import de.intevation.db.SymbolicStatement; import de.intevation.db.ConnectedStatements; public class DischargeTable { protected int id; protected int gaugeId; protected TimeInterval timeInterval; protected String description; protected List<WQ> values; public DischargeTable() { } public DischargeTable( int gaugeId, TimeInterval timeInterval, String description ) { this.gaugeId = gaugeId; this.timeInterval = timeInterval; this.description = description; values = new ArrayList<WQ>(); } public DischargeTable( int id, int gaugeId, TimeInterval timeInterval, String description ) { this(gaugeId, timeInterval, description); this.id = id; } public int getId() { return id; } public void setId(int id) { this.id = id; } public int getGaugeId() { return gaugeId; } public void setGaugeId(int gaugeId) { this.gaugeId = gaugeId; } public TimeInterval getTimeInterval() { return timeInterval; } public void setTimeInterval(TimeInterval timeInterval) { this.timeInterval = timeInterval; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public void clearValues() { values.clear(); } protected void loadValues(SymbolicStatement.Instance query) throws SQLException { ResultSet rs = query.executeQuery(); while (rs.next()) { int id = rs.getInt("id"); double w = rs.getDouble("w"); double q = rs.getDouble("q"); values.add(new WQ(id, w, q)); } rs.close(); } public void loadAftValues(SyncContext context) throws SQLException { loadValues(context.getAftStatements() .getStatement("select.tafelwert") .clearParameters() .setInt("number", getId())); } public void loadFlysValues(SyncContext context) throws SQLException { loadValues(context.getFlysStatements() .getStatement("select.discharge.table.values") .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 :