-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpressionVisitorWrapper.java
347 lines (296 loc) · 9.86 KB
/
ExpressionVisitorWrapper.java
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
package expvisitors;
// Wrapper of JSQL Parser
/**
*
* @authors
* Saarthak Chandra
* Shweta Srivastava
* Vikas P Nelamangala
*
*
*/
import error.SQLCustomErrorHandler;
import net.sf.jsqlparser.expression.AllComparisonExpression;
import net.sf.jsqlparser.expression.AnyComparisonExpression;
import net.sf.jsqlparser.expression.CaseExpression;
import net.sf.jsqlparser.expression.DateValue;
import net.sf.jsqlparser.expression.DoubleValue;
import net.sf.jsqlparser.expression.ExpressionVisitor;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.InverseExpression;
import net.sf.jsqlparser.expression.JdbcParameter;
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.NullValue;
import net.sf.jsqlparser.expression.Parenthesis;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.expression.TimeValue;
import net.sf.jsqlparser.expression.TimestampValue;
import net.sf.jsqlparser.expression.WhenClause;
import net.sf.jsqlparser.expression.operators.arithmetic.Addition;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseAnd;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseOr;
import net.sf.jsqlparser.expression.operators.arithmetic.BitwiseXor;
import net.sf.jsqlparser.expression.operators.arithmetic.Concat;
import net.sf.jsqlparser.expression.operators.arithmetic.Division;
import net.sf.jsqlparser.expression.operators.arithmetic.Multiplication;
import net.sf.jsqlparser.expression.operators.arithmetic.Subtraction;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.relational.Between;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
import net.sf.jsqlparser.expression.operators.relational.GreaterThan;
import net.sf.jsqlparser.expression.operators.relational.GreaterThanEquals;
import net.sf.jsqlparser.expression.operators.relational.InExpression;
import net.sf.jsqlparser.expression.operators.relational.IsNullExpression;
import net.sf.jsqlparser.expression.operators.relational.LikeExpression;
import net.sf.jsqlparser.expression.operators.relational.Matches;
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.SubSelect;
public class ExpressionVisitorWrapper implements ExpressionVisitor{
long expressionValue=0;
boolean expressionResult = false;
public boolean getExpressionEvaluationResult(){
return expressionResult;
}
@Override
public void visit(NullValue arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(Function arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(InverseExpression arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(JdbcParameter arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(DoubleValue arg0) {
// TODO Auto-generated method stub
}
@Override
public void visit(LongValue arg0) {
expressionValue = arg0.getValue();
}
@Override
public void visit(DateValue arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(TimeValue arg0) {
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(TimestampValue arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(Parenthesis arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(StringValue arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(Addition arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(Division arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(Multiplication arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(Subtraction arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(AndExpression arg0) {
// TODO Auto-generated method stub
arg0.getLeftExpression().accept(this);
boolean leftChild = expressionResult;
arg0.getRightExpression().accept(this);
boolean rightChild = expressionResult;
expressionResult = leftChild && rightChild;
}
@Override
public void visit(OrExpression arg0) {
// TODO Auto-generated method stub
}
@Override
public void visit(Between arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(EqualsTo arg0) {
// TODO Auto-generated method stub
arg0.getLeftExpression().accept(this);
double leftChild = expressionValue;
arg0.getRightExpression().accept(this);
double rightChild = expressionValue;
if(leftChild == rightChild)
expressionResult=true;
else
expressionResult = false;
}
@Override
public void visit(GreaterThan arg0) {
// TODO Auto-generated method stub
arg0.getLeftExpression().accept(this);
double leftChild = expressionValue;
arg0.getRightExpression().accept(this);
double rightChild = expressionValue;
if(leftChild > rightChild)
expressionResult=true;
else
expressionResult = false;
}
@Override
public void visit(GreaterThanEquals arg0) {
// TODO Auto-generated method stub
arg0.getLeftExpression().accept(this);
double leftChild = expressionValue;
arg0.getRightExpression().accept(this);
double rightChild = expressionValue;
if(leftChild >= rightChild)
expressionResult=true;
else
expressionResult = false;
}
@Override
public void visit(InExpression arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(IsNullExpression arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(LikeExpression arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(MinorThan arg0) {
// TODO Auto-generated method stub
arg0.getLeftExpression().accept(this);
double leftChild = expressionValue;
arg0.getRightExpression().accept(this);
double rightChild = expressionValue;
if(leftChild < rightChild)
expressionResult=true;
else
expressionResult = false;
}
@Override
public void visit(MinorThanEquals arg0) {
// TODO Auto-generated method stub
arg0.getLeftExpression().accept(this);
double leftChild = expressionValue;
arg0.getRightExpression().accept(this);
double rightChild = expressionValue;
if(leftChild <= rightChild)
expressionResult=true;
else
expressionResult = false;
}
@Override
public void visit(NotEqualsTo arg0) {
// TODO Auto-generated method stub
arg0.getLeftExpression().accept(this);
double leftChild = expressionValue;
arg0.getRightExpression().accept(this);
double rightChild = expressionValue;
if(leftChild != rightChild)
expressionResult=true;
else
expressionResult = false;
}
@Override
public void visit(Column arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(SubSelect arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(CaseExpression arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(WhenClause arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(ExistsExpression arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(AllComparisonExpression arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(AnyComparisonExpression arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(Concat arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(Matches arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(BitwiseAnd arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(BitwiseOr arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
@Override
public void visit(BitwiseXor arg0) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unsupported Operation");
}
}