Mercurial > dive4elements > river
annotate flys-aft/src/main/java/de/intevation/aft/SyncContext.java @ 4412:1b4aaa7dbd07
WaterevelState: Doc.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 05 Nov 2012 17:31:51 +0100 |
parents | 06891562e633 |
children | b195fede1c3b |
rev | line source |
---|---|
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.aft; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
3 import java.util.Map; |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
4 import java.util.Date; |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
5 import java.util.HashMap; |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
6 import java.util.TreeMap; |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
7 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
8 import java.sql.SQLException; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
9 import java.sql.ResultSet; |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
10 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
11 import org.w3c.dom.Document; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
12 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.db.ConnectedStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
15 import org.w3c.dom.NodeList; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
16 import org.w3c.dom.Element; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
17 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
18 import org.apache.log4j.Logger; |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 public class SyncContext |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 { |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
22 private static Logger log = Logger.getLogger(SyncContext.class); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
23 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
24 protected ConnectedStatements aftStatements; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
25 protected ConnectedStatements flysStatements; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
26 protected Document dips; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
27 |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
28 protected Map<Long, DIPSGauge> numberToGauge; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
29 protected Map<TimeInterval, TimeInterval> flysTimeIntervals; |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 public SyncContext() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 public SyncContext( |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 ConnectedStatements aftStatements, |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 ConnectedStatements flysStatements, |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 Document dips |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 ) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 this.aftStatements = aftStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 this.flysStatements = flysStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 this.dips = dips; |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
42 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
43 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
44 public void init() throws SQLException { |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
45 numberToGauge = indexByNumber(dips); |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
46 flysTimeIntervals = loadTimeIntervals(); |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 public ConnectedStatements getAftStatements() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 return aftStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 public void setAftStatements(ConnectedStatements aftStatements) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 this.aftStatements = aftStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 public ConnectedStatements getFlysStatements() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 return flysStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 public void setFlysStatements(ConnectedStatements flysStatements) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 this.flysStatements = flysStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 public Document getDips() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 return dips; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 public void setDips(Document dips) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 this.dips = dips; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 void close() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 aftStatements.close(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 flysStatements.close(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 } |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
77 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
78 public static Long numberToLong(String s) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
79 try { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
80 return Long.valueOf(s.trim()); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
81 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
82 catch (NumberFormatException nfe) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
83 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
84 return null; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
85 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
86 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
87 public Map<Long, DIPSGauge> getDIPSGauges() { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
88 return numberToGauge; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
89 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
90 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
91 protected static Map<Long, DIPSGauge> indexByNumber(Document document) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
92 Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>(); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
93 NodeList nodes = document.getElementsByTagName("PEGELSTATION"); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
94 for (int i = nodes.getLength()-1; i >= 0; --i) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
95 Element element = (Element)nodes.item(i); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
96 String numberString = element.getAttribute("NUMMER"); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
97 Long number = numberToLong(numberString); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
98 if (number != null) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
99 DIPSGauge newG = new DIPSGauge(element); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
100 DIPSGauge oldG = map.put(number, newG); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
101 if (oldG != null) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
102 log.warn("DIPS: '" + newG.getName() + |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
103 "' collides with '" + oldG.getName() + |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
104 "' on gauge number " + number + "."); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
105 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
106 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
107 else { |
4110
06891562e633
Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4101
diff
changeset
|
108 log.warn("DIPS: Gauge '" + element.getAttribute("NAME") + |
06891562e633
Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4101
diff
changeset
|
109 "' has invalid gauge number '" + numberString + "'."); |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
110 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
111 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
112 return map; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
113 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
114 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
115 protected Map<TimeInterval, TimeInterval> loadTimeIntervals() |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
116 throws SQLException { |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
117 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
118 boolean debug = log.isDebugEnabled(); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
119 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
120 Map<TimeInterval, TimeInterval> intervals = |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
121 new TreeMap<TimeInterval, TimeInterval>(); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
122 |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
123 ResultSet rs = null; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
124 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
125 try { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
126 rs = flysStatements |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
127 .getStatement("select.timeintervals") |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
128 .executeQuery(); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
129 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
130 while (rs.next()) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
131 int id = rs.getInt("id"); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
132 Date start = rs.getDate("start_time"); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
133 Date stop = rs.getDate("stop_time"); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
134 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
135 if (debug) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
136 log.debug("id: " + id); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
137 log.debug("start: " + start); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
138 log.debug("stop: " + stop); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
139 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
140 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
141 TimeInterval ti = new TimeInterval(id, start, stop); |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
142 intervals.put(ti, ti); |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
143 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
144 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
145 finally { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
146 if (rs != null) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
147 rs.close(); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
148 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
149 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
150 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
151 if (debug) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
152 log.debug("loaded time intervals: " + intervals.size()); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
153 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
154 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
155 return intervals; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
156 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
157 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
158 public TimeInterval fetchOrCreateFLYSTimeInterval(TimeInterval key) |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
159 throws SQLException |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
160 { |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
161 TimeInterval old = flysTimeIntervals.get(key); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
162 if (old != null) { |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
163 return old; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
164 } |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
165 |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
166 ResultSet rs = null; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
167 try { |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
168 rs = flysStatements.getStatement("next.timeinterval.id") |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
169 .executeQuery(); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
170 rs.next(); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
171 key.setId(rs.getInt("time_interval_id")); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
172 rs.close(); rs = null; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
173 |
4101
b6a18d706cbe
Added debugging for AFT time intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
174 if (log.isDebugEnabled()) { |
b6a18d706cbe
Added debugging for AFT time intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
175 log.debug("FLYS: Created time interval id: " + key.getId()); |
b6a18d706cbe
Added debugging for AFT time intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
176 log.debug("FLYS: " + key); |
b6a18d706cbe
Added debugging for AFT time intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
177 } |
b6a18d706cbe
Added debugging for AFT time intervals.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4090
diff
changeset
|
178 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
179 flysStatements.getStatement("insert.timeinterval") |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
180 .clearParameters() |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
181 .setInt("id", key.getId()) |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
182 .setObject("start_time", key.getStart()) |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
183 .setObject("stop_time", key.getStop()) |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
184 .execute(); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
185 } |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
186 finally { |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
187 if (rs != null) { |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
188 rs.close(); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
189 } |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
190 } |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
191 |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
192 flysTimeIntervals.put(key, key); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
193 |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
194 return key; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
195 } |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
196 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 |