1313import java .util .LinkedHashMap ;
1414import java .util .List ;
1515import java .util .stream .Collectors ;
16-
1716import net .sf .jsqlparser .schema .Table ;
18- import net .sf .jsqlparser .statement .select .Select ;
1917
2018/**
2119 * An {@code EXPLAIN} statement
2220 */
2321public class ExplainStatement implements Statement {
2422 private String keyword ;
25- private Select select ;
23+ private Statement statement ;
2624 private LinkedHashMap <OptionType , Option > options ;
2725 private Table table ;
2826
@@ -37,24 +35,17 @@ public ExplainStatement() {
3735 public ExplainStatement (String keyword , Table table ) {
3836 this .keyword = keyword ;
3937 this .table = table ;
40- this .select = null ;
4138 }
4239
43- public ExplainStatement (String keyword , Select select , List <Option > optionList ) {
40+ public ExplainStatement (String keyword , Statement statement , List <Option > optionList ) {
4441 this .keyword = keyword ;
45- this .select = select ;
46- this .table = null ;
42+ setStatement (statement );
4743
48- if (optionList != null && !optionList .isEmpty ()) {
49- options = new LinkedHashMap <>();
50- for (Option o : optionList ) {
51- options .put (o .getType (), o );
52- }
53- }
44+ initializeOptions (optionList );
5445 }
5546
56- public ExplainStatement (Select select ) {
57- this ("EXPLAIN" , select , null );
47+ public ExplainStatement (Statement statement ) {
48+ this ("EXPLAIN" , statement , null );
5849 }
5950
6051 public Table getTable () {
@@ -63,15 +54,20 @@ public Table getTable() {
6354
6455 public ExplainStatement setTable (Table table ) {
6556 this .table = table ;
57+ if (table != null ) {
58+ this .statement = null ;
59+ }
6660 return this ;
6761 }
6862
69- public Select getStatement () {
70- return select ;
63+ public Statement getStatement () {
64+ return statement ;
7165 }
7266
73- public void setStatement (Select select ) {
74- this .select = select ;
67+ public ExplainStatement setStatement (Statement statement ) {
68+ this .table = null ;
69+ this .statement = statement ;
70+ return this ;
7571 }
7672
7773 public LinkedHashMap <OptionType , Option > getOptions () {
@@ -122,8 +118,8 @@ public String toString() {
122118 }
123119
124120 builder .append (" " );
125- if (select != null ) {
126- select . appendTo ( builder );
121+ if (statement != null ) {
122+ builder . append ( statement );
127123 }
128124 }
129125
@@ -135,6 +131,15 @@ public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
135131 return statementVisitor .visit (this , context );
136132 }
137133
134+ private void initializeOptions (List <Option > optionList ) {
135+ if (optionList != null && !optionList .isEmpty ()) {
136+ options = new LinkedHashMap <>();
137+ for (Option o : optionList ) {
138+ options .put (o .getType (), o );
139+ }
140+ }
141+ }
142+
138143 public enum OptionType {
139144 ANALYZE , VERBOSE , COSTS , BUFFERS , FORMAT , PLAN , PLAN_FOR ;
140145
0 commit comments