Skip to content

Commit d8abd44

Browse files
committed
Merge origin/master
2 parents 4fed753 + 4f500a4 commit d8abd44

File tree

19 files changed

+451
-422
lines changed

19 files changed

+451
-422
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Also I would like to know about needed examples or documentation stuff.
6060

6161
## Extensions in the latest SNAPSHOT version 2.1
6262

63+
* introduces Statement streaming support by **CCJSqlParserUtil.streamStatements**
64+
* improved nested bracket parsing performance by a large scale
6365

6466
## Extensions of JSqlParser releases
6567

src/main/java/net/sf/jsqlparser/expression/AnalyticExpression.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
*/
1010
package net.sf.jsqlparser.expression;
1111

12-
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
13-
import net.sf.jsqlparser.statement.select.OrderByElement;
14-
1512
import java.util.List;
1613
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
14+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
15+
import net.sf.jsqlparser.statement.select.OrderByElement;
1716

1817
/**
1918
* Analytic function. The name of the function is variable but the parameters following the special
@@ -37,6 +36,32 @@ public class AnalyticExpression extends ASTNodeAccessImpl implements Expression
3736
private boolean distinct = false;
3837
private boolean ignoreNulls = false;
3938

39+
public AnalyticExpression() {
40+
}
41+
42+
public AnalyticExpression(Function function) {
43+
name = function.getName();
44+
allColumns = function.isAllColumns();
45+
distinct = function.isDistinct();
46+
47+
ExpressionList list = function.getParameters();
48+
if (list != null) {
49+
if (list.getExpressions().size() > 3) {
50+
throw new IllegalArgumentException("function object not valid to initialize analytic expression");
51+
}
52+
53+
expression = list.getExpressions().get(0);
54+
if (list.getExpressions().size() > 1) {
55+
offset = list.getExpressions().get(1);
56+
}
57+
if (list.getExpressions().size() > 2) {
58+
defaultValue = list.getExpressions().get(2);
59+
}
60+
}
61+
ignoreNulls = function.isIgnoreNulls();
62+
keep = function.getKeep();
63+
}
64+
4065
@Override
4166
public void accept(ExpressionVisitor expressionVisitor) {
4267
expressionVisitor.visit(this);

src/main/java/net/sf/jsqlparser/expression/BinaryExpression.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ public abstract class BinaryExpression extends ASTNodeAccessImpl implements Expr
1919

2020
private Expression leftExpression;
2121
private Expression rightExpression;
22-
private boolean not = false;
23-
24-
25-
22+
// private boolean not = false;
23+
2624
public BinaryExpression() {
2725
}
2826

@@ -42,23 +40,23 @@ public void setRightExpression(Expression expression) {
4240
rightExpression = expression;
4341
}
4442

45-
public void setNot() {
46-
not = true;
47-
}
48-
49-
public void removeNot() {
50-
not = false;
51-
}
52-
53-
public boolean isNot() {
54-
return not;
55-
}
56-
43+
// public void setNot() {
44+
// not = true;
45+
// }
46+
//
47+
// public void removeNot() {
48+
// not = false;
49+
// }
50+
//
51+
// public boolean isNot() {
52+
// return not;
53+
// }
5754
@Override
5855
public String toString() {
59-
return (not ? "NOT " : "") + getLeftExpression() + " " + getStringExpression() + " " + getRightExpression();
56+
return //(not ? "NOT " : "") +
57+
getLeftExpression() + " " + getStringExpression() + " " + getRightExpression();
6058
}
6159

6260
public abstract String getStringExpression();
63-
61+
6462
}

src/main/java/net/sf/jsqlparser/expression/Function.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class Function extends ASTNodeAccessImpl implements Expression {
2727
private Expression attribute;
2828
private String attributeName;
2929
private KeepExpression keep = null;
30+
private boolean ignoreNulls = false;
3031

3132
@Override
3233
public void accept(ExpressionVisitor expressionVisitor) {
@@ -49,6 +50,20 @@ public void setAllColumns(boolean b) {
4950
allColumns = b;
5051
}
5152

53+
public boolean isIgnoreNulls() {
54+
return ignoreNulls;
55+
}
56+
57+
/**
58+
* This is at the moment only necessary for AnalyticExpression initialization and not for normal
59+
* functions. Therefore there is no deparsing for it for normal functions.
60+
*
61+
* @param ignoreNulls
62+
*/
63+
public void setIgnoreNulls(boolean ignoreNulls) {
64+
this.ignoreNulls = ignoreNulls;
65+
}
66+
5267
/**
5368
* true if the function is "distinct"
5469
*

src/main/java/net/sf/jsqlparser/expression/operators/relational/LikeExpression.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515
public class LikeExpression extends BinaryExpression {
1616

17-
//private boolean not = false;
17+
private boolean not = false;
1818
private String escape = null;
1919
private boolean caseInsensitive = false;
2020

21-
// @Override
22-
// public boolean isNot() {
23-
// return not;
24-
// }
25-
//
26-
// public void setNot(boolean b) {
27-
// not = b;
28-
// }
21+
public boolean isNot() {
22+
return not;
23+
}
24+
25+
public void setNot(boolean b) {
26+
not = b;
27+
}
28+
2929
@Override
3030
public void accept(ExpressionVisitor expressionVisitor) {
3131
expressionVisitor.visit(this);
@@ -38,7 +38,7 @@ public String getStringExpression() {
3838

3939
@Override
4040
public String toString() {
41-
String retval = super.toString();
41+
String retval = getLeftExpression() + " " + (not ? "NOT " : "") + getStringExpression() + " " + getRightExpression();
4242
if (escape != null) {
4343
retval += " ESCAPE " + "'" + escape + "'";
4444
}

src/main/java/net/sf/jsqlparser/expression/operators/relational/OldOracleJoinBinaryExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public void setOldOracleJoinSyntax(int oldOracleJoinSyntax) {
2828

2929
@Override
3030
public String toString() {
31-
return (isNot() ? "NOT " : "")
32-
+ (oraclePriorPosition == ORACLE_PRIOR_START ? "PRIOR " : "")
31+
return //(isNot() ? "NOT " : "")
32+
(oraclePriorPosition == ORACLE_PRIOR_START ? "PRIOR " : "")
3333
+ getLeftExpression()
3434
+ (oldOracleJoinSyntax == ORACLE_JOIN_RIGHT ? "(+)" : "") + " "
3535
+ getStringExpression() + " "

src/main/java/net/sf/jsqlparser/parser/CCJSqlParserUtil.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static Statement parse(InputStream is, String encoding) throws JSQLParser
7070
public static Expression parseExpression(String expression) throws JSQLParserException {
7171
return parseExpression(expression, true);
7272
}
73-
73+
7474
public static Expression parseExpression(String expression, boolean allowPartialParse) throws JSQLParserException {
7575
CCJSqlParser parser = new CCJSqlParser(new StringProvider(expression));
7676
try {
@@ -124,4 +124,23 @@ public static Statements parseStatements(String sqls) throws JSQLParserException
124124
}
125125
}
126126

127+
public static void streamStatements(StatementListener listener, InputStream is, String encoding) throws JSQLParserException {
128+
try {
129+
CCJSqlParser parser = new CCJSqlParser(new StreamProvider(is, encoding));
130+
while (true) {
131+
Statement stmt = parser.SingleStatement();
132+
listener.accept(stmt);
133+
if (parser.getToken(1).kind == CCJSqlParserTokenManager.ST_SEMICOLON) {
134+
parser.getNextToken();
135+
}
136+
137+
if (parser.getToken(1).kind == CCJSqlParserTokenManager.EOF) {
138+
break;
139+
}
140+
}
141+
} catch (Exception ex) {
142+
throw new JSQLParserException(ex);
143+
}
144+
}
145+
127146
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2019 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
/*
11+
* Copyright (C) 2019 JSQLParser.
12+
*
13+
* This library is free software; you can redistribute it and/or
14+
* modify it under the terms of the GNU Lesser General Public
15+
* License as published by the Free Software Foundation; either
16+
* version 2.1 of the License, or (at your option) any later version.
17+
*
18+
* This library is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21+
* Lesser General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU Lesser General Public
24+
* License along with this library; if not, write to the Free Software
25+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26+
* MA 02110-1301 USA
27+
*/
28+
package net.sf.jsqlparser.parser;
29+
30+
import net.sf.jsqlparser.statement.Statement;
31+
32+
/**
33+
*
34+
* @author Tobias Warneke ([email protected])
35+
*/
36+
public interface StatementListener {
37+
38+
void accept(Statement statement);
39+
}

src/main/java/net/sf/jsqlparser/schema/Column.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ public Column(String columnName) {
3636
this(null, columnName);
3737
}
3838

39+
/**
40+
* Retrieve the information regarding the {@code Table} this {@code Column} does
41+
* belong to, if any can be inferred.
42+
* <p>
43+
* The inference is based only on local information, and not on the whole SQL command.
44+
* For example, consider the following query:
45+
* <blockquote><pre>
46+
* SELECT x FROM Foo
47+
* </pre></blockquote>
48+
* Given the {@code Column} called {@code x}, this method would return {@code null},
49+
* and not the info about the table {@code Foo}.
50+
* On the other hand, consider:
51+
* <blockquote><pre>
52+
* SELECT t.x FROM Foo t
53+
* </pre></blockquote>
54+
* Here, we will get a {@code Table} object for a table called {@code t}.
55+
* But because the inference is local, such object will not know that {@code t} is
56+
* just an alias for {@code Foo}.
57+
*
58+
* @return an instance of {@link net.sf.jsqlparser.schema.Table} representing the
59+
* table this column does belong to, if it can be inferred. Can be {@code null}.
60+
*/
3961
public Table getTable() {
4062
return table;
4163
}

0 commit comments

Comments
 (0)