Skip to content

Commit

Permalink
Merge commit 'd662484b73594eb7e4a1a1e60dfa0d34fb1f13a4' into IfElseSt…
Browse files Browse the repository at this point in the history
…atement

Conflicts:
	src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java
	src/main/java/net/sf/jsqlparser/statement/StatementVisitorAdapter.java
	src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
	src/main/java/net/sf/jsqlparser/util/deparser/StatementDeParser.java
	src/main/java/net/sf/jsqlparser/util/validation/validator/StatementValidator.java
  • Loading branch information
manticore-projects committed Jul 27, 2021
2 parents 456208e + d662484 commit ec4fff3
Show file tree
Hide file tree
Showing 27 changed files with 919 additions and 54 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,16 @@
</configuration>
</plugin>
<plugin>
<groupId>org.javacc.plugin</groupId>
<artifactId>javacc-maven-plugin</artifactId>
<version>3.0.3</version>

<!--
<groupId>org.codehaus.mojo</groupId>
<artifactId>javacc-maven-plugin</artifactId>
<version>2.6</version>
-->

<executions>
<execution>
<id>javacc</id>
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/net/sf/jsqlparser/expression/CastExpression.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,30 @@ public class CastExpression extends ASTNodeAccessImpl implements Expression {

private Expression leftExpression;
private ColDataType type;
private RowConstructor rowConstructor;
private boolean useCastKeyword = true;

public RowConstructor getRowConstructor() {
return rowConstructor;
}

public void setRowConstructor(RowConstructor rowConstructor) {
this.rowConstructor = rowConstructor;
this.type = null;
}

public CastExpression withRowConstructor(RowConstructor rowConstructor) {
setRowConstructor(rowConstructor);
return this;
}

public ColDataType getType() {
return type;
}

public void setType(ColDataType type) {
this.type = type;
this.rowConstructor = null;
}

public Expression getLeftExpression() {
Expand All @@ -50,7 +66,9 @@ public void setUseCastKeyword(boolean useCastKeyword) {
@Override
public String toString() {
if (useCastKeyword) {
return "CAST(" + leftExpression + " AS " + type.toString() + ")";
return rowConstructor!=null
? "CAST(" + leftExpression + " AS " + rowConstructor.toString() + ")"
: "CAST(" + leftExpression + " AS " + type.toString() + ")";
} else {
return leftExpression + "::" + type.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.sf.jsqlparser.expression.operators.conditional.XorExpression;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
import net.sf.jsqlparser.statement.select.AllColumns;
import net.sf.jsqlparser.statement.select.AllTableColumns;
import net.sf.jsqlparser.statement.select.ExpressionListItem;
Expand Down Expand Up @@ -503,8 +504,14 @@ public void visit(SelectExpressionItem selectExpressionItem) {

@Override
public void visit(RowConstructor rowConstructor) {
for (Expression expr : rowConstructor.getExprList().getExpressions()) {
expr.accept(this);
if (rowConstructor.getColumnDefinitions().isEmpty()) {
for (Expression expression: rowConstructor.getExprList().getExpressions()) {
expression.accept(this);
}
} else {
for (ColumnDefinition columnDefinition : rowConstructor.getColumnDefinitions()) {
columnDefinition.accept(this);
}
}
}

Expand Down Expand Up @@ -605,4 +612,8 @@ public void visit(JsonFunction expression) {
expr.getExpression().accept(this);
}
}

public void visit(ColumnDefinition columnDefinition) {
columnDefinition.accept(this);
}
}
5 changes: 5 additions & 0 deletions src/main/java/net/sf/jsqlparser/expression/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public void setName(String string) {
nameparts = Arrays.asList(string);
}

public Function withName(String name) {
this.setName(name);
return this;
}

public void setName(List<String> string) {
nameparts = string;
}
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/net/sf/jsqlparser/expression/RowConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@
*/
package net.sf.jsqlparser.expression;

import java.util.ArrayList;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;

public class RowConstructor extends ASTNodeAccessImpl implements Expression {

private ExpressionList exprList;
private ArrayList<ColumnDefinition> columnDefinitions = new ArrayList<>();
private String name = null;

public RowConstructor() {
}

public ArrayList<ColumnDefinition> getColumnDefinitions() {
return columnDefinitions;
}

public boolean addColumnDefinition(ColumnDefinition columnDefinition) {
return columnDefinitions.add(columnDefinition);
}

public ExpressionList getExprList() {
return exprList;
Expand All @@ -43,6 +53,17 @@ public void accept(ExpressionVisitor expressionVisitor) {

@Override
public String toString() {
if (columnDefinitions.size()>0) {
StringBuilder builder = new StringBuilder(name != null ? name : "");
builder.append("(");
int i = 0;
for (ColumnDefinition columnDefinition:columnDefinitions) {
builder.append(i>0 ? ", " : "").append(columnDefinition.toString());
i++;
}
builder.append(")");
return builder.toString();
}
return (name != null ? name : "") + exprList.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
import java.util.Optional;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;
import net.sf.jsqlparser.expression.JdbcNamedParameter;
import net.sf.jsqlparser.expression.JdbcParameter;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
import net.sf.jsqlparser.schema.Column;

public class FullTextSearch extends ASTNodeAccessImpl implements Expression {

private List<Column> _matchColumns;
private StringValue _againstValue;
private Expression _againstValue;
private String _searchModifier;

public FullTextSearch() {
Expand All @@ -42,8 +44,16 @@ public List<Column> getMatchColumns() {
public void setAgainstValue(StringValue val) {
this._againstValue = val;
}

public void setAgainstValue(JdbcNamedParameter val) {
this._againstValue = val;
}

public void setAgainstValue(JdbcParameter val) {
this._againstValue = val;
}

public StringValue getAgainstValue() {
public Expression getAgainstValue() {
return this._againstValue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static Expression parseExpression(String expression, boolean allowPartial
consumer.accept(parser);
}
try {
Expression expr = parser.SimpleExpression();
Expression expr = parser.Expression();
if (!allowPartialParse && parser.getNextToken().kind != CCJSqlParserTokenManager.EOF) {
throw new JSQLParserException("could only parse partial expression " + expr.toString());
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/PurgeObjectType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/
package net.sf.jsqlparser.statement;

/**
*
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
*/
public enum PurgeObjectType {
TABLE, INDEX, RECYCLEBIN, DBA_RECYCLEBIN, TABLESPACE;
}
103 changes: 103 additions & 0 deletions src/main/java/net/sf/jsqlparser/statement/PurgeStatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*-
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2021 JSQLParser
* %%
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
* #L%
*/

package net.sf.jsqlparser.statement;

import java.util.Objects;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.create.table.Index;

/**
*
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
* @see <a href="https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9018.htm">Purge</a>
*/

public class PurgeStatement implements Statement {
private final PurgeObjectType purgeObjectType;
private final Object object;
private String userName;

public PurgeStatement(Table table) {
this.purgeObjectType = PurgeObjectType.TABLE;
this.object = Objects.requireNonNull(table, "The TABLE of the PURGE TABLE statement must not be null.");
}

public PurgeStatement(Index index) {
this.purgeObjectType = PurgeObjectType.INDEX;
this.object = Objects.requireNonNull(index, "The INDEX of the PURGE INDEX statement must not be null.");
}

public PurgeStatement(PurgeObjectType purgeObjectType) {
this.purgeObjectType = purgeObjectType;
this.object = null;
}

public PurgeStatement(PurgeObjectType purgeObjectType, String tableSpaceName, String userName) {
this.purgeObjectType = purgeObjectType;
this.object = Objects.requireNonNull(tableSpaceName, "The TABLESPACE NAME of the PURGE TABLESPACE statement must not be null.");
this.userName = userName;
}

@Override
public void accept(StatementVisitor statementVisitor) {
statementVisitor.visit(this);
}

@SuppressWarnings({"PMD.MissingBreakInSwitch", "PMD.SwitchStmtsShouldHaveDefault", "PMD.CyclomaticComplexity"})
public StringBuilder appendTo(StringBuilder builder) {
builder.append("PURGE ");

switch (purgeObjectType) {
case RECYCLEBIN:
case DBA_RECYCLEBIN:
builder.append(purgeObjectType);
break;
case TABLE:
case INDEX:
builder.append(purgeObjectType);
if (object!=null) {
builder.append(" ").append(object);
}
break;
case TABLESPACE:
builder.append(purgeObjectType);
if (object!=null) {
builder.append(" ").append(object);
}
if (userName!=null && userName.length()>0) {
builder.append(" USER ").append(userName);
}
break;
}
return builder;
}

@Override
public String toString() {
return appendTo(new StringBuilder()).toString();
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public PurgeObjectType getPurgeObjectType() {
return purgeObjectType;
}

public Object getObject() {
return object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.alter.AlterSession;
import net.sf.jsqlparser.statement.alter.RenameTableStatement;
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
import net.sf.jsqlparser.statement.comment.Comment;
import net.sf.jsqlparser.statement.create.index.CreateIndex;
Expand Down Expand Up @@ -113,4 +114,7 @@ public interface StatementVisitor {
void visit(AlterSession alterSession);

void visit(IfElseStatement aThis);
void visit(RenameTableStatement renameTableStatement);

void visit(PurgeStatement purgeStatement);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.alter.AlterSession;
import net.sf.jsqlparser.statement.alter.RenameTableStatement;
import net.sf.jsqlparser.statement.alter.sequence.AlterSequence;
import net.sf.jsqlparser.statement.comment.Comment;
import net.sf.jsqlparser.statement.create.index.CreateIndex;
Expand Down Expand Up @@ -213,6 +214,19 @@ public void visit(AlterSession alterSession) {

@Override
public void visit(IfElseStatement ifElseStatement) {
ifElseStatement.getIfStatement().accept(this);
if (ifElseStatement.getElseStatement()!=null) {
ifElseStatement.getElseStatement().accept(this);
}
}

@Override
public void visit(RenameTableStatement renameTableStatement) {
//@todo: do something usefull here
}

@Override
public void visit(PurgeStatement purgeStatement) {
//@todo: do something usefull here
}
}

0 comments on commit ec4fff3

Please sign in to comment.