comparison 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
comparison
equal deleted inserted replaced
4088:52cde7fe742a 4089:859b4781554a
1 package de.intevation.aft; 1 package de.intevation.aft;
2 2
3 import java.util.Map; 3 import java.util.Map;
4 import java.util.Date;
4 import java.util.HashMap; 5 import java.util.HashMap;
6 import java.util.Set;
7 import java.util.TreeSet;
8
9 import java.sql.SQLException;
10 import java.sql.ResultSet;
5 11
6 import org.w3c.dom.Document; 12 import org.w3c.dom.Document;
7 13
8 import de.intevation.db.ConnectedStatements; 14 import de.intevation.db.ConnectedStatements;
9 15
18 24
19 protected ConnectedStatements aftStatements; 25 protected ConnectedStatements aftStatements;
20 protected ConnectedStatements flysStatements; 26 protected ConnectedStatements flysStatements;
21 protected Document dips; 27 protected Document dips;
22 protected Map<Long, DIPSGauge> numberToGauge; 28 protected Map<Long, DIPSGauge> numberToGauge;
29 protected Set<TimeInterval> flysTimeIntervals;
23 30
24 public SyncContext() { 31 public SyncContext() {
25 } 32 }
26 33
27 public SyncContext( 34 public SyncContext(
30 Document dips 37 Document dips
31 ) { 38 ) {
32 this.aftStatements = aftStatements; 39 this.aftStatements = aftStatements;
33 this.flysStatements = flysStatements; 40 this.flysStatements = flysStatements;
34 this.dips = dips; 41 this.dips = dips;
42 }
43
44 public void init() throws SQLException {
35 numberToGauge = indexByNumber(dips); 45 numberToGauge = indexByNumber(dips);
46 flysTimeIntervals = loadTimeIntervals();
36 } 47 }
37 48
38 public ConnectedStatements getAftStatements() { 49 public ConnectedStatements getAftStatements() {
39 return aftStatements; 50 return aftStatements;
40 } 51 }
99 } 110 }
100 } 111 }
101 return map; 112 return map;
102 } 113 }
103 114
115 protected Set<TimeInterval> loadTimeIntervals() throws SQLException {
116
117 boolean debug = log.isDebugEnabled();
118
119 Set<TimeInterval> intervals = new TreeSet<TimeInterval>();
120 ResultSet rs = null;
121
122 try {
123 rs = flysStatements
124 .getStatement("select.timeintervals")
125 .executeQuery();
126
127 while (rs.next()) {
128 int id = rs.getInt("id");
129 Date start = rs.getDate("start_time");
130 Date stop = rs.getDate("stop_time");
131
132 if (debug) {
133 log.debug("id: " + id);
134 log.debug("start: " + start);
135 log.debug("stop: " + stop);
136 }
137
138 TimeInterval ti = new TimeInterval(id, start, stop);
139 intervals.add(ti);
140 }
141 }
142 finally {
143 if (rs != null) {
144 rs.close();
145 }
146 }
147
148 if (debug) {
149 log.debug("loaded time intervals: " + intervals.size());
150 }
151
152 return intervals;
153 }
154
104 } 155 }
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 156 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
106 157

http://dive4elements.wald.intevation.org