Mercurial > dive4elements > river
changeset 4103:2305731f563c
Store W/Q in sets to prevent value duplications.
flys-aft/trunk@3633 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 09 Jan 2012 17:09:25 +0000 |
parents | e8967ee1cb05 |
children | cdcf98245e36 |
files | flys-aft/ChangeLog flys-aft/src/main/java/de/intevation/aft/DischargeTable.java |
diffstat | 2 files changed, 26 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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 <sascha.teichmann@inteavtion.de> + + * 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 <sascha.teichmann@inteavtion.de> * src/main/java/de/intevation/aft/River.java: Fixed logic bug
--- 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<WQ> values; + protected Set<WQ> values; public DischargeTable() { } @@ -34,7 +36,7 @@ this.gaugeId = gaugeId; this.timeInterval = timeInterval; this.description = description; - values = new ArrayList<WQ>(); + values = new TreeSet<WQ>(WQ.EPS_CMP); } public DischargeTable( @@ -83,16 +85,15 @@ values.clear(); } - public List<WQ> getValues() { + public Set<WQ> getValues() { return values; } - public void setValues(List<WQ> values) { + public void setValues(Set<WQ> 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())