comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4087:aad1886ea226

Store new gauges in FLYS db. flys-aft/trunk@3568 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 02 Jan 2012 17:45:25 +0000
parents 067341e86375
children 52cde7fe742a
comparison
equal deleted inserted replaced
4086:ee0c60757a94 4087:aad1886ea226
9 import java.sql.SQLException; 9 import java.sql.SQLException;
10 10
11 import org.apache.log4j.Logger; 11 import org.apache.log4j.Logger;
12 12
13 import de.intevation.db.ConnectedStatements; 13 import de.intevation.db.ConnectedStatements;
14 import de.intevation.db.SymbolicStatement;
14 15
15 public class River 16 public class River
16 extends IdPair 17 extends IdPair
17 { 18 {
18 private static Logger log = Logger.getLogger(River.class); 19 private static Logger log = Logger.getLogger(River.class);
106 log.info("Gauge '" + name + 107 log.info("Gauge '" + name +
107 "' found in FLYS, AFT and DIPS. -> Update"); 108 "' found in FLYS, AFT and DIPS. -> Update");
108 updateGauges.add(aftDIPSGauge); 109 updateGauges.add(aftDIPSGauge);
109 } 110 }
110 111
112 createGauges(context, aftDIPSGauges);
113
111 gaugesRs.close(); 114 gaugesRs.close();
115 }
112 116
113 for (DIPSGauge gauge: aftDIPSGauges.values()) { 117 protected void createGauges(
118 SyncContext context,
119 Map<Long, DIPSGauge> gauges
120 )
121 throws SQLException
122 {
123 ConnectedStatements flysStatements = context.getFlysStatements();
124
125 SymbolicStatement.Instance nextId =
126 flysStatements.getStatement("next.gauge.id");
127
128 SymbolicStatement.Instance insertStmnt =
129 flysStatements.getStatement("insert.gauge");
130
131 for (Map.Entry<Long, DIPSGauge> entry: gauges.entrySet()) {
132 Long officialNumber = entry.getKey();
133 DIPSGauge gauge = entry.getValue();
134
114 log.info("Gauge '" + gauge.getAftName() + 135 log.info("Gauge '" + gauge.getAftName() +
115 "' not in FLYS but in AFT/DIPS. -> Create"); 136 "' not in FLYS but in AFT/DIPS. -> Create");
137
138 if (!gauge.hasDatums()) {
139 log.warn("FLYS: Gauge '" +
140 gauge.getAftName() + "' has no datum. Ignored.");
141 continue;
142 }
143
144 ResultSet rs = null;
145 flysStatements.beginTransaction();
146 try {
147 (rs = nextId.executeQuery()).next();
148 int gaugeId = rs.getInt("gauge_id");
149 rs.close(); rs = null;
150
151 insertStmnt
152 .clearParameters()
153 .setInt("id", gaugeId)
154 .setString("name", gauge.getAftName())
155 .setInt("river_id", id1)
156 .setDouble("station", gauge.getStation())
157 .setDouble("aeo", gauge.getAeo())
158 .setDouble("official_number", officialNumber)
159 .setDouble("datum", gauge.getLatestDatum().getValue());
160
161 insertStmnt.execute();
162
163 log.info("FLYS: Created gauge '" + gauge.getAftName() +
164 "' with id " + gaugeId + ".");
165
166 flysStatements.commitTransaction();
167 }
168 catch (SQLException sqle) {
169 flysStatements.rollbackTransaction();
170 throw sqle;
171 }
172 finally {
173 if (rs != null) {
174 rs.close();
175 }
176 }
116 } 177 }
117 } 178 }
118 179
119 public String toString() { 180 public String toString() {
120 return "[River: name=" + name + ", " + super.toString() + "]"; 181 return "[River: name=" + name + ", " + super.toString() + "]";

http://dive4elements.wald.intevation.org