# HG changeset patch # User Sascha L. Teichmann # Date 1326130846 0 # Node ID cdcf98245e36d9ebe452d79a43408a19618dd536 # Parent 2305731f563cecb6265a01139b5651c23a45e5da Commit/rollback changes if a gauge is only updated. flys-aft/trunk@3636 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 2305731f563c -r cdcf98245e36 flys-aft/ChangeLog --- a/flys-aft/ChangeLog Mon Jan 09 17:09:25 2012 +0000 +++ b/flys-aft/ChangeLog Mon Jan 09 17:40:46 2012 +0000 @@ -1,3 +1,11 @@ +2012-01-09 Sascha L. Teichmann + + * src/main/java/de/intevation/aft/Sync.java: Log if modifications + are found or not. + + * src/main/java/de/intevation/aft/River.java: Commit/rollback + changes on gauge if a gauge is updated. + 2012-01-09 Sascha L. Teichmann * src/main/java/de/intevation/aft/DischargeTable.java: Store diff -r 2305731f563c -r cdcf98245e36 flys-aft/src/main/java/de/intevation/aft/River.java --- a/flys-aft/src/main/java/de/intevation/aft/River.java Mon Jan 09 17:09:25 2012 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/River.java Mon Jan 09 17:40:46 2012 +0000 @@ -144,58 +144,70 @@ boolean modified = false; - List flysDTs = - DischargeTable.loadFlysDischargeTables( - context, gauge.getFlysId()); - - List aftDTs = - DischargeTable.loadAftDischargeTables( - context, gauge.getOfficialNumber()); - - Map desc2FlysDT = - new HashMap(); - - for (DischargeTable dt: flysDTs) { - String description = dt.getDescription(); - if (description == null) { - log.warn("FLYS: discharge table " + dt.getId() - + " has no description. Ignored."); - continue; - } - desc2FlysDT.put(description, dt); - } - - List createDTs = new ArrayList(); + ConnectedStatements flysStatements = context.getFlysStatements(); - for (DischargeTable aftDT: aftDTs) { - String description = aftDT.getDescription(); - DischargeTable flysDT = desc2FlysDT.remove(description); - if (flysDT != null) { - // Found in AFT and FLYS. - log.info("FLYS: Discharge table '" + description - + "' found in AFT and FLYS. -> update"); - // Create the W/Q diff. - modified |= writeWQChanges(context, flysDT, aftDT); + flysStatements.beginTransaction(); + try { + List flysDTs = + DischargeTable.loadFlysDischargeTables( + context, gauge.getFlysId()); + + List aftDTs = + DischargeTable.loadAftDischargeTables( + context, gauge.getOfficialNumber()); + + Map desc2FlysDT = + new HashMap(); + + for (DischargeTable dt: flysDTs) { + String description = dt.getDescription(); + if (description == null) { + log.warn("FLYS: discharge table " + dt.getId() + + " has no description. Ignored."); + continue; + } + desc2FlysDT.put(description, dt); } - else { + + List createDTs = new ArrayList(); + + for (DischargeTable aftDT: aftDTs) { + String description = aftDT.getDescription(); + DischargeTable flysDT = desc2FlysDT.remove(description); + if (flysDT != null) { + // Found in AFT and FLYS. + log.info("FLYS: Discharge table '" + description + + "' found in AFT and FLYS. -> update"); + // Create the W/Q diff. + modified |= writeWQChanges(context, flysDT, aftDT); + } + else { + log.info("FLYS: Discharge table '" + description + + "' not found in FLYS. -> create"); + createDTs.add(aftDT); + } + } + + for (String description: desc2FlysDT.keySet()) { log.info("FLYS: Discharge table '" + description - + "' not found in FLYS. -> create"); - createDTs.add(aftDT); + + "' found in FLYS but not in AFT. -> ignore"); } - } - for (String description: desc2FlysDT.keySet()) { - log.info("FLYS: Discharge table '" + description - + "' found in FLYS but not in AFT. -> ignore"); - } + log.info("FLYS: Copy " + createDTs.size() + + " discharge tables over from AFT."); - log.info("FLYS: Copy " + createDTs.size() + - " discharge tables over from AFT."); + // Create the new discharge tables. + for (DischargeTable aftDT: createDTs) { + createDischargeTable(context, aftDT, gauge.getFlysId()); + modified = true; + } - // Create the new discharge tables. - for (DischargeTable aftDT: createDTs) { - createDischargeTable(context, aftDT, gauge.getFlysId()); - modified = true; + flysStatements.commitTransaction(); + } + catch (SQLException sqle) { + flysStatements.rollbackTransaction(); + log.error(sqle, sqle); + modified = false; } return modified; diff -r 2305731f563c -r cdcf98245e36 flys-aft/src/main/java/de/intevation/aft/Sync.java --- a/flys-aft/src/main/java/de/intevation/aft/Sync.java Mon Jan 09 17:09:25 2012 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/Sync.java Mon Jan 09 17:40:46 2012 +0000 @@ -155,8 +155,12 @@ } if (modified) { + log.info("Modifications found."); sendNotifications(config); } + else { + log.info("No modifications found."); + } if (exitCode != 0) { System.exit(1);