-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathAbstractJSqlParser.java
More file actions
234 lines (185 loc) · 7.95 KB
/
Copy pathAbstractJSqlParser.java
File metadata and controls
234 lines (185 loc) · 7.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2020 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.parser;
import net.sf.jsqlparser.parser.feature.Feature;
import net.sf.jsqlparser.parser.feature.FeatureConfiguration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
public abstract class AbstractJSqlParser<P> {
protected int jdbcParameterIndex = 0;
protected boolean errorRecovery = false;
protected List<ParseException> parseErrors = new ArrayList<>();
public enum AdjacentStringLiterals {
OFF, NEWLINE, WHITESPACE
}
public enum Dialect {
ANSI_SQL(AdjacentStringLiterals.NEWLINE), ORACLE, MYSQL(AdjacentStringLiterals.OFF,
Feature.allowBackslashEscapeCharacter,
Feature.allowHashLineComments,
Feature.allowDoubleQuotedStrings), MARIADB(AdjacentStringLiterals.OFF,
Feature.allowBackslashEscapeCharacter,
Feature.allowHashLineComments,
Feature.allowDoubleQuotedStrings), SQLSERVER(AdjacentStringLiterals.OFF,
Feature.allowSquareBracketQuotation), POSTGRESQL(
AdjacentStringLiterals.NEWLINE), H2, EXASOL, BIGQUERY(
AdjacentStringLiterals.WHITESPACE,
Feature.allowDoubleQuotedStrings,
Feature.allowHashLineComments,
Feature.allowBackslashEscapeCharacter), DATABRICKS(
AdjacentStringLiterals.WHITESPACE,
Feature.allowDoubleQuotedStrings,
Feature.allowBackslashEscapeCharacter), SNOWFLAKE(
Feature.allowBackslashEscapeCharacter);
private final Set<Feature> lexerFeatures;
private final AdjacentStringLiterals adjacentStringLiterals;
Dialect(AdjacentStringLiterals adjacentStringLiterals, Feature... lexerFeatures) {
this.adjacentStringLiterals = adjacentStringLiterals;
this.lexerFeatures = lexerFeatures.length == 0 ? EnumSet.noneOf(Feature.class)
: EnumSet.copyOf(Arrays.asList(lexerFeatures));
}
Dialect(Feature... lexerFeatures) {
this(AdjacentStringLiterals.OFF, lexerFeatures);
}
public Set<Feature> getLexerFeatures() {
return lexerFeatures;
}
public AdjacentStringLiterals getAdjacentStringLiterals() {
return adjacentStringLiterals;
}
}
public P withSquareBracketQuotation() {
return withFeature(Feature.allowSquareBracketQuotation, true);
}
public P withSquareBracketQuotation(boolean allowSquareBracketQuotation) {
return withFeature(Feature.allowSquareBracketQuotation, allowSquareBracketQuotation);
}
public P withAllowComplexParsing() {
return withFeature(Feature.allowComplexParsing, true);
}
public P withAllowComplexParsing(boolean allowComplexParsing) {
return withFeature(Feature.allowComplexParsing, allowComplexParsing);
}
public P withComplexParsing() {
return withFeature(Feature.allowComplexParsing, true);
}
public P withComplexParsing(boolean allowComplexParsing) {
return withFeature(Feature.allowComplexParsing, allowComplexParsing);
}
public P withUnsupportedStatements() {
return withFeature(Feature.allowUnsupportedStatements, true);
}
public P withUnsupportedStatements(boolean allowUnsupportedStatements) {
return withFeature(Feature.allowUnsupportedStatements, allowUnsupportedStatements);
}
public P withTimeOut(long timeOutMillSeconds) {
return withFeature(Feature.timeOut, timeOutMillSeconds);
}
public P withDialect(Dialect dialect) {
withFeature(Feature.dialect, dialect.name());
if (dialect.getAdjacentStringLiterals() != AdjacentStringLiterals.OFF) {
withAdjacentStringLiterals(dialect.getAdjacentStringLiterals());
}
for (Feature lexerFeature : dialect.getLexerFeatures()) {
withFeature(lexerFeature, true);
}
return me();
}
public P withAdjacentStringLiterals() {
return withAdjacentStringLiterals(AdjacentStringLiterals.NEWLINE);
}
public P withAdjacentStringLiterals(boolean adjacentStringLiterals) {
return withAdjacentStringLiterals(
adjacentStringLiterals ? AdjacentStringLiterals.NEWLINE
: AdjacentStringLiterals.OFF);
}
public P withAdjacentStringLiterals(AdjacentStringLiterals adjacentStringLiterals) {
getConfiguration().setValue(Feature.adjacentStringLiterals, adjacentStringLiterals);
return me();
}
public P withAllowedNestingDepth(int allowedNestingDepth) {
return withFeature(Feature.allowedNestingDepth, allowedNestingDepth);
}
public P withBackslashEscapeCharacter() {
return withFeature(Feature.allowBackslashEscapeCharacter, true);
}
public P withBackslashEscapeCharacter(boolean allowBackslashEscapeCharacter) {
return withFeature(Feature.allowBackslashEscapeCharacter, allowBackslashEscapeCharacter);
}
public P withDoubleQuotedStrings() {
return withFeature(Feature.allowDoubleQuotedStrings, true);
}
public P withDoubleQuotedStrings(boolean allowDoubleQuotedStrings) {
return withFeature(Feature.allowDoubleQuotedStrings, allowDoubleQuotedStrings);
}
public P withHashLineComments() {
return withFeature(Feature.allowHashLineComments, true);
}
public P withHashLineComments(boolean allowHashLineComments) {
return withFeature(Feature.allowHashLineComments, allowHashLineComments);
}
public P withUnparenthesizedSubSelects() {
return withFeature(Feature.allowUnparenthesizedSubSelects, true);
}
public P withUnparenthesizedSubSelects(boolean allowUnparenthesizedSubSelects) {
return withFeature(Feature.allowUnparenthesizedSubSelects, allowUnparenthesizedSubSelects);
}
public P withFeature(Feature f, boolean enabled) {
getConfiguration().setValue(f, enabled);
return me();
}
public P withFeature(Feature f, long value) {
getConfiguration().setValue(f, value);
return me();
}
public P withFeature(Feature f, String value) {
getConfiguration().setValue(f, value);
return me();
}
public abstract FeatureConfiguration getConfiguration();
public FeatureConfiguration setValue(Feature feature, Object value) {
return getConfiguration().setValue(feature, value);
}
public Object getValue(Feature feature) {
return getConfiguration().getValue(feature);
}
public abstract P me();
public boolean getAsBoolean(Feature f) {
return getConfiguration().getAsBoolean(f);
}
public Long getAsLong(Feature f) {
return getConfiguration().getAsLong(f);
}
public int getAsInt(Feature f) {
return getConfiguration().getAsInt(f);
}
public Integer getAsInteger(Feature f) {
return getConfiguration().getAsInteger(f);
}
public String getAsString(Feature f) {
return getConfiguration().getAsString(f);
}
public void setErrorRecovery(boolean errorRecovery) {
this.errorRecovery = errorRecovery;
}
public P withErrorRecovery() {
this.errorRecovery = true;
return me();
}
public P withErrorRecovery(boolean errorRecovery) {
this.errorRecovery = errorRecovery;
return me();
}
public List<ParseException> getParseErrors() {
return parseErrors;
}
}