# HG changeset patch # User Sascha L. Teichmann # Date 1326128965 0 # Node ID 2305731f563cecb6265a01139b5651c23a45e5da # Parent e8967ee1cb051dfc9c058493cda410338a7a5662 Store W/Q in sets to prevent value duplications. flys-aft/trunk@3633 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r e8967ee1cb05 -r 2305731f563c flys-aft/ChangeLog --- a/flys-aft/ChangeLog Mon Jan 09 16:43:14 2012 +0000 +++ b/flys-aft/ChangeLog Mon Jan 09 17:09:25 2012 +0000 @@ -1,3 +1,13 @@ +2012-01-09 Sascha L. Teichmann + + * src/main/java/de/intevation/aft/DischargeTable.java: Store + the W/Q values in sets to prevent value duplications leading + to unique constraint violations in FLYS. Log a warning + when loading a W/Q value duplication. + + This have the nice side effect that the W/Q values are + written sorted by Q/W which is of benefit for FLYS. + 2012-01-09 Sascha L. Teichmann * src/main/java/de/intevation/aft/River.java: Fixed logic bug diff -r e8967ee1cb05 -r 2305731f563c flys-aft/src/main/java/de/intevation/aft/DischargeTable.java --- a/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java Mon Jan 09 16:43:14 2012 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java Mon Jan 09 17:09:25 2012 +0000 @@ -3,6 +3,8 @@ import java.util.List; import java.util.Date; import java.util.ArrayList; +import java.util.TreeSet; +import java.util.Set; import java.sql.SQLException; import java.sql.ResultSet; @@ -21,7 +23,7 @@ protected int gaugeId; protected TimeInterval timeInterval; protected String description; - protected List values; + protected Set values; public DischargeTable() { } @@ -34,7 +36,7 @@ this.gaugeId = gaugeId; this.timeInterval = timeInterval; this.description = description; - values = new ArrayList(); + values = new TreeSet(WQ.EPS_CMP); } public DischargeTable( @@ -83,16 +85,15 @@ values.clear(); } - public List getValues() { + public Set getValues() { return values; } - public void setValues(List values) { + public void setValues(Set values) { this.values = values; } - protected void loadValues(SymbolicStatement.Instance query) throws SQLException { @@ -101,7 +102,9 @@ int id = rs.getInt("id"); double w = rs.getDouble("w"); double q = rs.getDouble("q"); - values.add(new WQ(id, w, q)); + if (!values.add(new WQ(id, w, q))) { + log.warn("Value duplication w="+w+" q="+q+". -> ignore."); + } } rs.close(); } @@ -132,23 +135,19 @@ 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); + for (WQ wq: values) { + ResultSet rs = nextId.executeQuery(); + rs.next(); + int wqId = rs.getInt("discharge_table_values_id"); + rs.close(); + insertDTV .clearParameters() - .setInt("id", ids[i]) + .setInt("id", wqId) .setInt("table_id", dischargeTableId) .setDouble("w", wq.getW()) .setDouble("q", wq.getQ())