annotate flys-aft/src/main/java/de/intevation/db/SymbolicStatement.java @ 5711:06f3a36a83b6

Merged.
author Sascha L. Teichmann <teichmann@intevation.de>
date Mon, 15 Apr 2013 16:29:54 +0200
parents 7a68967ca72a
children
rev   line source
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.db;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
4772
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
3 import java.sql.Connection;
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
4 import java.sql.PreparedStatement;
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
5 import java.sql.ResultSet;
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
6 import java.sql.SQLException;
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
7 import java.sql.Timestamp;
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
8
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import java.util.ArrayList;
4772
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
10 import java.util.HashMap;
f939e1e6cfa4 Sorted imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4736
diff changeset
11 import java.util.List;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import java.util.Map;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.util.regex.Matcher;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.util.regex.Pattern;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import org.apache.log4j.Logger;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 public class SymbolicStatement {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 private static Logger log = Logger.getLogger(SymbolicStatement.class);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public static final Pattern VAR = Pattern.compile(":([a-zA-Z0-9_]+)");
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 protected String statement;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 protected String compiled;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 protected Map<String, List<Integer>> positions;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public class Instance {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 /** TODO: Support more types. */
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 protected PreparedStatement stmnt;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 public Instance(Connection connection) throws SQLException {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 stmnt = connection.prepareStatement(compiled);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 public void close() {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 try {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 stmnt.close();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 catch (SQLException sqle) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 log.error("cannot close statement", sqle);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
48 public Instance setInt(String key, int value)
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4100
diff changeset
49 throws SQLException
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 List<Integer> pos = positions.get(key.toLowerCase());
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 if (pos != null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 for (Integer p: pos) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 stmnt.setInt(p, value);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 }
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
57
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
58 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
61 public Instance setString(String key, String value)
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4100
diff changeset
62 throws SQLException
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 List<Integer> pos = positions.get(key.toLowerCase());
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 if (pos != null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 for (Integer p: pos) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 stmnt.setString(p, value);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 }
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
70 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
73 public Instance setObject(String key, Object value)
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4100
diff changeset
74 throws SQLException
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 List<Integer> pos = positions.get(key.toLowerCase());
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 if (pos != null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78 for (Integer p: pos) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 stmnt.setObject(p, value);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 }
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
82 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
85 public Instance setTimestamp(String key, Timestamp value)
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4100
diff changeset
86 throws SQLException
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 List<Integer> pos = positions.get(key.toLowerCase());
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 if (pos != null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 for (Integer p: pos) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 stmnt.setTimestamp(p, value);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 }
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
94 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
4087
aad1886ea226 Store new gauges in FLYS db.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4076
diff changeset
97 public Instance setDouble(String key, double value)
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4100
diff changeset
98 throws SQLException
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 List<Integer> pos = positions.get(key.toLowerCase());
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 if (pos != null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 for (Integer p: pos) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 stmnt.setDouble(p, value);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 }
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
106 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108
4100
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
109 public Instance setLong(String key, long value)
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4100
diff changeset
110 throws SQLException
4100
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
111 {
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
112 List<Integer> pos = positions.get(key.toLowerCase());
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
113 if (pos != null) {
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
114 for (Integer p: pos) {
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
115 stmnt.setLong(p, value);
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
116 }
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
117 }
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
118 return this;
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
119 }
981de0b77c6b If gauges exist in FLYS and AFT store the discharge tables in FLYS that are only in AFT.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4087
diff changeset
120
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
121 public Instance setNull(String key, int sqlType)
4736
b195fede1c3b Remove trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4100
diff changeset
122 throws SQLException
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 List<Integer> pos = positions.get(key.toLowerCase());
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 if (pos != null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 for (Integer p: pos) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 stmnt.setNull(p, sqlType);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 }
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
130 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
133 public Instance set(Map<String, Object> map) throws SQLException {
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 for (Map.Entry<String, Object> entry: map.entrySet()) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 setObject(entry.getKey(), entry.getValue());
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 }
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
137 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
140 public Instance clearParameters() throws SQLException {
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 stmnt.clearParameters();
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
142 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144
4075
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
145 public boolean execute() throws SQLException {
5480
7a68967ca72a AFT/DIPS: Small fixes and workarounds for Oracle DB problems.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4772
diff changeset
146 if (log.isDebugEnabled()) {
7a68967ca72a AFT/DIPS: Small fixes and workarounds for Oracle DB problems.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4772
diff changeset
147 log.debug("execute: " + compiled);
7a68967ca72a AFT/DIPS: Small fixes and workarounds for Oracle DB problems.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4772
diff changeset
148 }
4075
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
149 return stmnt.execute();
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
150 }
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
151
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
152 public ResultSet executeQuery() throws SQLException {
5480
7a68967ca72a AFT/DIPS: Small fixes and workarounds for Oracle DB problems.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4772
diff changeset
153 if (log.isDebugEnabled()) {
7a68967ca72a AFT/DIPS: Small fixes and workarounds for Oracle DB problems.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4772
diff changeset
154 log.debug("query: " + compiled);
7a68967ca72a AFT/DIPS: Small fixes and workarounds for Oracle DB problems.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4772
diff changeset
155 }
4075
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
156 return stmnt.executeQuery();
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
157 }
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
158
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
159 public int executeUpdate() throws SQLException {
5480
7a68967ca72a AFT/DIPS: Small fixes and workarounds for Oracle DB problems.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4772
diff changeset
160 if (log.isDebugEnabled()) {
7a68967ca72a AFT/DIPS: Small fixes and workarounds for Oracle DB problems.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4772
diff changeset
161 log.debug("update: " + compiled);
7a68967ca72a AFT/DIPS: Small fixes and workarounds for Oracle DB problems.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4772
diff changeset
162 }
4075
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
163 return stmnt.executeUpdate();
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
164 }
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
165
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 } // class Instance
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 public SymbolicStatement(String statement) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 this.statement = statement;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 compile();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 public String getStatement() {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 return statement;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 protected void compile() {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 positions = new HashMap<String, List<Integer>>();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 StringBuffer sb = new StringBuffer();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 Matcher m = VAR.matcher(statement);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 int index = 1;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 while (m.find()) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 String key = m.group(1).toLowerCase();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 List<Integer> list = positions.get(key);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 if (list == null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 list = new ArrayList<Integer>();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 positions.put(key, list);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 list.add(index++);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 m.appendReplacement(sb, "?");
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 m.appendTail(sb);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 compiled = sb.toString();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 } // class SymbolicStatement

http://dive4elements.wald.intevation.org