annotate flys-aft/src/main/java/de/intevation/db/SymbolicStatement.java @ 4185:79878efbdf07

Merged.
author Christian Lins <christian.lins@intevation.de>
date Fri, 19 Oct 2012 09:30:37 +0200
parents 981de0b77c6b
children b195fede1c3b
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
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.List;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.util.ArrayList;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.util.Map;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.util.HashMap;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import java.util.regex.Matcher;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import java.util.regex.Pattern;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.sql.Connection;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import java.sql.SQLException;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import java.sql.PreparedStatement;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14 import java.sql.Timestamp;
4075
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
15 import java.sql.ResultSet;
4073
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)
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 throws SQLException
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)
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 throws SQLException
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)
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74 throws SQLException
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)
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 throws SQLException
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)
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 throws SQLException
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)
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
110 throws SQLException
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)
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 throws SQLException
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 {
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
146 return stmnt.execute();
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
147 }
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
148
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
149 public ResultSet executeQuery() throws SQLException {
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
150 return stmnt.executeQuery();
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
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
153 public int executeUpdate() throws SQLException {
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
154 return stmnt.executeUpdate();
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
155 }
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
156
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 } // class Instance
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 public SymbolicStatement(String statement) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 this.statement = statement;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 compile();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 public String getStatement() {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 return statement;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 }
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 protected void compile() {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 positions = new HashMap<String, List<Integer>>();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 StringBuffer sb = new StringBuffer();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 Matcher m = VAR.matcher(statement);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 int index = 1;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 while (m.find()) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 String key = m.group(1).toLowerCase();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 List<Integer> list = positions.get(key);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 if (list == null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 list = new ArrayList<Integer>();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 positions.put(key, list);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 list.add(index++);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 m.appendReplacement(sb, "?");
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 m.appendTail(sb);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 compiled = sb.toString();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 } // class SymbolicStatement

http://dive4elements.wald.intevation.org