comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4094:b20b710aa86f

Bubble up modifications up to main(). flys-aft/trunk@3605 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 05 Jan 2012 18:58:49 +0000
parents 7bddd4601707
children 83c72bc07591
comparison
equal deleted inserted replaced
4093:7bddd4601707 4094:b20b710aa86f
33 public String getName() { 33 public String getName() {
34 return name; 34 return name;
35 } 35 }
36 36
37 37
38 public void sync(SyncContext context) throws SQLException { 38 public boolean sync(SyncContext context) throws SQLException {
39 log.info("sync river: " + this); 39 log.info("sync river: " + this);
40 40
41 Map<Long, DIPSGauge> dipsGauges = context.getDIPSGauges(); 41 Map<Long, DIPSGauge> dipsGauges = context.getDIPSGauges();
42 42
43 ConnectedStatements flysStatements = context.getFlysStatements(); 43 ConnectedStatements flysStatements = context.getFlysStatements();
78 dipsGauge.setAftName(name); 78 dipsGauge.setAftName(name);
79 aftDIPSGauges.put(number, dipsGauge); 79 aftDIPSGauges.put(number, dipsGauge);
80 } 80 }
81 81
82 messstellenRs.close(); 82 messstellenRs.close();
83
84 83
85 List<DIPSGauge> updateGauges = new ArrayList<DIPSGauge>(); 84 List<DIPSGauge> updateGauges = new ArrayList<DIPSGauge>();
86 85
87 ResultSet gaugesRs = flysStatements 86 ResultSet gaugesRs = flysStatements
88 .getStatement("select.gauges") 87 .getStatement("select.gauges")
108 aftDIPSGauge.setFlysId(gaugeId); 107 aftDIPSGauge.setFlysId(gaugeId);
109 log.info("Gauge '" + name + 108 log.info("Gauge '" + name +
110 "' found in FLYS, AFT and DIPS. -> Update"); 109 "' found in FLYS, AFT and DIPS. -> Update");
111 updateGauges.add(aftDIPSGauge); 110 updateGauges.add(aftDIPSGauge);
112 } 111 }
113
114 createGauges(context, aftDIPSGauges);
115
116 gaugesRs.close(); 112 gaugesRs.close();
117 } 113
118 114 boolean modified = createGauges(context, aftDIPSGauges);
119 protected void createGauges( 115
116 return modified;
117 }
118
119 protected boolean createGauges(
120 SyncContext context, 120 SyncContext context,
121 Map<Long, DIPSGauge> gauges 121 Map<Long, DIPSGauge> gauges
122 ) 122 )
123 throws SQLException 123 throws SQLException
124 { 124 {
127 SymbolicStatement.Instance nextId = 127 SymbolicStatement.Instance nextId =
128 flysStatements.getStatement("next.gauge.id"); 128 flysStatements.getStatement("next.gauge.id");
129 129
130 SymbolicStatement.Instance insertStmnt = 130 SymbolicStatement.Instance insertStmnt =
131 flysStatements.getStatement("insert.gauge"); 131 flysStatements.getStatement("insert.gauge");
132
133 boolean modified = false;
132 134
133 for (Map.Entry<Long, DIPSGauge> entry: gauges.entrySet()) { 135 for (Map.Entry<Long, DIPSGauge> entry: gauges.entrySet()) {
134 Long officialNumber = entry.getKey(); 136 Long officialNumber = entry.getKey();
135 DIPSGauge gauge = entry.getValue(); 137 DIPSGauge gauge = entry.getValue();
136 138
165 log.info("FLYS: Created gauge '" + gauge.getAftName() + 167 log.info("FLYS: Created gauge '" + gauge.getAftName() +
166 "' with id " + gaugeId + "."); 168 "' with id " + gaugeId + ".");
167 169
168 gauge.setFlysId(gaugeId); 170 gauge.setFlysId(gaugeId);
169 createDischargeTables(context, officialNumber, gauge); 171 createDischargeTables(context, officialNumber, gauge);
170
171 flysStatements.commitTransaction(); 172 flysStatements.commitTransaction();
173 modified = true;
172 } 174 }
173 catch (SQLException sqle) { 175 catch (SQLException sqle) {
174 flysStatements.rollbackTransaction(); 176 flysStatements.rollbackTransaction();
175 throw sqle; 177 log.error(sqle, sqle);
176 } 178 }
177 finally { 179 finally {
178 if (rs != null) { 180 if (rs != null) {
179 rs.close(); 181 rs.close();
180 } 182 }
181 } 183 }
182 } 184 }
185
186 return modified;
183 } 187 }
184 188
185 protected void createDischargeTables( 189 protected void createDischargeTables(
186 SyncContext context, 190 SyncContext context,
187 Long officialNumber, 191 Long officialNumber,

http://dive4elements.wald.intevation.org