Skip to content

Commit

Permalink
Merge branch 'master' into TSQLNextValueFor
Browse files Browse the repository at this point in the history
  • Loading branch information
wumpz committed Jun 2, 2021
2 parents c8d0ebb + 537649b commit 8839943
Show file tree
Hide file tree
Showing 54 changed files with 991 additions and 149 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ Also I would like to know about needed examples or documentation stuff.

## Extensions in the latest SNAPSHOT version 4.1

* support for **with** (ctl) for **delete**, **update** and **merge**
* introduce a max depth to allow parsing complex expression lists without performance loss (thx to @manticore-projects)
* allow all functions to have complex expressions as parameters (thx to @manticore-projects)
** API change FunctionWithCondParams production removed
* API change in ValuesStatement: the expression list is now hold as a ItemList and not as a List<Expression>
* support for parser modification within **parseExpression** and **parseCondExpression**
' support for table schema for foreign keys
* support for table schema for foreign keys
* support for Oracle hints on **insert, update and merge**
* support for **merge insert where** clause
* allow **in** as schema name
Expand Down
337 changes: 337 additions & 0 deletions eclipse-java-google-style.xml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion nb-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<org-netbeans-modules-javascript2-requirejs.enabled>true</org-netbeans-modules-javascript2-requirejs.enabled>
<netbeans.hint.jdkPlatform>JDK_1.8</netbeans.hint.jdkPlatform>
<org-netbeans-modules-editor-indent.text.xml.CodeStyle.project.expand-tabs>false</org-netbeans-modules-editor-indent.text.xml.CodeStyle.project.expand-tabs>
<org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.enable-indent>true</org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.enable-indent>
<org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap>none</org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap>
<org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width>4</org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width>
<org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab>4</org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab>
Expand Down
4 changes: 3 additions & 1 deletion pmd-rules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,7 @@ under the License.

<rule ref="category/java/performance.xml/BigIntegerInstantiation" />
<rule ref="category/java/performance.xml/BooleanInstantiation" />


