comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4104:cdcf98245e36

Commit/rollback changes if a gauge is only updated. flys-aft/trunk@3636 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 09 Jan 2012 17:40:46 +0000
parents e8967ee1cb05
children 06891562e633
comparison
equal deleted inserted replaced
4103:2305731f563c 4104:cdcf98245e36
142 // We need to load all discharge tables from both database 142 // We need to load all discharge tables from both database
143 // of the gauge and do some pairing based on their descriptions. 143 // of the gauge and do some pairing based on their descriptions.
144 144
145 boolean modified = false; 145 boolean modified = false;
146 146
147 List<DischargeTable> flysDTs = 147 ConnectedStatements flysStatements = context.getFlysStatements();
148 DischargeTable.loadFlysDischargeTables( 148
149 context, gauge.getFlysId()); 149 flysStatements.beginTransaction();
150 150 try {
151 List<DischargeTable> aftDTs = 151 List<DischargeTable> flysDTs =
152 DischargeTable.loadAftDischargeTables( 152 DischargeTable.loadFlysDischargeTables(
153 context, gauge.getOfficialNumber()); 153 context, gauge.getFlysId());
154 154
155 Map<String, DischargeTable> desc2FlysDT = 155 List<DischargeTable> aftDTs =
156 new HashMap<String, DischargeTable>(); 156 DischargeTable.loadAftDischargeTables(
157 157 context, gauge.getOfficialNumber());
158 for (DischargeTable dt: flysDTs) { 158
159 String description = dt.getDescription(); 159 Map<String, DischargeTable> desc2FlysDT =
160 if (description == null) { 160 new HashMap<String, DischargeTable>();
161 log.warn("FLYS: discharge table " + dt.getId() 161
162 + " has no description. Ignored."); 162 for (DischargeTable dt: flysDTs) {
163 continue; 163 String description = dt.getDescription();
164 } 164 if (description == null) {
165 desc2FlysDT.put(description, dt); 165 log.warn("FLYS: discharge table " + dt.getId()
166 } 166 + " has no description. Ignored.");
167 167 continue;
168 List<DischargeTable> createDTs = new ArrayList<DischargeTable>(); 168 }
169 169 desc2FlysDT.put(description, dt);
170 for (DischargeTable aftDT: aftDTs) { 170 }
171 String description = aftDT.getDescription(); 171
172 DischargeTable flysDT = desc2FlysDT.remove(description); 172 List<DischargeTable> createDTs = new ArrayList<DischargeTable>();
173 if (flysDT != null) { 173
174 // Found in AFT and FLYS. 174 for (DischargeTable aftDT: aftDTs) {
175 String description = aftDT.getDescription();
176 DischargeTable flysDT = desc2FlysDT.remove(description);
177 if (flysDT != null) {
178 // Found in AFT and FLYS.
179 log.info("FLYS: Discharge table '" + description
180 + "' found in AFT and FLYS. -> update");
181 // Create the W/Q diff.
182 modified |= writeWQChanges(context, flysDT, aftDT);
183 }
184 else {
185 log.info("FLYS: Discharge table '" + description
186 + "' not found in FLYS. -> create");
187 createDTs.add(aftDT);
188 }
189 }
190
191 for (String description: desc2FlysDT.keySet()) {
175 log.info("FLYS: Discharge table '" + description 192 log.info("FLYS: Discharge table '" + description
176 + "' found in AFT and FLYS. -> update"); 193 + "' found in FLYS but not in AFT. -> ignore");
177 // Create the W/Q diff. 194 }
178 modified |= writeWQChanges(context, flysDT, aftDT); 195
179 } 196 log.info("FLYS: Copy " + createDTs.size() +
180 else { 197 " discharge tables over from AFT.");
181 log.info("FLYS: Discharge table '" + description 198
182 + "' not found in FLYS. -> create"); 199 // Create the new discharge tables.
183 createDTs.add(aftDT); 200 for (DischargeTable aftDT: createDTs) {
184 } 201 createDischargeTable(context, aftDT, gauge.getFlysId());
185 } 202 modified = true;
186 203 }
187 for (String description: desc2FlysDT.keySet()) { 204
188 log.info("FLYS: Discharge table '" + description 205 flysStatements.commitTransaction();
189 + "' found in FLYS but not in AFT. -> ignore"); 206 }
190 } 207 catch (SQLException sqle) {
191 208 flysStatements.rollbackTransaction();
192 log.info("FLYS: Copy " + createDTs.size() + 209 log.error(sqle, sqle);
193 " discharge tables over from AFT."); 210 modified = false;
194
195 // Create the new discharge tables.
196 for (DischargeTable aftDT: createDTs) {
197 createDischargeTable(context, aftDT, gauge.getFlysId());
198 modified = true;
199 } 211 }
200 212
201 return modified; 213 return modified;
202 } 214 }
203 215

http://dive4elements.wald.intevation.org