Mercurial > dive4elements > river
comparison flys-aft/src/main/java/de/intevation/aft/DischargeTable.java @ 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 | 309d4ca09816 |
comparison
equal
deleted
inserted
replaced
4102:e8967ee1cb05 | 4103:2305731f563c |
---|---|
1 package de.intevation.aft; | 1 package de.intevation.aft; |
2 | 2 |
3 import java.util.List; | 3 import java.util.List; |
4 import java.util.Date; | 4 import java.util.Date; |
5 import java.util.ArrayList; | 5 import java.util.ArrayList; |
6 import java.util.TreeSet; | |
7 import java.util.Set; | |
6 | 8 |
7 import java.sql.SQLException; | 9 import java.sql.SQLException; |
8 import java.sql.ResultSet; | 10 import java.sql.ResultSet; |
9 import java.sql.Types; | 11 import java.sql.Types; |
10 | 12 |
19 | 21 |
20 protected int id; | 22 protected int id; |
21 protected int gaugeId; | 23 protected int gaugeId; |
22 protected TimeInterval timeInterval; | 24 protected TimeInterval timeInterval; |
23 protected String description; | 25 protected String description; |
24 protected List<WQ> values; | 26 protected Set<WQ> values; |
25 | 27 |
26 public DischargeTable() { | 28 public DischargeTable() { |
27 } | 29 } |
28 | 30 |
29 public DischargeTable( | 31 public DischargeTable( |
32 String description | 34 String description |
33 ) { | 35 ) { |
34 this.gaugeId = gaugeId; | 36 this.gaugeId = gaugeId; |
35 this.timeInterval = timeInterval; | 37 this.timeInterval = timeInterval; |
36 this.description = description; | 38 this.description = description; |
37 values = new ArrayList<WQ>(); | 39 values = new TreeSet<WQ>(WQ.EPS_CMP); |
38 } | 40 } |
39 | 41 |
40 public DischargeTable( | 42 public DischargeTable( |
41 int id, | 43 int id, |
42 int gaugeId, | 44 int gaugeId, |
81 | 83 |
82 public void clearValues() { | 84 public void clearValues() { |
83 values.clear(); | 85 values.clear(); |
84 } | 86 } |
85 | 87 |
86 public List<WQ> getValues() { | 88 public Set<WQ> getValues() { |
87 return values; | 89 return values; |
88 } | 90 } |
89 | 91 |
90 public void setValues(List<WQ> values) { | 92 public void setValues(Set<WQ> values) { |
91 this.values = values; | 93 this.values = values; |
92 } | 94 } |
93 | |
94 | 95 |
95 | 96 |
96 protected void loadValues(SymbolicStatement.Instance query) | 97 protected void loadValues(SymbolicStatement.Instance query) |
97 throws SQLException | 98 throws SQLException |
98 { | 99 { |
99 ResultSet rs = query.executeQuery(); | 100 ResultSet rs = query.executeQuery(); |
100 while (rs.next()) { | 101 while (rs.next()) { |
101 int id = rs.getInt("id"); | 102 int id = rs.getInt("id"); |
102 double w = rs.getDouble("w"); | 103 double w = rs.getDouble("w"); |
103 double q = rs.getDouble("q"); | 104 double q = rs.getDouble("q"); |
104 values.add(new WQ(id, w, q)); | 105 if (!values.add(new WQ(id, w, q))) { |
106 log.warn("Value duplication w="+w+" q="+q+". -> ignore."); | |
107 } | |
105 } | 108 } |
106 rs.close(); | 109 rs.close(); |
107 } | 110 } |
108 | 111 |
109 public void loadAftValues(SyncContext context) throws SQLException { | 112 public void loadAftValues(SyncContext context) throws SQLException { |
130 | 133 |
131 // Create the ids. | 134 // Create the ids. |
132 SymbolicStatement.Instance nextId = flysStatements | 135 SymbolicStatement.Instance nextId = flysStatements |
133 .getStatement("next.discharge.table.values.id"); | 136 .getStatement("next.discharge.table.values.id"); |
134 | 137 |
135 int [] ids = new int[values.size()]; | |
136 for (int i = 0; i < ids.length; ++i) { | |
137 ResultSet rs = nextId.executeQuery(); | |
138 rs.next(); | |
139 ids[i] = rs.getInt("discharge_table_values_id"); | |
140 rs.close(); | |
141 } | |
142 | |
143 // Insert the values. | 138 // Insert the values. |
144 SymbolicStatement.Instance insertDTV = flysStatements | 139 SymbolicStatement.Instance insertDTV = flysStatements |
145 .getStatement("insert.discharge.table.value"); | 140 .getStatement("insert.discharge.table.value"); |
146 | 141 |
147 for (int i = 0; i < ids.length; ++i) { | 142 for (WQ wq: values) { |
148 WQ wq = values.get(i); | 143 ResultSet rs = nextId.executeQuery(); |
144 rs.next(); | |
145 int wqId = rs.getInt("discharge_table_values_id"); | |
146 rs.close(); | |
147 | |
149 insertDTV | 148 insertDTV |
150 .clearParameters() | 149 .clearParameters() |
151 .setInt("id", ids[i]) | 150 .setInt("id", wqId) |
152 .setInt("table_id", dischargeTableId) | 151 .setInt("table_id", dischargeTableId) |
153 .setDouble("w", wq.getW()) | 152 .setDouble("w", wq.getW()) |
154 .setDouble("q", wq.getQ()) | 153 .setDouble("q", wq.getQ()) |
155 .execute(); | 154 .execute(); |
156 } | 155 } |