annotate etl/src/main/java/org/dive4elements/river/etl/aft/WQDiff.java @ 7146:414794d0a50d

Add label for bed difference axis
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 25 Sep 2013 15:08:18 +0200
parents 6f80d5f375fd
children
rev   line source
5841
8bd9b551456c Added header to Java files in ETL process.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
8bd9b551456c Added header to Java files in ETL process.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
8bd9b551456c Added header to Java files in ETL process.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5991
6f80d5f375fd Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5841
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5841
8bd9b551456c Added header to Java files in ETL process.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5991
6f80d5f375fd Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5841
diff changeset
6 * documentation coming with Dive4Elements River for details.
5841
8bd9b551456c Added header to Java files in ETL process.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
8bd9b551456c Added header to Java files in ETL process.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5826
9438e9259213 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5825
diff changeset
9 package org.dive4elements.river.etl.aft;
4096
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
5826
9438e9259213 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5825
diff changeset
11 import org.dive4elements.river.etl.db.ConnectedStatements;
9438e9259213 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5825
diff changeset
12 import org.dive4elements.river.etl.db.SymbolicStatement;
4096
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.sql.ResultSet;
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.sql.SQLException;
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
4772
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
17 import java.util.Collection;
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
18 import java.util.Iterator;
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
19 import java.util.Set;
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
20 import java.util.TreeSet;
4096
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 public class WQDiff
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 protected Set<WQ> toAdd;
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 protected Set<WQ> toDelete;
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 public WQDiff() {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 public WQDiff(Collection<WQ> a, Collection<WQ> b) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 toAdd = new TreeSet<WQ>(WQ.EPS_CMP);
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 toDelete = new TreeSet<WQ>(WQ.EPS_CMP);
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 build(a, b);
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 public void build(Collection<WQ> a, Collection<WQ> b) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 toAdd.addAll(b);
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 toAdd.removeAll(a);
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 toDelete.addAll(a);
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 toDelete.removeAll(b);
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 public void clear() {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 toAdd.clear();
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 toDelete.clear();
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 public Set<WQ> getToAdd() {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 return toAdd;
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 public void setToAdd(Set<WQ> toAdd) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 this.toAdd = toAdd;
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 public Set<WQ> getToDelete() {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 return toDelete;
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 public void setToDelete(Set<WQ> toDelete) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 this.toDelete = toDelete;
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 public boolean hasChanges() {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 return !(toAdd.isEmpty() && toDelete.isEmpty());
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 public void writeChanges(
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4096
diff changeset
70 SyncContext context,
4096
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 int tableId
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 )
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 throws SQLException
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 ConnectedStatements flysStatements = context.getFlysStatements();
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 // Delete the old entries
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 if (!toDelete.isEmpty()) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 SymbolicStatement.Instance deleteDTV =
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 flysStatements.getStatement("delete.discharge.table.value");
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 for (WQ wq: toDelete) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 deleteDTV
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 .clearParameters()
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 .setInt("id", wq.getId())
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 .execute();
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 // Add the new entries.
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 if (!toAdd.isEmpty()) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 SymbolicStatement.Instance nextId =
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 flysStatements.getStatement("next.discharge.table.values.id");
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 SymbolicStatement.Instance insertDTV =
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 flysStatements.getStatement("insert.discharge.table.value");
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 // Recycle old ids as much as possible.
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 Iterator<WQ> oldIds = toDelete.iterator();
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 // Create ids for new entries.
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 for (WQ wq: toAdd) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 if (oldIds.hasNext()) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 wq.setId(oldIds.next().getId());
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 else {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 ResultSet rs = nextId.executeQuery();
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 rs.next();
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 wq.setId(rs.getInt("discharge_table_values_id"));
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 rs.close();
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 // Write the new entries.
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 for (WQ wq: toAdd) {
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 insertDTV
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 .clearParameters()
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 .setInt("id", wq.getId())
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 .setInt("table_id", tableId)
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 .setDouble("w", wq.getW())
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 .setDouble("q", wq.getQ())
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 .execute();
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 }
82f5266f881b Add code to build the difference of the W/Q values of two discharge tables.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org