Skip to content

Commit 10e8f7f

Browse files
committed
add WithItem to visitor interface
1 parent 0079970 commit 10e8f7f

File tree

6 files changed

+64
-33
lines changed

6 files changed

+64
-33
lines changed
Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
/* ================================================================
2-
* JSQLParser : java based sql parser
3-
* ================================================================
4-
*
5-
* Project Info: http://jsqlparser.sourceforge.net
6-
* Project Lead: Leonardo Francalanci (leoonardoo@yahoo.it);
7-
*
8-
* (C) Copyright 2004, by Leonardo Francalanci
9-
*
10-
* This library is free software; you can redistribute it and/or modify it under the terms
11-
* of the GNU Lesser General Public License as published by the Free Software Foundation;
12-
* either version 2.1 of the License, or (at your option) any later version.
13-
*
14-
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15-
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16-
* See the GNU Lesser General Public License for more details.
17-
*
18-
* You should have received a copy of the GNU Lesser General Public License along with this
19-
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20-
* Boston, MA 02111-1307, USA.
21-
*/
22-
23-
package net.sf.jsqlparser.statement.select;
24-
25-
public interface SelectVisitor {
26-
public void visit(PlainSelect plainSelect);
27-
28-
public void visit(SetOperationList setOpList);
29-
}
1+
/* ================================================================
2+
* JSQLParser : java based sql parser
3+
* ================================================================
4+
*
5+
* Project Info: http://jsqlparser.sourceforge.net
6+
* Project Lead: Leonardo Francalanci (leoonardoo@yahoo.it);
7+
*
8+
* (C) Copyright 2004, by Leonardo Francalanci
9+
*
10+
* This library is free software; you can redistribute it and/or modify it under the terms
11+
* of the GNU Lesser General Public License as published by the Free Software Foundation;
12+
* either version 2.1 of the License, or (at your option) any later version.
13+
*
14+
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16+
* See the GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License along with this
19+
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20+
* Boston, MA 02111-1307, USA.
21+
*/
22+
package net.sf.jsqlparser.statement.select;
23+
24+
public interface SelectVisitor {
25+
26+
public void visit(PlainSelect plainSelect);
27+
28+
public void visit(SetOperationList setOpList);
29+
30+
public void visit(WithItem withItem);
31+
}

src/main/java/net/sf/jsqlparser/statement/select/WithItem.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* One of the parts of a "WITH" clause of a "SELECT" statement
77
*/
8-
public class WithItem {
8+
public class WithItem implements SelectBody {
99
private String name;
1010
private List<SelectItem> withItemList;
1111
private SelectBody selectBody;
@@ -54,5 +54,8 @@ public String toString() {
5454
return name + ((withItemList != null) ? " " + PlainSelect.getStringList(withItemList, true, true) : "")
5555
+ " AS (" + selectBody + ")";
5656
}
57-
57+
58+
public void accept(SelectVisitor visitor) {
59+
visitor.visit(this);
60+
}
5861
}

src/main/java/net/sf/jsqlparser/util/AddAliasesVisitor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import net.sf.jsqlparser.statement.select.SelectItemVisitor;
1111
import net.sf.jsqlparser.statement.select.SelectVisitor;
1212
import net.sf.jsqlparser.statement.select.SetOperationList;
13+
import net.sf.jsqlparser.statement.select.WithItem;
1314

1415
/**
1516
* Add aliases to every column and expression selected by a
@@ -96,4 +97,9 @@ protected String getNextAlias() {
9697
public void setPrefix(String prefix) {
9798
this.prefix = prefix;
9899
}
100+
101+
@Override
102+
public void visit(WithItem withItem) {
103+
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
104+
}
99105
}

src/main/java/net/sf/jsqlparser/util/ConnectExpressionsVisitor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.sf.jsqlparser.statement.select.SelectItemVisitor;
1212
import net.sf.jsqlparser.statement.select.SelectVisitor;
1313
import net.sf.jsqlparser.statement.select.SetOperationList;
14+
import net.sf.jsqlparser.statement.select.WithItem;
1415

1516
/**
1617
* Connect all selected expressions with a binary expression. Out of select a,b from table
@@ -69,6 +70,10 @@ public void visit(SetOperationList setOpList) {
6970
select.accept(this);
7071
}
7172
}
73+
74+
@Override
75+
public void visit(WithItem withItem) {
76+
}
7277

7378
@Override
7479
public void visit(AllColumns allColumns) {

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,29 @@ public class TablesNamesFinder implements SelectVisitor, FromItemVisitor, Expres
7474
*/
7575
private List<String> otherItemNames;
7676

77+
/**
78+
* Main entry for this Tool class. A list of found tables is returned.
79+
* @param select
80+
* @return
81+
*/
7782
public List<String> getTableList(Select select) {
7883
otherItemNames = new ArrayList<String>();
7984
tables = new ArrayList<String>();
8085
if (select.getWithItemsList() != null) {
8186
for (WithItem withItem : select.getWithItemsList()) {
82-
otherItemNames.add(withItem.getName().toLowerCase());
83-
withItem.getSelectBody().accept(this);
87+
withItem.accept(this);
8488
}
8589
}
8690
select.getSelectBody().accept(this);
8791

8892
return tables;
8993
}
94+
95+
@Override
96+
public void visit(WithItem withItem) {
97+
otherItemNames.add(withItem.getName().toLowerCase());
98+
withItem.getSelectBody().accept(this);
99+
}
90100

91101
@Override
92102
public void visit(PlainSelect plainSelect) {

src/main/java/net/sf/jsqlparser/util/deparser/SelectDeParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import net.sf.jsqlparser.statement.select.SubJoin;
2525
import net.sf.jsqlparser.statement.select.SubSelect;
2626
import net.sf.jsqlparser.statement.select.Top;
27+
import net.sf.jsqlparser.statement.select.WithItem;
2728

2829
/**
2930
* A class to de-parse (that is, tranform from JSqlParser hierarchy into a string) a
@@ -295,4 +296,8 @@ public void visit(SetOperationList list) {
295296
deparseLimit(list.getLimit());
296297
}
297298
}
299+
300+
@Override
301+
public void visit(WithItem withItem) {
302+
}
298303
}

0 commit comments

Comments
 (0)