changeset 5930:33e514a0c6b7

Delete discharge tables which are in AFT but not in FLYS. Fixed Oracle specific pom.xml
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 08 May 2013 17:04:49 +0200
parents 4d526e313fa0
children 5de1b9faebf5
files etl/pom-oracle.xml etl/src/main/java/org/dive4elements/river/etl/aft/River.java etl/src/main/resources/sql/flys-common.properties
diffstat 3 files changed, 46 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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>
--- 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
--- 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

http://dive4elements.wald.intevation.org