annotate flys-aft/src/main/java/de/intevation/aft/SyncContext.java @ 5119:15ff9ddc765e

Patch WIKI urls during release building
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 27 Feb 2013 17:12:56 +0100
parents f939e1e6cfa4
children 2b7f44c80857
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
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
90 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
91 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
92 NodeList nodes = document.getElementsByTagName("PEGELSTATION");
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
93 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
94 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
95 String numberString = element.getAttribute("NUMMER");
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
96 Long number = numberToLong(numberString);
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
97 if (number != null) {
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
98 DIPSGauge newG = new DIPSGauge(element);
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
99 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
100 if (oldG != null) {
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
101 log.warn("DIPS: '" + newG.getName() +
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4110
diff changeset
102 "' collides with '" + oldG.getName() +
4084
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
103 "' on gauge number " + number + ".");
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
104 }
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 else {
4110
06891562e633 Extracted and documented the error messages of the process.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4101
diff changeset
107 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
108 "' 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
109 }
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 return map;
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
112 }
9178beeb7b05 Moved DIPS gauge number -> DIPS gauge index.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4077
diff changeset
113
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4110
diff changeset
114 protected Map<TimeInterval, TimeInterval> loadTimeIntervals()
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
115 throws SQLException {
4089
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
116
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
117 boolean debug = log.isDebugEnabled();
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
118
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
119 Map<TimeInterval, TimeInterval> intervals =
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
120 new TreeMap<TimeInterval, TimeInterval>();
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
121
4771
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
122 ResultSet rs = flysStatements
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
123 .getStatement("select.timeintervals")
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
124 .executeQuery();
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4110
diff changeset
125
4089
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
126 try {
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
127 while (rs.next()) {
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
128 int id = rs.getInt("id");
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
129 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
130 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
131
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
132 if (debug) {
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
133 log.debug("id: " + id);
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
134 log.debug("start: " + start);
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
135 log.debug("stop: " + stop);
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
136 }
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
137
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
138 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
139 intervals.put(ti, ti);
4089
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 }
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
142 finally {
4771
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
143 rs.close();
4089
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
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
146 if (debug) {
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
147 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
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 return intervals;
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
151 }
859b4781554a Prefetch existing time intervals from FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4084
diff changeset
152
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
153 public TimeInterval fetchOrCreateFLYSTimeInterval(TimeInterval key)
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
154 throws SQLException
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
155 {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
156 TimeInterval old = flysTimeIntervals.get(key);
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
157 if (old != null) {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
158 return old;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
159 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
160
4771
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
161 ResultSet rs = flysStatements
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
162 .getStatement("next.timeinterval.id")
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
163 .executeQuery();
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
164
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
165 try {
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
166 rs.next();
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
167 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
168 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
169 finally {
4771
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
170 rs.close();
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
171 }
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
172
4771
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
173 if (log.isDebugEnabled()) {
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
174 log.debug("FLYS: Created time interval id: " + key.getId());
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
175 log.debug("FLYS: " + key);
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
176 }
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
177
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
178 flysStatements.getStatement("insert.timeinterval")
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
179 .clearParameters()
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
180 .setInt("id", key.getId())
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
181 .setObject("start_time", key.getStart())
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
182 .setObject("stop_time", key.getStop())
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
183 .execute();
e21acb4f5c62 Simplified code.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
184
4090
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
185 flysTimeIntervals.put(key, key);
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
186
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
187 return key;
d556e29592f5 Create new discharge tables if needed.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4089
diff changeset
188 }
4077
97de7a552b79 Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 }
97de7a552b79 Load DIPS XML
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org