Skip to content

Commit e4a91cd

Browse files
authored
Merge branch 'master' into add_support_for_logical_operators
2 parents b59b48e + b76e639 commit e4a91cd

File tree

12 files changed

+320
-93
lines changed

12 files changed

+320
-93
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ JSqlParser is dual licensed under **LGPL V2.1** and **Apache Software License, V
1717

1818

1919
## News
20+
* Changed behaviour of dotted multipart names for user variables, tables and columns to accept e.g. ORM class names. To achieve this some behaviour of name parsing had to be changed. Before this the parser would fail missing databasenames for SqlServer queries (server..schema.table). But this is allowed for the schema (server.database..table). Now the parser accepts missing inner names per se to avoid some very complicated parsing rules.
2021
* Released version **1.2** of JSqlParser
2122
* breaking **API** change: merge of *within group* and *over* (window expressions)
2223
* Released version **1.1** of JSqlParser.
@@ -47,6 +48,11 @@ Also I would like to know about needed examples or documentation stuff.
4748

4849
## Extensions in the latest SNAPSHOT version 1.3
4950

51+
* introduced dotted multipart names for uservariables (issue #608)
52+
* changed behaviour of dotted multipart names for tables and columns to accept ORM class names (issue #163)
53+
** the parser allows now empty inner names, to still accept missing schema names for SQLServer (db..col)
54+
** methods like **getDatabase** will still work but have no sense using it for classnames
55+
* named parameter for **OFFSET** (issue #612)
5056
* corrected ISNULL regression (issue #610)
5157
* refactored statement test classes to the class corresponding packages
5258
* allowed nested postgresql casts (e.g. col::bigint::int)

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

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import java.util.List;
2828
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
29-
import net.sf.jsqlparser.statement.select.PlainSelect;
3029

3130
/**
3231
* Analytic function. The name of the function is variable but the parameters following the special
@@ -38,14 +37,13 @@
3837
*/
3938
public class AnalyticExpression extends ASTNodeAccessImpl implements Expression {
4039

41-
private ExpressionList partitionExpressionList;
42-
private List<OrderByElement> orderByElements;
40+
private final OrderByClause orderBy = new OrderByClause();
41+
private final PartitionByClause partitionBy = new PartitionByClause();
4342
private String name;
4443
private Expression expression;
4544
private Expression offset;
4645
private Expression defaultValue;
4746
private boolean allColumns = false;
48-
private WindowElement windowElement;
4947
private KeepExpression keep = null;
5048
private AnalyticType type = AnalyticType.OVER;
5149
private boolean distinct = false;
@@ -56,11 +54,11 @@ public void accept(ExpressionVisitor expressionVisitor) {
5654
}
5755

5856
public List<OrderByElement> getOrderByElements() {
59-
return orderByElements;
57+
return orderBy.getOrderByElements();
6058
}
6159

6260
public void setOrderByElements(List<OrderByElement> orderByElements) {
63-
this.orderByElements = orderByElements;
61+
orderBy.setOrderByElements(orderByElements);
6462
}
6563

6664
public KeepExpression getKeep() {
@@ -72,11 +70,11 @@ public void setKeep(KeepExpression keep) {
7270
}
7371

7472
public ExpressionList getPartitionExpressionList() {
75-
return partitionExpressionList;
73+
return partitionBy.getPartitionExpressionList();
7674
}
7775

7876
public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
79-
this.partitionExpressionList = partitionExpressionList;
77+
partitionBy.setPartitionExpressionList(partitionExpressionList);
8078
}
8179

8280
public String getName() {
@@ -112,11 +110,11 @@ public void setDefaultValue(Expression defaultValue) {
112110
}
113111

114112
public WindowElement getWindowElement() {
115-
return windowElement;
113+
return orderBy.getWindowElement();
116114
}
117115

118116
public void setWindowElement(WindowElement windowElement) {
119-
this.windowElement = windowElement;
117+
orderBy.setWindowElement(windowElement);
120118
}
121119

122120
public AnalyticType getType() {
@@ -168,8 +166,8 @@ public String toString() {
168166
}
169167
b.append(" (");
170168

171-
toStringPartitionBy(b);
172-
toStringOrderByElements(b);
169+
partitionBy.toStringPartitionBy(b);
170+
orderBy.toStringOrderByElements(b);
173171

174172
b.append(")");
175173

@@ -184,29 +182,4 @@ public void setAllColumns(boolean allColumns) {
184182
this.allColumns = allColumns;
185183
}
186184

187-
private void toStringPartitionBy(StringBuilder b) {
188-
if (partitionExpressionList != null && !partitionExpressionList.getExpressions().isEmpty()) {
189-
b.append("PARTITION BY ");
190-
b.append(PlainSelect.
191-
getStringList(partitionExpressionList.getExpressions(), true, false));
192-
b.append(" ");
193-
}
194-
}
195-
196-
private void toStringOrderByElements(StringBuilder b) {
197-
if (orderByElements != null && !orderByElements.isEmpty()) {
198-
b.append("ORDER BY ");
199-
for (int i = 0; i < orderByElements.size(); i++) {
200-
if (i > 0) {
201-
b.append(", ");
202-
}
203-
b.append(orderByElements.get(i).toString());
204-
}
205-
206-
if (windowElement != null) {
207-
b.append(' ');
208-
b.append(windowElement);
209-
}
210-
}
211-
}
212185
}

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ public class JdbcNamedParameter extends ASTNodeAccessImpl implements Expression
3131

3232
private String name;
3333

34-
/**
35-
* The name of the parameter
36-
*
37-
* @return the name of the parameter
38-
*/
34+
public JdbcNamedParameter() {
35+
}
36+
37+
public JdbcNamedParameter(String name) {
38+
this.name = name;
39+
}
40+
3941
public String getName() {
4042
return name;
4143
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2018 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.statement.select.OrderByElement;
25+
26+
import java.util.List;
27+
28+
public class OrderByClause {
29+
private List<OrderByElement> orderByElements;
30+
private WindowElement windowElement;
31+
32+
public List<OrderByElement> getOrderByElements() {
33+
return orderByElements;
34+
}
35+
36+
public void setOrderByElements(List<OrderByElement> orderByElements) {
37+
this.orderByElements = orderByElements;
38+
}
39+
40+
public WindowElement getWindowElement() {
41+
return windowElement;
42+
}
43+
44+
public void setWindowElement(WindowElement windowElement) {
45+
this.windowElement = windowElement;
46+
}
47+
48+
void toStringOrderByElements(StringBuilder b) {
49+
if (orderByElements != null && !orderByElements.isEmpty()) {
50+
b.append("ORDER BY ");
51+
for (int i = 0; i < orderByElements.size(); i++) {
52+
if (i > 0) {
53+
b.append(", ");
54+
}
55+
b.append(orderByElements.get(i).toString());
56+
}
57+
58+
if (windowElement != null) {
59+
b.append(' ');
60+
b.append(windowElement);
61+
}
62+
}
63+
}
64+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2018 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.expression.operators.relational.ExpressionList;
25+
import net.sf.jsqlparser.statement.select.PlainSelect;
26+
27+
public class PartitionByClause {
28+
ExpressionList partitionExpressionList;
29+
30+
public ExpressionList getPartitionExpressionList() {
31+
return partitionExpressionList;
32+
}
33+
34+
public void setPartitionExpressionList(ExpressionList partitionExpressionList) {
35+
this.partitionExpressionList = partitionExpressionList;
36+
}
37+
38+
void toStringPartitionBy(StringBuilder b) {
39+
if (partitionExpressionList != null && !partitionExpressionList.getExpressions().isEmpty()) {
40+
b.append("PARTITION BY ");
41+
b.append(PlainSelect.
42+
getStringList(partitionExpressionList.getExpressions(), true, false));
43+
b.append(" ");
44+
}
45+
}
46+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*/
2222
package net.sf.jsqlparser.schema;
2323

24+
import java.util.List;
2425
import net.sf.jsqlparser.expression.*;
2526
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
2627

@@ -40,6 +41,12 @@ public Column(Table table, String columnName) {
4041
setColumnName(columnName);
4142
}
4243

44+
public Column(List<String> nameParts) {
45+
this(nameParts.size() > 1
46+
? new Table(nameParts.subList(0, nameParts.size() - 1)) : null,
47+
nameParts.get(nameParts.size() - 1));
48+
}
49+
4350
public Column(String columnName) {
4451
this(null, columnName);
4552
}

0 commit comments

Comments
 (0)