diff flys-aft/src/main/java/de/intevation/aft/DischargeTable.java @ 4097:83c72bc07591

Load all discharge tables from AFT and FLYS of a gauge which needs updating. flys-aft/trunk@3618 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 06 Jan 2012 18:32:08 +0000
parents 7bddd4601707
children 006e99437fb9
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java	Fri Jan 06 17:16:46 2012 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/DischargeTable.java	Fri Jan 06 18:32:08 2012 +0000
@@ -1,6 +1,7 @@
 package de.intevation.aft;
 
 import java.util.List;
+import java.util.Date;
 import java.util.ArrayList;
 
 import java.sql.SQLException;
@@ -139,5 +140,90 @@
                 .execute();
         }
     }
+
+    public static List<DischargeTable> loadFlysDischargeTables(
+        SyncContext context,
+        int         gaugeId
+    )
+    throws SQLException
+    {
+        List<DischargeTable> dts = new ArrayList<DischargeTable>();
+
+        ResultSet rs = context
+            .getFlysStatements()
+            .getStatement("select.gauge.discharge.tables")
+            .clearParameters()
+            .setInt("gauge_id", gaugeId)
+            .executeQuery();
+
+        while (rs.next()) {
+            int    id          = rs.getInt("id");
+            String description = rs.getString("description");
+            Date   startTime   = rs.getDate("start_time");
+            Date   stopTime    = rs.getDate("stop_time");
+            TimeInterval ti = startTime == null
+                ? null
+                : new TimeInterval(startTime, stopTime);
+            DischargeTable dt = new DischargeTable(
+                id, gaugeId, ti, description);
+            dts.add(dt);
+        }
+        rs.close();
+
+        return dts;
+    }
+
+    public static List<DischargeTable> loadAftDischargeTables(
+        SyncContext context,
+        Long        officialNumber
+    )
+    throws SQLException
+    {
+        return loadAftDischargeTables(context, officialNumber, 0);
+    }
+
+    public static List<DischargeTable> loadAftDischargeTables(
+        SyncContext context,
+        Long        officialNumber,
+        int         flysGaugeId
+    )
+    throws SQLException
+    {
+        List<DischargeTable> dts = new ArrayList<DischargeTable>();
+
+        ResultSet rs = context
+            .getAftStatements()
+            .getStatement("select.abflusstafel")
+            .clearParameters()
+            .setString("number", "%" + officialNumber)
+            .executeQuery();
+
+        while (rs.next()) {
+            int    dtId        = rs.getInt("ABFLUSSTAFEL_NR");
+            Date   from        = rs.getDate("GUELTIG_VON");
+            Date   to          = rs.getDate("GUELTIG_BIS");
+            String description = rs.getString("ABFLUSSTAFEL_BEZ");
+            if (description == null) {
+                description = String.valueOf(officialNumber);
+            }
+
+            double datumValue = rs.getDouble("PEGELNULLPUNKT");
+            Double datum = rs.wasNull() ? null : datumValue;
+
+            TimeInterval timeInterval = from == null
+                ? null
+                : new TimeInterval(from, to);
+
+            DischargeTable dt = new DischargeTable(
+                dtId,
+                flysGaugeId,
+                timeInterval,
+                description);
+            dts.add(dt);
+        }
+        rs.close();
+
+        return dts;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org