annotate flys-aft/src/main/java/de/intevation/db/SymbolicStatement.java @ 4089:859b4781554a

Prefetch existing time intervals from FLYS db. flys-aft/trunk@3574 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Jan 2012 12:25:06 +0000
parents aad1886ea226
children 981de0b77c6b
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
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
109 public Instance setNull(String key, int sqlType)
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 throws SQLException
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 List<Integer> pos = positions.get(key.toLowerCase());
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 if (pos != null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 for (Integer p: pos) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 stmnt.setNull(p, sqlType);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 }
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
118 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
121 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
122 for (Map.Entry<String, Object> entry: map.entrySet()) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 setObject(entry.getKey(), entry.getValue());
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 }
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
125 return this;
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127
4076
039413d7e394 Load gauges from both dbs.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4075
diff changeset
128 public Instance clearParameters() throws SQLException {
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 stmnt.clearParameters();
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
4075
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
133 public boolean execute() throws SQLException {
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
134 return stmnt.execute();
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
135 }
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
136
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
137 public ResultSet executeQuery() throws SQLException {
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
138 return stmnt.executeQuery();
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
139 }
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
140
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
141 public int executeUpdate() throws SQLException {
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
142 return stmnt.executeUpdate();
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
143 }
dbd0b3b1b8b8 Sync each river.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 4073
diff changeset
144
4073
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 } // class Instance
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 public SymbolicStatement(String statement) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 this.statement = statement;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 compile();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 public String getStatement() {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 return statement;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 protected void compile() {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 positions = new HashMap<String, List<Integer>>();
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 StringBuffer sb = new StringBuffer();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 Matcher m = VAR.matcher(statement);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 int index = 1;
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 while (m.find()) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 String key = m.group(1).toLowerCase();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 List<Integer> list = positions.get(key);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 if (list == null) {
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 list = new ArrayList<Integer>();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 positions.put(key, list);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 list.add(index++);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 m.appendReplacement(sb, "?");
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 m.appendTail(sb);
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 compiled = sb.toString();
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 }
2c70fae83d0c start syncing at river level.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 } // class SymbolicStatement

http://dive4elements.wald.intevation.org