1414import java .util .Collections ;
1515import java .util .HashMap ;
1616import java .util .List ;
17+ import java .util .Locale ;
1718import java .util .Map ;
1819import java .util .Optional ;
20+ import java .util .stream .Collectors ;
1921
2022import net .sf .jsqlparser .schema .Table ;
2123import net .sf .jsqlparser .statement .Statement ;
2426
2527public class Drop implements Statement {
2628
29+ public enum ObjectType {
30+ DATABASE , EVENT , FUNCTION , INDEX , PROCEDURE , SCHEMA , SEQUENCE , SERVER , TABLE , TABLESPACE , TRIGGER , VIEW , OTHER
31+ }
32+
2733 private String type ;
28- private Table name ;
34+ private ObjectType objectType = ObjectType .OTHER ;
35+ private final List <Table > names = new ArrayList <>();
2936 private List <String > parameters ;
3037 private Map <String , List <String >> typeToParameters = new HashMap <>();
3138 private boolean ifExists = false ;
@@ -46,11 +53,25 @@ public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
4653 }
4754
4855 public Table getName () {
49- return name ;
56+ return names .isEmpty () ? null : names .get (0 );
57+ }
58+
59+ public void setName (Table name ) {
60+ names .clear ();
61+ if (name != null ) {
62+ names .add (name );
63+ }
64+ }
65+
66+ public List <Table > getNames () {
67+ return Collections .unmodifiableList (names );
5068 }
5169
52- public void setName (Table string ) {
53- name = string ;
70+ public void setNames (Collection <? extends Table > names ) {
71+ this .names .clear ();
72+ if (names != null ) {
73+ this .names .addAll (names );
74+ }
5475 }
5576
5677 public List <String > getParameters () {
@@ -67,6 +88,22 @@ public String getType() {
6788
6889 public void setType (String string ) {
6990 type = string ;
91+ try {
92+ objectType = ObjectType .valueOf (string .toUpperCase (Locale .ROOT ));
93+ } catch (IllegalArgumentException | NullPointerException ignored ) {
94+ objectType = ObjectType .OTHER ;
95+ }
96+ }
97+
98+ public ObjectType getObjectType () {
99+ return objectType ;
100+ }
101+
102+ public void setObjectType (ObjectType objectType ) {
103+ this .objectType = objectType == null ? ObjectType .OTHER : objectType ;
104+ if (this .objectType != ObjectType .OTHER ) {
105+ this .type = this .objectType .name ();
106+ }
70107 }
71108
72109 public boolean isIfExists () {
@@ -112,7 +149,8 @@ public String toString() {
112149 + (isUsingTemporary ? "TEMPORARY " : "" )
113150 + (materialized ? "MATERIALIZED " : "" )
114151 + type + " "
115- + (ifExists ? "IF EXISTS " : "" ) + name .toString ();
152+ + (ifExists ? "IF EXISTS " : "" ) + names .stream ().map (Table ::toString )
153+ .collect (Collectors .joining (", " ));
116154
117155 if (type .equals ("FUNCTION" )) {
118156 sql += formatFuncParams (getParamsByType ("FUNCTION" ));
@@ -149,6 +187,21 @@ public Drop withName(Table name) {
149187 return this ;
150188 }
151189
190+ public Drop withNames (Collection <? extends Table > names ) {
191+ setNames (names );
192+ return this ;
193+ }
194+
195+ public Drop addNames (Table ... names ) {
196+ Collections .addAll (this .names , names );
197+ return this ;
198+ }
199+
200+ public Drop withObjectType (ObjectType objectType ) {
201+ setObjectType (objectType );
202+ return this ;
203+ }
204+
152205 public Drop withParameters (List <String > parameters ) {
153206 this .setParameters (parameters );
154207 return this ;
0 commit comments