Mercurial > dive4elements > river
annotate flys-aft/src/main/java/de/intevation/aft/SyncContext.java @ 5405:5ca06120b918
Remove river_name and map elements to reduce datacage level depth
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 25 Mar 2013 15:38:54 +0100 |
parents | 2b7f44c80857 |
children |
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 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import de.intevation.db.ConnectedStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
5 import java.sql.ResultSet; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
6 import java.sql.SQLException; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
7 |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
8 import java.util.Date; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
9 import java.util.HashMap; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
10 import java.util.Map; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
11 import java.util.TreeMap; |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
12 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
13 import org.apache.log4j.Logger; |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
4772
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
15 import org.w3c.dom.Document; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
16 import org.w3c.dom.Element; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
17 import org.w3c.dom.NodeList; |
f939e1e6cfa4
Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4771
diff
changeset
|
18 |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 public class SyncContext |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 { |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
21 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
|
22 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
23 protected ConnectedStatements aftStatements; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
24 protected ConnectedStatements flysStatements; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
25 protected Document dips; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
26 |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
27 protected Map<Long, DIPSGauge> numberToGauge; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
28 protected Map<TimeInterval, TimeInterval> flysTimeIntervals; |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public SyncContext() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 } |
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 public SyncContext( |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 ConnectedStatements aftStatements, |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 ConnectedStatements flysStatements, |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 Document dips |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 ) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 this.aftStatements = aftStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 this.flysStatements = flysStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 this.dips = dips; |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
41 } |
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 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
|
44 numberToGauge = indexByNumber(dips); |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
45 flysTimeIntervals = loadTimeIntervals(); |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 } |
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 public ConnectedStatements getAftStatements() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 return aftStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 } |
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 public void setAftStatements(ConnectedStatements aftStatements) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 this.aftStatements = aftStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } |
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 public ConnectedStatements getFlysStatements() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 return flysStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 } |
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 public void setFlysStatements(ConnectedStatements flysStatements) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 this.flysStatements = flysStatements; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 } |
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 public Document getDips() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 return dips; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 } |
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 public void setDips(Document dips) { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 this.dips = dips; |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 } |
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 void close() { |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 aftStatements.close(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 flysStatements.close(); |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
76 |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
77 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
|
78 try { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
79 return Long.valueOf(s.trim()); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
80 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
81 catch (NumberFormatException nfe) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
82 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
83 return null; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
84 } |
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 public Map<Long, DIPSGauge> getDIPSGauges() { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
87 return numberToGauge; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
88 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
89 |
5188
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
90 public Map<Long, DIPSGauge> getDIPSGauges( |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
91 String riverName, |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
92 double from, |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
93 double to |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
94 ) { |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
95 if (from > to) { |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
96 double t = from; |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
97 from = to; |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
98 to = t; |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
99 } |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
100 |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
101 riverName = riverName.toLowerCase(); |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
102 |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
103 Map<Long, DIPSGauge> result = new HashMap<Long, DIPSGauge>(); |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
104 |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
105 for (Map.Entry<Long, DIPSGauge> entry: numberToGauge.entrySet()) { |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
106 DIPSGauge gauge = entry.getValue(); |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
107 // XXX: Maybe a bit too sloppy. |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
108 if (!riverName.contains(gauge.getRiverName().toLowerCase())) { |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
109 continue; |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
110 } |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
111 double station = gauge.getStation(); |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
112 if (station >= from && station <= to) { |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
113 result.put(entry.getKey(), gauge); |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
114 } |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
115 } |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
116 |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
117 return result; |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
118 } |
2b7f44c80857
Stations are now filtered by DiPS not AFT.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4772
diff
changeset
|
119 |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
120 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
|
121 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
|
122 NodeList nodes = document.getElementsByTagName("PEGELSTATION"); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
123 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
|
124 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
|
125 String numberString = element.getAttribute("NUMMER"); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
126 Long number = numberToLong(numberString); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
127 if (number != null) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
128 DIPSGauge newG = new DIPSGauge(element); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
129 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
|
130 if (oldG != null) { |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
131 log.warn("DIPS: '" + newG.getName() + |
4736
b195fede1c3b
Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
132 "' collides with '" + oldG.getName() + |
4084
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
133 "' on gauge number " + number + "."); |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
134 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
135 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
136 else { |
4110
06891562e633
Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4101
diff
changeset
|
137 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
|
138 "' 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
|
139 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
140 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
141 return map; |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
142 } |
9178beeb7b05
Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4077
diff
changeset
|
143 |
4736
b195fede1c3b
Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
144 protected Map<TimeInterval, TimeInterval> loadTimeIntervals() |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
145 throws SQLException { |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
146 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
147 boolean debug = log.isDebugEnabled(); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
148 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
149 Map<TimeInterval, TimeInterval> intervals = |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
150 new TreeMap<TimeInterval, TimeInterval>(); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
151 |
4771
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
152 ResultSet rs = flysStatements |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
153 .getStatement("select.timeintervals") |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
154 .executeQuery(); |
4736
b195fede1c3b
Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4110
diff
changeset
|
155 |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
156 try { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
157 while (rs.next()) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
158 int id = rs.getInt("id"); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
159 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
|
160 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
|
161 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
162 if (debug) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
163 log.debug("id: " + id); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
164 log.debug("start: " + start); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
165 log.debug("stop: " + stop); |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
166 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
167 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
168 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
|
169 intervals.put(ti, ti); |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
170 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
171 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
172 finally { |
4771
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
173 rs.close(); |
4089
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
174 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
175 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
176 if (debug) { |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
177 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
|
178 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
179 |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
180 return intervals; |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
181 } |
859b4781554a
Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4084
diff
changeset
|
182 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
183 public TimeInterval fetchOrCreateFLYSTimeInterval(TimeInterval key) |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
184 throws SQLException |
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 TimeInterval old = flysTimeIntervals.get(key); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
187 if (old != null) { |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
188 return old; |
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 |
4771
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
191 ResultSet rs = flysStatements |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
192 .getStatement("next.timeinterval.id") |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
193 .executeQuery(); |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
194 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
195 try { |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
196 rs.next(); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
197 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
|
198 } |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
199 finally { |
4771
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
200 rs.close(); |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
201 } |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
202 |
4771
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
203 if (log.isDebugEnabled()) { |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
204 log.debug("FLYS: Created time interval id: " + key.getId()); |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
205 log.debug("FLYS: " + key); |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
206 } |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
207 |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
208 flysStatements.getStatement("insert.timeinterval") |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
209 .clearParameters() |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
210 .setInt("id", key.getId()) |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
211 .setObject("start_time", key.getStart()) |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
212 .setObject("stop_time", key.getStop()) |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
213 .execute(); |
e21acb4f5c62
Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4736
diff
changeset
|
214 |
4090
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
215 flysTimeIntervals.put(key, key); |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
216 |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
217 return key; |
d556e29592f5
Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4089
diff
changeset
|
218 } |
4077
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 } |
97de7a552b79
Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |