Skip to content

Commit fed0aab

Browse files
committed
Added Oracle COMMENT statement
1 parent de8ad10 commit fed0aab

11 files changed

Lines changed: 416 additions & 13 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2013 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.expression;
23+
24+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
25+
import net.sf.jsqlparser.statement.select.SubSelect;
26+
27+
public class AllComparisonExpression extends ASTNodeAccessImpl implements Expression {
28+
29+
private final SubSelect subSelect;
30+
31+
public AllComparisonExpression(SubSelect subSelect) {
32+
this.subSelect = subSelect;
33+
}
34+
35+
public SubSelect getSubSelect() {
36+
return subSelect;
37+
}
38+
39+
@Override
40+
public void accept(ExpressionVisitor expressionVisitor) {
41+
expressionVisitor.visit(this);
42+
}
43+
44+
@Override
45+
public String toString() {
46+
return "ALL " + subSelect.toString();
47+
}
48+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2017 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
/*
23+
* Copyright (C) 2017 JSQLParser.
24+
*
25+
* This library is free software; you can redistribute it and/or
26+
* modify it under the terms of the GNU Lesser General Public
27+
* License as published by the Free Software Foundation; either
28+
* version 2.1 of the License, or (at your option) any later version.
29+
*
30+
* This library is distributed in the hope that it will be useful,
31+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
32+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33+
* Lesser General Public License for more details.
34+
*
35+
* You should have received a copy of the GNU Lesser General Public
36+
* License along with this library; if not, write to the Free Software
37+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
38+
* MA 02110-1301 USA
39+
*/
40+
package net.sf.jsqlparser.expression;
41+
42+
/**
43+
*
44+
* @author Tobias Warneke (t.warneke@gmx.net)
45+
*/
46+
public enum AnalyticType {
47+
OVER,
48+
WITHIN_GROUP
49+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2013 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.expression;
23+
24+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
25+
import net.sf.jsqlparser.statement.create.table.ColDataType;
26+
27+
/**
28+
*
29+
* @author tw
30+
*/
31+
public class CastExpression extends ASTNodeAccessImpl implements Expression {
32+
33+
private Expression leftExpression;
34+
private ColDataType type;
35+
private boolean useCastKeyword = true;
36+
37+
public ColDataType getType() {
38+
return type;
39+
}
40+
41+
public void setType(ColDataType type) {
42+
this.type = type;
43+
}
44+
45+
public Expression getLeftExpression() {
46+
return leftExpression;
47+
}
48+
49+
public void setLeftExpression(Expression expression) {
50+
leftExpression = expression;
51+
}
52+
53+
@Override
54+
public void accept(ExpressionVisitor expressionVisitor) {
55+
expressionVisitor.visit(this);
56+
}
57+
58+
public boolean isUseCastKeyword() {
59+
return useCastKeyword;
60+
}
61+
62+
public void setUseCastKeyword(boolean useCastKeyword) {
63+
this.useCastKeyword = useCastKeyword;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
if (useCastKeyword) {
69+
return "CAST(" + leftExpression + " AS " + type.toString() + ")";
70+
} else {
71+
return leftExpression + "::" + type.toString();
72+
}
73+
}
74+
}

src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package net.sf.jsqlparser.statement;
2323

2424
import net.sf.jsqlparser.statement.alter.Alter;
25+
import net.sf.jsqlparser.statement.comment.Comment;
2526
import net.sf.jsqlparser.statement.create.index.CreateIndex;
2627
import net.sf.jsqlparser.statement.create.table.CreateTable;
2728
import net.sf.jsqlparser.statement.create.view.AlterView;
@@ -39,6 +40,8 @@
3940

4041
public interface StatementVisitor {
4142

43+
void visit(Comment comment);
44+
4245
void visit(Commit commit);
4346

4447
void visit(Delete delete);

src/main/java/net/sf/jsqlparser/statement/StatementVisitorAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package net.sf.jsqlparser.statement;
2323

2424
import net.sf.jsqlparser.statement.alter.Alter;
25+
import net.sf.jsqlparser.statement.comment.Comment;
2526
import net.sf.jsqlparser.statement.create.index.CreateIndex;
2627
import net.sf.jsqlparser.statement.create.table.CreateTable;
2728
import net.sf.jsqlparser.statement.create.view.AlterView;
@@ -39,6 +40,11 @@
3940

4041
public class StatementVisitorAdapter implements StatementVisitor {
4142

43+
@Override
44+
public void visit(Comment commemt) {
45+
46+
}
47+
4248
@Override
4349
public void visit(Commit commit) {
4450

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2017 JSQLParser
6+
* %%
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation, either version 2.1 of the
10+
* License, or (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Lesser Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Lesser Public
18+
* License along with this program. If not, see
19+
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
20+
* #L%
21+
*/
22+
package net.sf.jsqlparser.statement.comment;
23+
24+
import net.sf.jsqlparser.expression.StringValue;
25+
import net.sf.jsqlparser.schema.Column;
26+
import net.sf.jsqlparser.schema.Table;
27+
import net.sf.jsqlparser.statement.Statement;
28+
import net.sf.jsqlparser.statement.StatementVisitor;
29+
30+
public class Comment implements Statement {
31+
32+
private Table table;
33+
private Column column;
34+
private StringValue comment;
35+
36+
@Override
37+
public void accept(StatementVisitor statementVisitor) {
38+
statementVisitor.visit(this);
39+
}
40+
41+
public Table getTable() {
42+
return table;
43+
}
44+
45+
public void setTable(Table table) {
46+
this.table = table;
47+
}
48+
49+
public Column getColumn() {
50+
return column;
51+
}
52+
53+
public void setColumn(Column column) {
54+
this.column = column;
55+
}
56+
57+
public StringValue getComment() {
58+
return comment;
59+
}
60+
61+
public void setComment(StringValue comment) {
62+
this.comment = comment;
63+
}
64+
65+
@Override
66+
public String toString() {
67+
String sql = "COMMENT ON ";
68+
if (table != null) {
69+
sql += "TABLE " + table + " ";
70+
} else if (column != null) {
71+
sql += "COLUMN " + column + " ";
72+
}
73+
sql += "IS " + comment;
74+
return sql;
75+
}
76+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.util.ArrayList;
2525
import java.util.List;
26+
2627
import net.sf.jsqlparser.expression.AllComparisonExpression;
2728
import net.sf.jsqlparser.expression.AnalyticExpression;
2829
import net.sf.jsqlparser.expression.AnyComparisonExpression;
@@ -100,6 +101,7 @@
100101
import net.sf.jsqlparser.statement.Statements;
101102
import net.sf.jsqlparser.statement.UseStatement;
102103
import net.sf.jsqlparser.statement.alter.Alter;
104+
import net.sf.jsqlparser.statement.comment.Comment;
103105
import net.sf.jsqlparser.statement.create.index.CreateIndex;
104106
import net.sf.jsqlparser.statement.create.table.CreateTable;
105107
import net.sf.jsqlparser.statement.create.view.AlterView;
@@ -811,4 +813,17 @@ public void visit(Block block) {
811813
visit(block.getStatements());
812814
}
813815
}
816+
817+
@Override
818+
public void visit(Comment comment) {
819+
if (comment.getTable() != null) {
820+
visit(comment.getTable());
821+
}
822+
if (comment.getColumn() != null) {
823+
Table table = comment.getColumn().getTable();
824+
if (table != null) {
825+
visit(table);
826+
}
827+
}
828+
}
814829
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import net.sf.jsqlparser.statement.Statements;
3131
import net.sf.jsqlparser.statement.UseStatement;
3232
import net.sf.jsqlparser.statement.alter.Alter;
33+
import net.sf.jsqlparser.statement.comment.Comment;
3334
import net.sf.jsqlparser.statement.create.index.CreateIndex;
3435
import net.sf.jsqlparser.statement.create.table.CreateTable;
3536
import net.sf.jsqlparser.statement.create.view.AlterView;
@@ -240,4 +241,9 @@ public void visit(Block block) {
240241
}
241242
buffer.append("END");
242243
}
244+
245+
@Override
246+
public void visit(Comment comment) {
247+
buffer.append(comment.toString());
248+
}
243249
}

0 commit comments

Comments
 (0)