diff flys-aft/src/main/java/de/intevation/aft/SyncContext.java @ 4089:859b4781554a

Prefetch existing time intervals from FLYS db. flys-aft/trunk@3574 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Jan 2012 12:25:06 +0000
parents 9178beeb7b05
children d556e29592f5
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/SyncContext.java	Tue Jan 03 11:36:07 2012 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/SyncContext.java	Tue Jan 03 12:25:06 2012 +0000
@@ -1,7 +1,13 @@
 package de.intevation.aft;
 
 import java.util.Map;
+import java.util.Date;
 import java.util.HashMap;
+import java.util.Set;
+import java.util.TreeSet;
+
+import java.sql.SQLException;
+import java.sql.ResultSet;
 
 import org.w3c.dom.Document;
 
@@ -20,6 +26,7 @@
     protected ConnectedStatements  flysStatements;
     protected Document             dips;
     protected Map<Long, DIPSGauge> numberToGauge;
+    protected Set<TimeInterval>    flysTimeIntervals;
 
     public SyncContext() {
     }
@@ -32,7 +39,11 @@
         this.aftStatements  = aftStatements;
         this.flysStatements = flysStatements;
         this.dips           = dips;
+    }
+
+    public void init() throws SQLException {
         numberToGauge       = indexByNumber(dips);
+        flysTimeIntervals   = loadTimeIntervals();
     }
 
     public ConnectedStatements getAftStatements() {
@@ -101,6 +112,46 @@
         return map;
     }
 
+    protected Set<TimeInterval> loadTimeIntervals() throws SQLException {
+
+        boolean debug = log.isDebugEnabled();
+
+        Set<TimeInterval> intervals = new TreeSet<TimeInterval>();
+        ResultSet rs = null;
+        
+        try {
+            rs = flysStatements
+                .getStatement("select.timeintervals")
+                .executeQuery();
+
+            while (rs.next()) {
+                int  id    = rs.getInt("id");
+                Date start = rs.getDate("start_time");
+                Date stop  = rs.getDate("stop_time");
+
+                if (debug) {
+                    log.debug("id:    " + id);
+                    log.debug("start: " + start);
+                    log.debug("stop:  " + stop);
+                }
+
+                TimeInterval ti = new TimeInterval(id, start, stop);
+                intervals.add(ti);
+            }
+        }
+        finally {
+            if (rs != null) {
+                rs.close();
+            }
+        }
+
+        if (debug) {
+            log.debug("loaded time intervals: " + intervals.size());
+        }
+
+        return intervals;
+    }
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
 

http://dive4elements.wald.intevation.org