sascha@4090: package de.intevation.aft; sascha@4090: sascha@4091: import java.util.List; sascha@4091: import java.util.ArrayList; sascha@4091: sascha@4091: import java.sql.SQLException; sascha@4091: import java.sql.ResultSet; sascha@4091: sascha@4091: import de.intevation.db.SymbolicStatement; sascha@4092: import de.intevation.db.ConnectedStatements; sascha@4091: sascha@4090: public class DischargeTable sascha@4090: { sascha@4090: protected int id; sascha@4090: protected int gaugeId; sascha@4090: protected TimeInterval timeInterval; sascha@4090: protected String description; sascha@4091: protected List values; sascha@4090: sascha@4090: public DischargeTable() { sascha@4090: } sascha@4090: sascha@4090: public DischargeTable( sascha@4090: int gaugeId, sascha@4090: TimeInterval timeInterval, sascha@4090: String description sascha@4090: ) { sascha@4090: this.gaugeId = gaugeId; sascha@4090: this.timeInterval = timeInterval; sascha@4090: this.description = description; sascha@4091: values = new ArrayList(); sascha@4090: } sascha@4090: sascha@4090: public DischargeTable( sascha@4090: int id, sascha@4090: int gaugeId, sascha@4090: TimeInterval timeInterval, sascha@4090: String description sascha@4090: ) { sascha@4090: this(gaugeId, timeInterval, description); sascha@4090: this.id = id; sascha@4090: } sascha@4090: sascha@4090: public int getId() { sascha@4090: return id; sascha@4090: } sascha@4090: sascha@4090: public void setId(int id) { sascha@4090: this.id = id; sascha@4090: } sascha@4090: sascha@4090: public int getGaugeId() { sascha@4090: return gaugeId; sascha@4090: } sascha@4090: sascha@4090: public void setGaugeId(int gaugeId) { sascha@4090: this.gaugeId = gaugeId; sascha@4090: } sascha@4090: sascha@4090: public TimeInterval getTimeInterval() { sascha@4090: return timeInterval; sascha@4090: } sascha@4090: sascha@4090: public void setTimeInterval(TimeInterval timeInterval) { sascha@4090: this.timeInterval = timeInterval; sascha@4090: } sascha@4090: sascha@4090: public String getDescription() { sascha@4090: return description; sascha@4090: } sascha@4090: sascha@4090: public void setDescription(String description) { sascha@4090: this.description = description; sascha@4090: } sascha@4091: sascha@4091: protected void loadValues(SymbolicStatement.Instance query) sascha@4091: throws SQLException sascha@4091: { sascha@4091: ResultSet rs = query.executeQuery(); sascha@4091: while (rs.next()) { sascha@4091: int id = rs.getInt("id"); sascha@4091: double w = rs.getDouble("w"); sascha@4091: double q = rs.getDouble("q"); sascha@4091: values.add(new WQ(id, w, q)); sascha@4091: } sascha@4091: rs.close(); sascha@4091: } sascha@4091: sascha@4091: public void loadAftValues(SyncContext context) throws SQLException { sascha@4091: loadValues(context.getAftStatements() sascha@4091: .getStatement("select.tafelwert") sascha@4091: .clearParameters() sascha@4091: .setInt("number", getId())); sascha@4091: } sascha@4091: sascha@4091: public void loadFlysValues(SyncContext context) throws SQLException { sascha@4091: loadValues(context.getFlysStatements() sascha@4091: .getStatement("select.discharge.table.values") sascha@4091: .clearParameters() sascha@4091: .setInt("table_id", getId())); sascha@4091: } sascha@4092: sascha@4092: public void storeFlysValues( sascha@4092: SyncContext context, sascha@4092: int dischargeTableId sascha@4092: ) sascha@4092: throws SQLException sascha@4092: { sascha@4092: ConnectedStatements flysStatements = context.getFlysStatements(); sascha@4092: sascha@4092: // Create the ids. sascha@4092: SymbolicStatement.Instance nextId = flysStatements sascha@4092: .getStatement("next.discharge.table.values.id"); sascha@4092: sascha@4092: int [] ids = new int[values.size()]; sascha@4092: for (int i = 0; i < ids.length; ++i) { sascha@4092: ResultSet rs = nextId.executeQuery(); sascha@4092: rs.next(); sascha@4092: ids[i] = rs.getInt("discharge_table_values_id"); sascha@4092: rs.close(); sascha@4092: } sascha@4092: sascha@4092: // Insert the values. sascha@4092: SymbolicStatement.Instance insertDTV = flysStatements sascha@4092: .getStatement("insert.discharge.table.value"); sascha@4092: sascha@4092: for (int i = 0; i < ids.length; ++i) { sascha@4092: WQ wq = values.get(i); sascha@4092: insertDTV sascha@4092: .clearParameters() sascha@4092: .setInt("id", ids[i]) sascha@4092: .setInt("table_id", dischargeTableId) sascha@4092: .setDouble("w", wq.getW()) sascha@4092: .setDouble("q", wq.getQ()) sascha@4092: .execute(); sascha@4092: } sascha@4092: } sascha@4090: } sascha@4090: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :