[Dive4elements-commits] [PATCH] Delete discharge tables which are in AFT but not in FLYS. Fixed Oracle specific pom.xml

Wald Commits scm-commit at wald.intevation.org
Wed May 8 17:04:53 CEST 2013


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1368025489 -7200
# Node ID 33e514a0c6b7ba79873ad183618ceb5e9f2b3825
# Parent  4d526e313fa0dcf7eb1574e2c18a1f700d471204
Delete discharge tables which are in AFT but not in FLYS. Fixed Oracle specific pom.xml

diff -r 4d526e313fa0 -r 33e514a0c6b7 etl/pom-oracle.xml
--- a/etl/pom-oracle.xml	Wed May 08 17:02:51 2013 +0200
+++ b/etl/pom-oracle.xml	Wed May 08 17:04:49 2013 +0200
@@ -27,8 +27,8 @@
         <configuration>
           <archive>
             <manifest>
-              <mainClass>de.intevation.aft.Sync</mainClass>
-              <packageName>de.intevation.aft</packageName>
+              <mainClass>org.dive4elements.river.etl.aft.Sync</mainClass>
+              <packageName>org.dive4elements.river.etl.aft</packageName>
             </manifest>
           </archive>
         </configuration>
@@ -38,7 +38,7 @@
         <configuration>
           <archive>
             <manifest>
-              <mainClass>de.intevation.aft.Sync</mainClass>
+              <mainClass>org.dive4elements.river.etl.aft.Sync</mainClass>
             </manifest>
           </archive>
           <descriptorRefs>
diff -r 4d526e313fa0 -r 33e514a0c6b7 etl/src/main/java/org/dive4elements/river/etl/aft/River.java
--- a/etl/src/main/java/org/dive4elements/river/etl/aft/River.java	Wed May 08 17:02:51 2013 +0200
+++ b/etl/src/main/java/org/dive4elements/river/etl/aft/River.java	Wed May 08 17:04:49 2013 +0200
@@ -15,6 +15,7 @@
 import java.sql.SQLException;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -323,6 +324,8 @@
                 }
             }
 
+            modified |= deleteDischargeTables(context, bfgId2FlysDT);
+
             for (String bfgId: bfgId2FlysDT.keySet()) {
                 log.info("FLYS: Discharge table '" + bfgId
                     + "' found in FLYS but not in AFT. -> ignore");
@@ -449,6 +452,42 @@
         aftDT.storeFlysValues(context, flysId);
     }
 
+    protected boolean deleteDischargeTables(
+        SyncContext                 context,
+        Map<String, DischargeTable> tables
+    )
+    throws SQLException
+    {
+        ConnectedStatements flysStatements = context.getFlysStatements();
+
+        SymbolicStatement.Instance deleteDischargeTableValues =
+            flysStatements.getStatement("delete.discharge.table.values");
+
+        SymbolicStatement.Instance deleteDischargeTable =
+            flysStatements.getStatement("delete.discharge.table");
+
+        boolean modified = false;
+
+        for (Map.Entry<String, DischargeTable> entry: tables.entrySet()) {
+            log.info("FLYS: Discharge table '" + entry.getKey()
+                + "' found in FLYS but not in AFT. -> delete");
+            int id = entry.getValue().getId();
+
+            deleteDischargeTableValues
+                .clearParameters()
+                .setInt("id", id);
+            deleteDischargeTableValues.execute();
+
+            deleteDischargeTable
+                .clearParameters()
+                .setInt("id", id);
+            deleteDischargeTable.execute();
+
+            modified = true;
+        }
+        return modified;
+    }
+
     protected void createDischargeTables(
         SyncContext context,
         DIPSGauge   gauge
diff -r 4d526e313fa0 -r 33e514a0c6b7 etl/src/main/resources/sql/flys-common.properties
--- a/etl/src/main/resources/sql/flys-common.properties	Wed May 08 17:02:51 2013 +0200
+++ b/etl/src/main/resources/sql/flys-common.properties	Wed May 08 17:04:49 2013 +0200
@@ -55,3 +55,7 @@
     WHERE g.id = :gauge_id AND dt.kind = 0
 update.bfg.id.discharge.table = \
     UPDATE discharge_tables SET bfg_id = :bfg_id WHERE id = :id
+delete.discharge.table.values = \
+    DELETE from discharge_table_values where table_id = :id
+delete.discharge.table = \
+    DELETE from discharge_tables where id = :id and kind = 1


More information about the Dive4elements-commits mailing list