17
17
import net .sf .jsqlparser .statement .ReturningClause ;
18
18
import net .sf .jsqlparser .statement .Statement ;
19
19
import net .sf .jsqlparser .statement .StatementVisitor ;
20
+ import net .sf .jsqlparser .statement .select .FromItem ;
20
21
import net .sf .jsqlparser .statement .select .Join ;
21
22
import net .sf .jsqlparser .statement .select .Limit ;
22
23
import net .sf .jsqlparser .statement .select .OrderByElement ;
29
30
import java .util .Iterator ;
30
31
import java .util .List ;
31
32
import java .util .Optional ;
33
+ import java .util .stream .Collectors ;
32
34
33
35
import static java .util .stream .Collectors .joining ;
34
36
@@ -38,7 +40,7 @@ public class Delete implements Statement {
38
40
private Table table ;
39
41
private OracleHint oracleHint = null ;
40
42
private List <Table > tables ;
41
- private List <Table > usingList ;
43
+ private List <FromItem > usingFromItemList ;
42
44
private List <Join > joins ;
43
45
private Expression where ;
44
46
private PreferringClause preferringClause ;
@@ -157,12 +159,29 @@ public void setTables(List<Table> tables) {
157
159
this .tables = tables ;
158
160
}
159
161
162
+ /**
163
+ * This is compatible with the old logic. When calling this method, you need to ensure that the
164
+ * specific table is used after using.
165
+ *
166
+ * @return Table collection used in using.
167
+ */
168
+ @ Deprecated
160
169
public List <Table > getUsingList () {
161
- return usingList ;
170
+ if (usingFromItemList == null || usingFromItemList .isEmpty ()) {
171
+ return new ArrayList <>();
172
+ }
173
+ return usingFromItemList .stream ().map (ele -> (Table ) ele ).collect (Collectors .toList ());
162
174
}
163
175
176
+ /**
177
+ * This is compatible with the old logic. When calling this method, you need to ensure that the
178
+ * specific table is used after using.
179
+ *
180
+ * @param usingList Table collection used in using.
181
+ */
182
+ @ Deprecated
164
183
public void setUsingList (List <Table > usingList ) {
165
- this .usingList = usingList ;
184
+ this .usingFromItemList = new ArrayList <>( usingList ) ;
166
185
}
167
186
168
187
public List <Join > getJoins () {
@@ -228,10 +247,10 @@ public String toString() {
228
247
}
229
248
b .append (" " ).append (table );
230
249
231
- if (usingList != null && usingList . size () > 0 ) {
250
+ if (usingFromItemList != null && ! usingFromItemList . isEmpty () ) {
232
251
b .append (" USING " );
233
- b .append (usingList .stream ()
234
- .map (Table ::toString )
252
+ b .append (usingFromItemList .stream ()
253
+ .map (Object ::toString )
235
254
.collect (joining (", " )));
236
255
}
237
256
@@ -273,11 +292,30 @@ public Delete withTables(List<Table> tables) {
273
292
return this ;
274
293
}
275
294
295
+ /**
296
+ * The old method has been replaced by withUsingFromItemList.
297
+ *
298
+ * @param usingList
299
+ * @return
300
+ * @see Delete#withUsingFromItemList
301
+ */
302
+ @ Deprecated
276
303
public Delete withUsingList (List <Table > usingList ) {
277
304
this .setUsingList (usingList );
278
305
return this ;
279
306
}
280
307
308
+ /**
309
+ * New using syntax method.Supports the complete using syntax of pg, such as subqueries, etc.
310
+ *
311
+ * @param usingFromItemList
312
+ * @return
313
+ */
314
+ public Delete withUsingFromItemList (List <FromItem > usingFromItemList ) {
315
+ this .setUsingFromItemList (usingFromItemList );
316
+ return this ;
317
+ }
318
+
281
319
public Delete withJoins (List <Join > joins ) {
282
320
this .setJoins (joins );
283
321
return this ;
@@ -364,18 +402,60 @@ public Delete addTables(Collection<? extends Table> tables) {
364
402
return this .withTables (collection );
365
403
}
366
404
405
+ /**
406
+ * The old method has been replaced by addUsingFromItemList.
407
+ *
408
+ * @param usingList
409
+ * @return
410
+ * @see Delete#addUsingFromItemList
411
+ */
412
+ @ Deprecated
367
413
public Delete addUsingList (Table ... usingList ) {
368
414
List <Table > collection = Optional .ofNullable (getUsingList ()).orElseGet (ArrayList ::new );
369
415
Collections .addAll (collection , usingList );
370
416
return this .withUsingList (collection );
371
417
}
372
418
419
+ /**
420
+ * New using syntax method.Supports the complete using syntax of pg, such as subqueries, etc.
421
+ *
422
+ * @param usingFromItemList
423
+ * @return
424
+ */
425
+ public Delete addUsingFromItemList (FromItem ... usingFromItemList ) {
426
+ List <FromItem > collection =
427
+ Optional .ofNullable (getUsingFromItemList ()).orElseGet (ArrayList ::new );
428
+ Collections .addAll (collection , usingFromItemList );
429
+ return this .withUsingFromItemList (collection );
430
+ }
431
+
432
+ /**
433
+ * The old method has been replaced by addUsingFromItemList.
434
+ *
435
+ * @param usingList
436
+ * @return
437
+ * @see Delete#addUsingFromItemList
438
+ */
439
+ @ Deprecated
373
440
public Delete addUsingList (Collection <? extends Table > usingList ) {
374
441
List <Table > collection = Optional .ofNullable (getUsingList ()).orElseGet (ArrayList ::new );
375
442
collection .addAll (usingList );
376
443
return this .withUsingList (collection );
377
444
}
378
445
446
+ /**
447
+ * New using syntax method. Supports the complete using syntax of pg, such as subqueries, etc.
448
+ *
449
+ * @param usingFromItemList
450
+ * @return
451
+ */
452
+ public Delete addUsingFromItemList (Collection <? extends Table > usingFromItemList ) {
453
+ List <FromItem > collection =
454
+ Optional .ofNullable (getUsingFromItemList ()).orElseGet (ArrayList ::new );
455
+ collection .addAll (usingFromItemList );
456
+ return this .withUsingFromItemList (collection );
457
+ }
458
+
379
459
public Delete addJoins (Join ... joins ) {
380
460
List <Join > collection = Optional .ofNullable (getJoins ()).orElseGet (ArrayList ::new );
381
461
Collections .addAll (collection , joins );
@@ -405,4 +485,23 @@ public Delete addOrderByElements(Collection<? extends OrderByElement> orderByEle
405
485
public <E extends Expression > E getWhere (Class <E > type ) {
406
486
return type .cast (getWhere ());
407
487
}
488
+
489
+ /**
490
+ * Return the content after using. Supports the complete using syntax of pg, such as subqueries,
491
+ * etc.
492
+ *
493
+ * @return
494
+ */
495
+ public List <FromItem > getUsingFromItemList () {
496
+ return usingFromItemList ;
497
+ }
498
+
499
+ /**
500
+ * Supports the complete using syntax of pg, such as subqueries, etc.
501
+ *
502
+ * @param usingFromItemList The content after using.
503
+ */
504
+ public void setUsingFromItemList (List <FromItem > usingFromItemList ) {
505
+ this .usingFromItemList = usingFromItemList ;
506
+ }
408
507
}
0 commit comments