changeset 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 2305731f563c
children 309d4ca09816
files flys-aft/ChangeLog flys-aft/src/main/java/de/intevation/aft/River.java flys-aft/src/main/java/de/intevation/aft/Sync.java
diffstat 3 files changed, 69 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- 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	<sascha.teichmann@inteavtion.de>
+
+	* 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	<sascha.teichmann@inteavtion.de>
 
 	* src/main/java/de/intevation/aft/DischargeTable.java: Store 
--- 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<DischargeTable> flysDTs =
-            DischargeTable.loadFlysDischargeTables(
-                context, gauge.getFlysId());
-
-        List<DischargeTable> aftDTs =
-            DischargeTable.loadAftDischargeTables(
-                context, gauge.getOfficialNumber());
-
-        Map<String, DischargeTable> desc2FlysDT =
-            new HashMap<String, DischargeTable>();
-
-        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<DischargeTable> createDTs = new ArrayList<DischargeTable>();
+        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<DischargeTable> flysDTs =
+                DischargeTable.loadFlysDischargeTables(
+                    context, gauge.getFlysId());
+
+            List<DischargeTable> aftDTs =
+                DischargeTable.loadAftDischargeTables(
+                    context, gauge.getOfficialNumber());
+
+            Map<String, DischargeTable> desc2FlysDT =
+                new HashMap<String, DischargeTable>();
+
+            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<DischargeTable> createDTs = new ArrayList<DischargeTable>();
+
+            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;
--- 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);

http://dive4elements.wald.intevation.org