<!-- for Codazy -->
<rule ref="category/java/documentation.xml/UncommentedEmptyMethodBody" />
</ruleset>
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,13 @@
<artifactId>javacc-maven-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>config/sun_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void setIgnoreNulls(boolean ignoreNulls) {
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.ExcessiveMethodLength"})
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {
StringBuilder b = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.sf.jsqlparser.expression.operators.arithmetic.*;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
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.select.SubSelect;
Expand Down Expand Up @@ -62,6 +63,8 @@ public interface ExpressionVisitor {

void visit(OrExpression orExpression);

void visit(XorExpression orExpression);

void visit(Between between);

void visit(EqualsTo equalsTo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.sf.jsqlparser.expression.operators.arithmetic.*;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
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.select.AllColumns;
Expand All @@ -29,7 +30,7 @@
import net.sf.jsqlparser.statement.select.UnPivot;
import net.sf.jsqlparser.statement.select.WithItem;

@SuppressWarnings({"PMD.CyclomaticComplexity"})
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.UncommentedEmptyMethodBody"})
public class ExpressionVisitorAdapter implements ExpressionVisitor, ItemsListVisitor, PivotVisitor, SelectItemVisitor {

private SelectVisitor selectVisitor;
Expand Down Expand Up @@ -147,6 +148,11 @@ public void visit(OrExpression expr) {
visitBinaryExpression(expr);
}

@Override
public void visit(XorExpression expr) {
visitBinaryExpression(expr);
}

@Override
public void visit(Between expr) {
expr.getLeftExpression().accept(this);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/sf/jsqlparser/expression/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void setKeep(KeepExpression keep) {
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity"})
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {
String params;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*-
* #%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.expression.operators.conditional;

import net.sf.jsqlparser.expression.BinaryExpression;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitor;

public class XorExpression extends BinaryExpression {

public XorExpression() {
// nothing
}

public XorExpression(Expression leftExpression, Expression rightExpression) {
setLeftExpression(leftExpression);
setRightExpression(rightExpression);
}

@Override
public XorExpression withLeftExpression(Expression expression) {
return (XorExpression) super.withLeftExpression(expression);
}

@Override
public XorExpression withRightExpression(Expression expression) {
return (XorExpression) super.withRightExpression(expression);
}

@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}

@Override
public String getStringExpression() {
return "XOR";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import net.sf.jsqlparser.statement.select.SubSelect;

@SuppressWarnings({"PMD.UncommentedEmptyMethodBody"})
public class ItemsListVisitorAdapter implements ItemsListVisitor {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.sf.jsqlparser.statement.upsert.Upsert;
import net.sf.jsqlparser.statement.values.ValuesStatement;

@SuppressWarnings({"PMD.UncommentedEmptyMethodBody"})
public class StatementVisitorAdapter implements StatementVisitor {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public void setUk(boolean uk) {
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity"})
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {

StringBuilder b = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void setRowMovement(RowMovement rowMovement) {
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity"})
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {
String sql;
String createOps = PlainSelect.getStringList(createOptionsStrings, false, false);
Expand Down
43 changes: 42 additions & 1 deletion src/main/java/net/sf/jsqlparser/statement/delete/Delete.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import static java.util.stream.Collectors.joining;
Expand All @@ -24,16 +25,42 @@
import net.sf.jsqlparser.statement.select.Limit;
import net.sf.jsqlparser.statement.select.OrderByElement;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.WithItem;

public class Delete implements Statement {

private List<WithItem> withItemsList;
private Table table;
private OracleHint oracleHint = null;
private List<Table> tables;
private List<Join> joins;
private Expression where;
private Limit limit;
private List<OrderByElement> orderByElements;
public List<WithItem> getWithItemsList() {
return withItemsList;
}

public void setWithItemsList(List<WithItem> withItemsList) {
this.withItemsList = withItemsList;
}

public Delete withWithItemsList(List<WithItem> withItemsList) {
this.setWithItemsList(withItemsList);
return this;
}

public Delete addWithItemsList(WithItem... withItemsList) {
List<WithItem> collection = Optional.ofNullable(getWithItemsList()).orElseGet(ArrayList::new);
Collections.addAll(collection, withItemsList);
return this.withWithItemsList(collection);
}

public Delete addWithItemsList(Collection<? extends WithItem> withItemsList) {
List<WithItem> collection = Optional.ofNullable(getWithItemsList()).orElseGet(ArrayList::new);
collection.addAll(withItemsList);
return this.withWithItemsList(collection);
}

public List<OrderByElement> getOrderByElements() {
return orderByElements;
Expand Down Expand Up @@ -97,8 +124,22 @@ public void setJoins(List<Join> joins) {
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {
StringBuilder b = new StringBuilder("DELETE");
StringBuilder b = new StringBuilder();
if (withItemsList != null && !withItemsList.isEmpty()) {
b.append("WITH ");
for (Iterator<WithItem> iter = withItemsList.iterator(); iter.hasNext();) {
WithItem withItem = iter.next();
b.append(withItem);
if (iter.hasNext()) {
b.append(",");
}
b.append(" ");
}
}

b.append("DELETE");

if (tables != null && tables.size() > 0) {
b.append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public void setWithItemsList(List<WithItem> withItemsList) {
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity"})
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {
StringBuilder sql = new StringBuilder();
if (withItemsList != null && !withItemsList.isEmpty()) {
Expand Down
51 changes: 48 additions & 3 deletions src/main/java/net/sf/jsqlparser/statement/merge/Merge.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@
*/
package net.sf.jsqlparser.statement.merge;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import net.sf.jsqlparser.expression.Alias;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.OracleHint;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.StatementVisitor;
import net.sf.jsqlparser.statement.select.SubSelect;
import net.sf.jsqlparser.statement.select.WithItem;

public class Merge implements Statement {

private List<WithItem> withItemsList;
private Table table;
private OracleHint oracleHint = null;
private Table usingTable;
Expand All @@ -29,14 +37,39 @@ public class Merge implements Statement {
private MergeUpdate mergeUpdate;
private boolean insertFirst = false;

public List<WithItem> getWithItemsList() {
return withItemsList;
}

public void setWithItemsList(List<WithItem> withItemsList) {
this.withItemsList = withItemsList;
}

public Merge withWithItemsList(List<WithItem> withItemsList) {
this.setWithItemsList(withItemsList);
return this;
}

public Merge addWithItemsList(WithItem... withItemsList) {
List<WithItem> collection = Optional.ofNullable(getWithItemsList()).orElseGet(ArrayList::new);
Collections.addAll(collection, withItemsList);
return this.withWithItemsList(collection);
}

public Merge addWithItemsList(Collection<? extends WithItem> withItemsList) {
List<WithItem> collection = Optional.ofNullable(getWithItemsList()).orElseGet(ArrayList::new);
collection.addAll(withItemsList);
return this.withWithItemsList(collection);
}

public Table getTable() {
return table;
}

public void setTable(Table name) {
table = name;
}

public OracleHint getOracleHint() {
return oracleHint;
}
Expand Down Expand Up @@ -110,8 +143,20 @@ public void setInsertFirst(boolean insertFirst) {
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.NPathComplexity"})
public String toString() {
StringBuilder b = new StringBuilder();
if (withItemsList != null && !withItemsList.isEmpty()) {
b.append("WITH ");
for (Iterator<WithItem> iter = withItemsList.iterator(); iter.hasNext();) {
WithItem withItem = iter.next();
b.append(withItem);
if (iter.hasNext()) {
b.append(",");
}
b.append(" ");
}
}
b.append("MERGE INTO ");
b.append(table);
b.append(" USING ");
Expand All @@ -129,15 +174,15 @@ public String toString() {
b.append(")");

if (insertFirst && mergeInsert != null) {
b.append(mergeInsert.toString());
b.append(mergeInsert.toString());
}

if (mergeUpdate != null) {
b.append(mergeUpdate.toString());
}

if (!insertFirst && mergeInsert != null) {
b.append(mergeInsert.toString());
b.append(mergeInsert.toString());
}

return b.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import net.sf.jsqlparser.schema.Table;

@SuppressWarnings({"PMD.UncommentedEmptyMethodBody"})
public class FromItemVisitorAdapter implements FromItemVisitor {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void addGroupingSet(ExpressionList list) {
}

@Override
@SuppressWarnings({"PMD.CyclomaticComplexity"})
public String toString() {
StringBuilder b = new StringBuilder();
b.append("GROUP BY ");
Expand Down

0 comments on commit 8839943

Please sign in to comment.