1717import net .sf .jsqlparser .statement .ReturningClause ;
1818import net .sf .jsqlparser .statement .Statement ;
1919import net .sf .jsqlparser .statement .StatementVisitor ;
20+ import net .sf .jsqlparser .statement .select .FromItem ;
2021import net .sf .jsqlparser .statement .select .Join ;
2122import net .sf .jsqlparser .statement .select .Limit ;
2223import net .sf .jsqlparser .statement .select .OrderByElement ;
2930import java .util .Iterator ;
3031import java .util .List ;
3132import java .util .Optional ;
33+ import java .util .stream .Collectors ;
3234
3335import static java .util .stream .Collectors .joining ;
3436
@@ -38,7 +40,7 @@ public class Delete implements Statement {
3840 private Table table ;
3941 private OracleHint oracleHint = null ;
4042 private List <Table > tables ;
41- private List <Table > usingList ;
43+ private List <FromItem > usingFromItemList ;
4244 private List <Join > joins ;
4345 private Expression where ;
4446 private PreferringClause preferringClause ;
@@ -157,12 +159,29 @@ public void setTables(List<Table> tables) {
157159 this .tables = tables ;
158160 }
159161
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
160169 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 ());
162174 }
163175
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
164183 public void setUsingList (List <Table > usingList ) {
165- this .usingList = usingList ;
184+ this .usingFromItemList = new ArrayList <>( usingList ) ;
166185 }
167186
168187 public List <Join > getJoins () {
@@ -228,10 +247,10 @@ public String toString() {
228247 }
229248 b .append (" " ).append (table );
230249
231- if (usingList != null && usingList . size () > 0 ) {
250+ if (usingFromItemList != null && ! usingFromItemList . isEmpty () ) {
232251 b .append (" USING " );
233- b .append (usingList .stream ()
234- .map (Table ::toString )
252+ b .append (usingFromItemList .stream ()
253+ .map (Object ::toString )
235254 .collect (joining (", " )));
236255 }
237256
@@ -273,11 +292,30 @@ public Delete withTables(List<Table> tables) {
273292 return this ;
274293 }
275294
295+ /**
296+ * The old method has been replaced by withUsingFromItemList.
297+ *
298+ * @param usingList
299+ * @return
300+ * @see Delete#withUsingFromItemList
301+ */
302+ @ Deprecated
276303 public Delete withUsingList (List <Table > usingList ) {
277304 this .setUsingList (usingList );
278305 return this ;
279306 }
280307
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+
281319 public Delete withJoins (List <Join > joins ) {
282320 this .setJoins (joins );
283321 return this ;
@@ -364,18 +402,60 @@ public Delete addTables(Collection<? extends Table> tables) {
364402 return this .withTables (collection );
365403 }
366404
405+ /**
406+ * The old method has been replaced by addUsingFromItemList.
407+ *
408+ * @param usingList
409+ * @return
410+ * @see Delete#addUsingFromItemList
411+ */
412+ @ Deprecated
367413 public Delete addUsingList (Table ... usingList ) {
368414 List <Table > collection = Optional .ofNullable (getUsingList ()).orElseGet (ArrayList ::new );
369415 Collections .addAll (collection , usingList );
370416 return this .withUsingList (collection );
371417 }
372418
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
373440 public Delete addUsingList (Collection <? extends Table > usingList ) {
374441 List <Table > collection = Optional .ofNullable (getUsingList ()).orElseGet (ArrayList ::new );
375442 collection .addAll (usingList );
376443 return this .withUsingList (collection );
377444 }
378445
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+
379459 public Delete addJoins (Join ... joins ) {
380460 List <Join > collection = Optional .ofNullable (getJoins ()).orElseGet (ArrayList ::new );
381461 Collections .addAll (collection , joins );
@@ -405,4 +485,23 @@ public Delete addOrderByElements(Collection<? extends OrderByElement> orderByEle
405485 public <E extends Expression > E getWhere (Class <E > type ) {
406486 return type .cast (getWhere ());
407487 }
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+ }
408507}
0 commit comments