@@ -122,13 +122,56 @@ WHITESPACE = [ \t\r\n]+
122
122
/* * @return true if all statement info is gathered */
123
123
boolean handleNext () {
124
124
return false ;
125
- }
125
+ }
126
+
127
+ /* * @return true if all statement info is gathered */
128
+ boolean handleOperationTarget (String target ) {
129
+ return false ;
130
+ }
131
+
132
+ boolean expectingOperationTarget () {
133
+ return false ;
134
+ }
126
135
127
136
SqlStatementInfo getResult (String fullStatement ) {
128
137
return SqlStatementInfo . create(fullStatement, getClass(). getSimpleName(). toUpperCase(java.util. Locale . ROOT ), mainIdentifier);
129
138
}
130
139
}
131
140
141
+ private abstract class DdlOperation extends Operation {
142
+ private String operationTarget = " " ;
143
+ private boolean expectingOperationTarget = true ;
144
+
145
+ boolean expectingOperationTarget () {
146
+ return expectingOperationTarget;
147
+ }
148
+
149
+ boolean handleOperationTarget (String target ) {
150
+ operationTarget = target;
151
+ expectingOperationTarget = false ;
152
+ return false ;
153
+ }
154
+
155
+ boolean shouldHandleIdentifier () {
156
+ // Return true only if the provided value corresponds to a table, as it will be used to set the attribute `db.sql.table`.
157
+ return " TABLE" . equals(operationTarget);
158
+ }
159
+
160
+ boolean handleIdentifier () {
161
+ if (shouldHandleIdentifier()) {
162
+ mainIdentifier = readIdentifierName();
163
+ }
164
+ return true ;
165
+ }
166
+
167
+ SqlStatementInfo getResult (String fullStatement ) {
168
+ if (! " " . equals(operationTarget)) {
169
+ return SqlStatementInfo . create(fullStatement, getClass(). getSimpleName(). toUpperCase(java.util. Locale . ROOT ) + " " + operationTarget, mainIdentifier);
170
+ }
171
+ return super . getResult(fullStatement);
172
+ }
173
+ }
174
+
132
175
private static class NoOp extends Operation {
133
176
static final Operation INSTANCE = new NoOp ();
134
177
@@ -273,6 +316,15 @@ WHITESPACE = [ \t\r\n]+
273
316
}
274
317
}
275
318
319
+ private class Create extends DdlOperation {
320
+ }
321
+
322
+ private class Drop extends DdlOperation {
323
+ }
324
+
325
+ private class Alter extends DdlOperation {
326
+ }
327
+
276
328
private SqlStatementInfo getResult() {
277
329
if (builder. length() > LIMIT ) {
278
330
builder. delete(LIMIT , builder. length());
@@ -329,6 +381,27 @@ WHITESPACE = [ \t\r\n]+
329
381
appendCurrentFragment();
330
382
if (isOverLimit()) return YYEOF ;
331
383
}
384
+ "CREATE" {
385
+ if (! insideComment) {
386
+ setOperation(new Create ());
387
+ }
388
+ appendCurrentFragment();
389
+ if (isOverLimit()) return YYEOF ;
390
+ }
391
+ "DROP" {
392
+ if (! insideComment) {
393
+ setOperation(new Drop ());
394
+ }
395
+ appendCurrentFragment();
396
+ if (isOverLimit()) return YYEOF ;
397
+ }
398
+ "ALTER" {
399
+ if (! insideComment) {
400
+ setOperation(new Alter ());
401
+ }
402
+ appendCurrentFragment();
403
+ if (isOverLimit()) return YYEOF ;
404
+ }
332
405
"FROM" {
333
406
if (! insideComment && ! extractionDone) {
334
407
if (operation == NoOp . INSTANCE ) {
@@ -358,7 +431,62 @@ WHITESPACE = [ \t\r\n]+
358
431
"NEXT" {
359
432
if (! insideComment && ! extractionDone) {
360
433
extractionDone = operation. handleNext();
434
+ }
435
+ appendCurrentFragment();
436
+ if (isOverLimit()) return YYEOF ;
437
+ }
438
+ "TABLE" {
439
+ if (! insideComment && ! extractionDone) {
440
+ if (operation. expectingOperationTarget()) {
441
+ extractionDone = operation. handleOperationTarget(" TABLE" );
442
+ } else {
443
+ extractionDone = operation. handleIdentifier();
444
+ }
445
+ }
446
+ appendCurrentFragment();
447
+ if (isOverLimit()) return YYEOF ;
448
+ }
449
+ "INDEX" {
450
+ if (! insideComment && ! extractionDone) {
451
+ if (operation. expectingOperationTarget()) {
452
+ extractionDone = operation. handleOperationTarget(" INDEX" );
453
+ } else {
454
+ extractionDone = operation. handleIdentifier();
455
+ }
456
+ }
457
+ appendCurrentFragment();
458
+ if (isOverLimit()) return YYEOF ;
459
+ }
460
+ "DATABASE" {
461
+ if (! insideComment && ! extractionDone) {
462
+ if (operation. expectingOperationTarget()) {
463
+ extractionDone = operation. handleOperationTarget(" DATABASE" );
464
+ } else {
465
+ extractionDone = operation. handleIdentifier();
466
+ }
467
+ }
468
+ appendCurrentFragment();
469
+ if (isOverLimit()) return YYEOF ;
470
+ }
471
+ "PROCEDURE" {
472
+ if (! insideComment && ! extractionDone) {
473
+ if (operation. expectingOperationTarget()) {
474
+ extractionDone = operation. handleOperationTarget(" PROCEDURE" );
475
+ } else {
476
+ extractionDone = operation. handleIdentifier();
477
+ }
478
+ }
479
+ appendCurrentFragment();
480
+ if (isOverLimit()) return YYEOF ;
481
+ }
482
+ "VIEW" {
483
+ if (! insideComment && ! extractionDone) {
484
+ if (operation. expectingOperationTarget()) {
485
+ extractionDone = operation. handleOperationTarget(" VIEW" );
486
+ } else {
487
+ extractionDone = operation. handleIdentifier();
361
488
}
489
+ }
362
490
appendCurrentFragment();
363
491
if (isOverLimit()) return YYEOF ;
364
492
}
0 commit comments