annotate flys-aft/src/main/java/de/intevation/aft/DischargeTable.java @ 4099:006e99437fb9

Store the W/Q differences o existing discharge tables to FLYS database. flys-aft/trunk@3621 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 08 Jan 2012 09:25:36 +0000
parents 83c72bc07591
children b6a18d706cbe
rev   line source
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.aft;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
4091
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
3 import java.util.List;
4097
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
4 import java.util.Date;
4091
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
5 import java.util.ArrayList;
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
6
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
7 import java.sql.SQLException;
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
8 import java.sql.ResultSet;
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
9
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
10 import de.intevation.db.SymbolicStatement;
4092
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
11 import de.intevation.db.ConnectedStatements;
4091
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
12
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 public class DischargeTable
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 protected int id;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 protected int gaugeId;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 protected TimeInterval timeInterval;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 protected String description;
4091
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
19 protected List<WQ> values;
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 public DischargeTable() {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public DischargeTable(
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 int gaugeId,
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 TimeInterval timeInterval,
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 String description
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 ) {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 this.gaugeId = gaugeId;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 this.timeInterval = timeInterval;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 this.description = description;
4091
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
32 values = new ArrayList<WQ>();
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 public DischargeTable(
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 int id,
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 int gaugeId,
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 TimeInterval timeInterval,
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 String description
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 ) {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 this(gaugeId, timeInterval, description);
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 this.id = id;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 public int getId() {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 return id;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 public void setId(int id) {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 this.id = id;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 public int getGaugeId() {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 return gaugeId;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 public void setGaugeId(int gaugeId) {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 this.gaugeId = gaugeId;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public TimeInterval getTimeInterval() {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 return timeInterval;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 public void setTimeInterval(TimeInterval timeInterval) {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 this.timeInterval = timeInterval;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 public String getDescription() {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 return description;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 public void setDescription(String description) {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 this.description = description;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
4091
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
76
4093
7bddd4601707 Copy over W/Q values from AFT to FLYS for new discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4092
diff changeset
77 public void clearValues() {
7bddd4601707 Copy over W/Q values from AFT to FLYS for new discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4092
diff changeset
78 values.clear();
7bddd4601707 Copy over W/Q values from AFT to FLYS for new discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4092
diff changeset
79 }
7bddd4601707 Copy over W/Q values from AFT to FLYS for new discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4092
diff changeset
80
4099
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
81 public List<WQ> getValues() {
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
82 return values;
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
83 }
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
84
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
85 public void setValues(List<WQ> values) {
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
86 this.values = values;
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
87 }
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
88
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
89
006e99437fb9 Store the W/Q differences o existing discharge tables to FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4097
diff changeset
90
4091
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
91 protected void loadValues(SymbolicStatement.Instance query)
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
92 throws SQLException
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
93 {
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
94 ResultSet rs = query.executeQuery();
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
95 while (rs.next()) {
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
96 int id = rs.getInt("id");
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
97 double w = rs.getDouble("w");
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
98 double q = rs.getDouble("q");
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
99 values.add(new WQ(id, w, q));
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
100 }
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
101 rs.close();
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
102 }
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
103
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
104 public void loadAftValues(SyncContext context) throws SQLException {
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
105 loadValues(context.getAftStatements()
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
106 .getStatement("select.tafelwert")
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
107 .clearParameters()
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
108 .setInt("number", getId()));
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
109 }
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
110
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
111 public void loadFlysValues(SyncContext context) throws SQLException {
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
112 loadValues(context.getFlysStatements()
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
113 .getStatement("select.discharge.table.values")
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
114 .clearParameters()
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
115 .setInt("table_id", getId()));
a91c7e982c32 Make W/Q values from AFT and FLYS loadable.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4090
diff changeset
116 }
4092
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
117
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
118 public void storeFlysValues(
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
119 SyncContext context,
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
120 int dischargeTableId
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
121 )
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
122 throws SQLException
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
123 {
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
124 ConnectedStatements flysStatements = context.getFlysStatements();
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
125
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
126 // Create the ids.
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
127 SymbolicStatement.Instance nextId = flysStatements
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
128 .getStatement("next.discharge.table.values.id");
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
129
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
130 int [] ids = new int[values.size()];
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
131 for (int i = 0; i < ids.length; ++i) {
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
132 ResultSet rs = nextId.executeQuery();
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
133 rs.next();
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
134 ids[i] = rs.getInt("discharge_table_values_id");
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
135 rs.close();
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
136 }
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
137
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
138 // Insert the values.
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
139 SymbolicStatement.Instance insertDTV = flysStatements
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
140 .getStatement("insert.discharge.table.value");
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
141
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
142 for (int i = 0; i < ids.length; ++i) {
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
143 WQ wq = values.get(i);
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
144 insertDTV
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
145 .clearParameters()
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
146 .setInt("id", ids[i])
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
147 .setInt("table_id", dischargeTableId)
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
148 .setDouble("w", wq.getW())
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
149 .setDouble("q", wq.getQ())
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
150 .execute();
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
151 }
b3fc044f75ba Added code to store W/Q values into FLYS database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4091
diff changeset
152 }
4097
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
153
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
154 public static List<DischargeTable> loadFlysDischargeTables(
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
155 SyncContext context,
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
156 int gaugeId
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
157 )
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
158 throws SQLException
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
159 {
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
160 List<DischargeTable> dts = new ArrayList<DischargeTable>();
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
161
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
162 ResultSet rs = context
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
163 .getFlysStatements()
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
164 .getStatement("select.gauge.discharge.tables")
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
165 .clearParameters()
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
166 .setInt("gauge_id", gaugeId)
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
167 .executeQuery();
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
168
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
169 while (rs.next()) {
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
170 int id = rs.getInt("id");
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
171 String description = rs.getString("description");
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
172 Date startTime = rs.getDate("start_time");
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
173 Date stopTime = rs.getDate("stop_time");
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
174 TimeInterval ti = startTime == null
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
175 ? null
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
176 : new TimeInterval(startTime, stopTime);
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
177 DischargeTable dt = new DischargeTable(
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
178 id, gaugeId, ti, description);
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
179 dts.add(dt);
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
180 }
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
181 rs.close();
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
182
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
183 return dts;
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
184 }
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
185
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
186 public static List<DischargeTable> loadAftDischargeTables(
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
187 SyncContext context,
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
188 Long officialNumber
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
189 )
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
190 throws SQLException
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
191 {
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
192 return loadAftDischargeTables(context, officialNumber, 0);
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
193 }
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
194
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
195 public static List<DischargeTable> loadAftDischargeTables(
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
196 SyncContext context,
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
197 Long officialNumber,
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
198 int flysGaugeId
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
199 )
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
200 throws SQLException
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
201 {
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
202 List<DischargeTable> dts = new ArrayList<DischargeTable>();
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
203
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
204 ResultSet rs = context
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
205 .getAftStatements()
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
206 .getStatement("select.abflusstafel")
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
207 .clearParameters()
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
208 .setString("number", "%" + officialNumber)
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
209 .executeQuery();
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
210
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
211 while (rs.next()) {
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
212 int dtId = rs.getInt("ABFLUSSTAFEL_NR");
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
213 Date from = rs.getDate("GUELTIG_VON");
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
214 Date to = rs.getDate("GUELTIG_BIS");
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
215 String description = rs.getString("ABFLUSSTAFEL_BEZ");
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
216 if (description == null) {
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
217 description = String.valueOf(officialNumber);
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
218 }
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
219
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
220 double datumValue = rs.getDouble("PEGELNULLPUNKT");
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
221 Double datum = rs.wasNull() ? null : datumValue;
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
222
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
223 TimeInterval timeInterval = from == null
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
224 ? null
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
225 : new TimeInterval(from, to);
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
226
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
227 DischargeTable dt = new DischargeTable(
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
228 dtId,
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
229 flysGaugeId,
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
230 timeInterval,
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
231 description);
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
232 dts.add(dt);
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
233 }
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
234 rs.close();
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
235
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
236 return dts;
83c72bc07591 Load all discharge tables from AFT and FLYS of a gauge which needs updating.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4093
diff changeset
237 }
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org