Skip to content

Commit 21c4550

Browse files
2 parents 96808d2 + adeed53 commit 21c4550

11 files changed

Lines changed: 2624 additions & 2086 deletions

File tree

config/checkstyle/checkstyle_checks.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<property name="format" value="^ \* .+(Type|Default value|Validation type) is \{@code "/>
124124
<property name="minimum" value="0"/>
125125
<property name="maximum" value="0"/>
126-
<property name="message" value="Property attribute should be on new javadoc line"/>
126+
<property name="message" value="Property attributeExpression should be on new javadoc line"/>
127127
</module>
128128
<module name="RegexpSingleline">
129129
<property name="id" value="commentFirstSentenceSingleline"/>
@@ -410,7 +410,7 @@
410410
<property name="query" value="//METHOD_DEF/MODIFIERS//
411411
ANNOTATION[./IDENT[@text='Test']]/ANNOTATION_MEMBER_VALUE_PAIR
412412
[./IDENT[@text='expected']]"/>
413-
<message key="matchxpath.match" value="Avoid using 'expected' attribute in Test annotation."/>
413+
<message key="matchxpath.match" value="Avoid using 'expected' attributeExpression in Test annotation."/>
414414
</module>
415415
<module name="MatchXpath">
416416
<property name="query" value="//ANNOTATION[./IDENT[@text='Issue']]"/>

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

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
1515
import net.sf.jsqlparser.expression.operators.relational.NamedExpressionList;
1616
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
17+
import net.sf.jsqlparser.schema.*;
1718
import net.sf.jsqlparser.statement.select.OrderByElement;
1819
import net.sf.jsqlparser.statement.select.PlainSelect;
1920

@@ -29,8 +30,8 @@ public class Function extends ASTNodeAccessImpl implements Expression {
2930
private boolean distinct = false;
3031
private boolean unique = false;
3132
private boolean isEscaped = false;
32-
private Expression attribute;
33-
private String attributeName;
33+
private Expression attributeExpression;
34+
private Column attributeColumn = null;
3435
private List<OrderByElement> orderByElements;
3536
private KeepExpression keep = null;
3637
private boolean ignoreNulls = false;
@@ -43,20 +44,20 @@ public void accept(ExpressionVisitor expressionVisitor) {
4344
public String getName() {
4445
return nameparts == null ? null : String.join(".", nameparts);
4546
}
46-
47+
4748
public List<String> getMultipartName() {
4849
return nameparts;
4950
}
5051

5152
public void setName(String string) {
5253
nameparts = Arrays.asList(string);
5354
}
54-
55+
5556
public Function withName(String name) {
5657
this.setName(name);
5758
return this;
5859
}
59-
60+
6061
public void setName(List<String> string) {
6162
nameparts = string;
6263
}
@@ -148,20 +149,35 @@ public void setEscaped(boolean isEscaped) {
148149
this.isEscaped = isEscaped;
149150
}
150151

151-
public Expression getAttribute() {
152-
return attribute;
152+
public Object getAttribute() {
153+
return attributeExpression != null ? attributeExpression : attributeColumn;
153154
}
154155

155-
public void setAttribute(Expression attribute) {
156-
this.attribute = attribute;
156+
public void setAttribute(Expression attributeExpression) {
157+
this.attributeExpression = attributeExpression;
157158
}
158159

160+
@Deprecated
159161
public String getAttributeName() {
160-
return attributeName;
162+
return attributeColumn.toString();
161163
}
162164

163165
public void setAttributeName(String attributeName) {
164-
this.attributeName = attributeName;
166+
this.attributeColumn = new Column().withColumnName(attributeName);
167+
}
168+
169+
public Column getAttributeColumn() {
170+
return attributeColumn;
171+
}
172+
173+
public void setAttribute(Column attributeColumn) {
174+
attributeExpression = null;
175+
this.attributeColumn = attributeColumn;
176+
}
177+
178+
public Function withAttribute(Column attributeColumn) {
179+
setAttribute(attributeColumn);
180+
return this;
165181
}
166182

167183
public KeepExpression getKeep() {
@@ -213,14 +229,14 @@ public String toString() {
213229

214230
String ans = getName() + params;
215231

216-
if (attribute != null) {
217-
ans += "." + attribute.toString();
218-
} else if (attributeName != null) {
219-
ans += "." + attributeName;
232+
if (attributeExpression != null) {
233+
ans += "." + attributeExpression;
234+
} else if (attributeColumn != null) {
235+
ans += "." + attributeColumn;
220236
}
221237

222238
if (keep != null) {
223-
ans += " " + keep.toString();
239+
ans += " " + keep;
224240
}
225241

226242
if (isEscaped) {
@@ -235,6 +251,7 @@ public Function withAttribute(Expression attribute) {
235251
return this;
236252
}
237253

254+
@Deprecated
238255
public Function withAttributeName(String attributeName) {
239256
this.setAttributeName(attributeName);
240257
return this;

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

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public ExpressionDeParser(SelectVisitor selectVisitor, StringBuilder buffer) {
7777
this(selectVisitor, buffer, new OrderByDeParser());
7878
}
7979

80-
ExpressionDeParser(SelectVisitor selectVisitor, StringBuilder buffer, OrderByDeParser orderByDeParser) {
80+
ExpressionDeParser(SelectVisitor selectVisitor, StringBuilder buffer,
81+
OrderByDeParser orderByDeParser) {
8182
super(buffer);
8283
this.selectVisitor = selectVisitor;
8384
this.orderByDeParser = orderByDeParser;
@@ -157,10 +158,11 @@ public void visit(BitwiseLeftShift expr) {
157158
visitBinaryExpression(expr, " << ");
158159
}
159160

160-
public void visitOldOracleJoinBinaryExpression(OldOracleJoinBinaryExpression expression, String operator) {
161-
// if (expression.isNot()) {
162-
// buffer.append(NOT);
163-
// }
161+
public void visitOldOracleJoinBinaryExpression(OldOracleJoinBinaryExpression expression,
162+
String operator) {
163+
// if (expression.isNot()) {
164+
// buffer.append(NOT);
165+
// }
164166
expression.getLeftExpression().accept(this);
165167
if (expression.getOldOracleJoinSyntax() == EqualsTo.ORACLE_JOIN_RIGHT) {
166168
buffer.append("(+)");
@@ -186,7 +188,8 @@ public void visit(GreaterThanEquals greaterThanEquals) {
186188
@Override
187189
public void visit(InExpression inExpression) {
188190
inExpression.getLeftExpression().accept(this);
189-
if (inExpression.getOldOracleJoinSyntax() == SupportsOldOracleJoinSyntax.ORACLE_JOIN_RIGHT) {
191+
if (inExpression
192+
.getOldOracleJoinSyntax() == SupportsOldOracleJoinSyntax.ORACLE_JOIN_RIGHT) {
190193
buffer.append("(+)");
191194
}
192195
if (inExpression.isNot()) {
@@ -212,8 +215,12 @@ public void visit(FullTextSearch fullTextSearch) {
212215
columnsListCommaSeperated += ",";
213216
}
214217
}
215-
buffer.append("MATCH (" + columnsListCommaSeperated + ") AGAINST (" + fullTextSearch.getAgainstValue()
216-
+ (fullTextSearch.getSearchModifier() != null ? " " + fullTextSearch.getSearchModifier() : "") + ")");
218+
buffer.append("MATCH (" + columnsListCommaSeperated + ") AGAINST ("
219+
+ fullTextSearch.getAgainstValue()
220+
+ (fullTextSearch.getSearchModifier() != null
221+
? " " + fullTextSearch.getSearchModifier()
222+
: "")
223+
+ ")");
217224
}
218225

219226
@Override
@@ -269,8 +276,8 @@ public void visit(JdbcParameter jdbcParameter) {
269276

270277
@Override
271278
public void visit(LikeExpression likeExpression) {
272-
visitBinaryExpression(likeExpression,
273-
(likeExpression.isNot() ? " NOT" : "") + (likeExpression.isCaseInsensitive() ? " ILIKE " : " LIKE "));
279+
visitBinaryExpression(likeExpression, (likeExpression.isNot() ? " NOT" : "")
280+
+ (likeExpression.isCaseInsensitive() ? " ILIKE " : " LIKE "));
274281
Expression escape = likeExpression.getEscape();
275282
if (escape != null) {
276283
buffer.append(" ESCAPE ");
@@ -314,7 +321,8 @@ public void visit(Multiplication multiplication) {
314321

315322
@Override
316323
public void visit(NotEqualsTo notEqualsTo) {
317-
visitOldOracleJoinBinaryExpression(notEqualsTo, " " + notEqualsTo.getStringExpression() + " ");
324+
visitOldOracleJoinBinaryExpression(notEqualsTo,
325+
" " + notEqualsTo.getStringExpression() + " ");
318326

319327
}
320328

@@ -372,7 +380,8 @@ public void visit(SubSelect subSelect) {
372380
if (selectVisitor != null) {
373381
if (subSelect.getWithItemsList() != null) {
374382
buffer.append("WITH ");
375-
for (Iterator<WithItem> iter = subSelect.getWithItemsList().iterator(); iter.hasNext();) {
383+
for (Iterator<WithItem> iter = subSelect.getWithItemsList().iterator(); iter
384+
.hasNext();) {
376385
iter.next().accept(selectVisitor);
377386
if (iter.hasNext()) {
378387
buffer.append(", ");
@@ -451,8 +460,6 @@ public void visit(Function function) {
451460

452461
if (function.getAttribute() != null) {
453462
buffer.append(".").append(function.getAttribute());
454-
} else if (function.getAttributeName() != null) {
455-
buffer.append(".").append(function.getAttributeName());
456463
}
457464
if (function.getKeep() != null) {
458465
buffer.append(" ").append(function.getKeep());
@@ -465,7 +472,8 @@ public void visit(Function function) {
465472

466473
@Override
467474
public void visit(ExpressionList expressionList) {
468-
new ExpressionListDeParser(this, buffer, expressionList.isUsingBrackets(), true).deParse(expressionList.getExpressions());
475+
new ExpressionListDeParser(this, buffer, expressionList.isUsingBrackets(), true)
476+
.deParse(expressionList.getExpressions());
469477
}
470478

471479
@Override
@@ -549,8 +557,8 @@ public void visit(AnyComparisonExpression anyComparisonExpression) {
549557
} else {
550558
ExpressionList expressionList = (ExpressionList) anyComparisonExpression.getItemsList();
551559
buffer.append("VALUES ");
552-
buffer.append(
553-
PlainSelect.getStringList(expressionList.getExpressions(), true, anyComparisonExpression.isUsingBracketsForValues()));
560+
buffer.append(PlainSelect.getStringList(expressionList.getExpressions(), true,
561+
anyComparisonExpression.isUsingBracketsForValues()));
554562
}
555563
buffer.append(" ) ");
556564
}
@@ -586,7 +594,8 @@ public void visit(CastExpression cast) {
586594
buffer.append("CAST(");
587595
cast.getLeftExpression().accept(this);
588596
buffer.append(" AS ");
589-
buffer.append(cast.getRowConstructor() != null ? cast.getRowConstructor() : cast.getType());
597+
buffer.append(
598+
cast.getRowConstructor() != null ? cast.getRowConstructor() : cast.getType());
590599
buffer.append(")");
591600
} else {
592601
cast.getLeftExpression().accept(this);
@@ -601,7 +610,8 @@ public void visit(TryCastExpression cast) {
601610
buffer.append("TRY_CAST(");
602611
cast.getLeftExpression().accept(this);
603612
buffer.append(" AS ");
604-
buffer.append(cast.getRowConstructor() != null ? cast.getRowConstructor() : cast.getType());
613+
buffer.append(
614+
cast.getRowConstructor() != null ? cast.getRowConstructor() : cast.getType());
605615
buffer.append(")");
606616
} else {
607617
cast.getLeftExpression().accept(this);
@@ -616,7 +626,8 @@ public void visit(SafeCastExpression cast) {
616626
buffer.append("SAFE_CAST(");
617627
cast.getLeftExpression().accept(this);
618628
buffer.append(" AS ");
619-
buffer.append(cast.getRowConstructor() != null ? cast.getRowConstructor() : cast.getType());
629+
buffer.append(
630+
cast.getRowConstructor() != null ? cast.getRowConstructor() : cast.getType());
620631
buffer.append(")");
621632
} else {
622633
cast.getLeftExpression().accept(this);
@@ -632,7 +643,8 @@ public void visit(Modulo modulo) {
632643
}
633644

634645
@Override
635-
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.ExcessiveMethodLength", "PMD.MissingBreakInSwitch"})
646+
@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.ExcessiveMethodLength",
647+
"PMD.MissingBreakInSwitch"})
636648
public void visit(AnalyticExpression aexpr) {
637649
String name = aexpr.getName();
638650
Expression expression = aexpr.getExpression();
@@ -669,7 +681,8 @@ public void visit(AnalyticExpression aexpr) {
669681
}
670682
if (aexpr.getFuncOrderBy() != null) {
671683
buffer.append(" ORDER BY ");
672-
buffer.append(aexpr.getFuncOrderBy().stream().map(OrderByElement::toString).collect(joining(", ")));
684+
buffer.append(aexpr.getFuncOrderBy().stream().map(OrderByElement::toString)
685+
.collect(joining(", ")));
673686
}
674687

675688
buffer.append(") ");
@@ -710,10 +723,11 @@ public void visit(AnalyticExpression aexpr) {
710723

711724
if (aexpr.getWindowName() != null) {
712725
buffer.append(" ").append(aexpr.getWindowName());
713-
} else if (aexpr.getType()!=AnalyticType.WITHIN_GROUP_OVER) {
726+
} else if (aexpr.getType() != AnalyticType.WITHIN_GROUP_OVER) {
714727
buffer.append(" (");
715728

716-
if (partitionExpressionList != null && !partitionExpressionList.getExpressions().isEmpty()) {
729+
if (partitionExpressionList != null
730+
&& !partitionExpressionList.getExpressions().isEmpty()) {
717731
buffer.append("PARTITION BY ");
718732
if (aexpr.isPartitionByBrackets()) {
719733
buffer.append("(");
@@ -884,12 +898,14 @@ public void visit(DateTimeLiteralExpression literal) {
884898

885899
@Override
886900
public void visit(NextValExpression nextVal) {
887-
buffer.append(nextVal.isUsingNextValueFor() ? "NEXT VALUE FOR " : "NEXTVAL FOR ").append(nextVal.getName());
901+
buffer.append(nextVal.isUsingNextValueFor() ? "NEXT VALUE FOR " : "NEXTVAL FOR ")
902+
.append(nextVal.getName());
888903
}
889904

890905
@Override
891906
public void visit(CollateExpression col) {
892-
buffer.append(col.getLeftExpression().toString()).append(" COLLATE ").append(col.getCollate());
907+
buffer.append(col.getLeftExpression().toString()).append(" COLLATE ")
908+
.append(col.getCollate());
893909
}
894910

895911
@Override
@@ -948,7 +964,7 @@ public void visit(VariableAssignment var) {
948964

949965
@Override
950966
public void visit(XMLSerializeExpr expr) {
951-
//xmlserialize(xmlagg(xmltext(COMMENT_LINE) ORDER BY COMMENT_SEQUENCE) as varchar(1024))
967+
// xmlserialize(xmlagg(xmltext(COMMENT_LINE) ORDER BY COMMENT_SEQUENCE) as varchar(1024))
952968
buffer.append("xmlserialize(xmlagg(xmltext(");
953969
expr.getExpression().accept(this);
954970
buffer.append(")");
@@ -992,9 +1008,7 @@ public void visit(ConnectByRootOperator connectByRootOperator) {
9921008

9931009
@Override
9941010
public void visit(OracleNamedFunctionParameter oracleNamedFunctionParameter) {
995-
buffer
996-
.append(oracleNamedFunctionParameter.getName())
997-
.append(" => ");
1011+
buffer.append(oracleNamedFunctionParameter.getName()).append(" => ");
9981012

9991013
oracleNamedFunctionParameter.getExpression().accept(this);
10001014
}
@@ -1023,6 +1037,7 @@ public void visit(IsDistinctExpression isDistinctExpression) {
10231037

10241038
@Override
10251039
public void visit(GeometryDistance geometryDistance) {
1026-
visitOldOracleJoinBinaryExpression(geometryDistance, " " + geometryDistance.getStringExpression() + " ");
1040+
visitOldOracleJoinBinaryExpression(geometryDistance,
1041+
" " + geometryDistance.getStringExpression() + " ");
10271042
}
10281043
}

0 commit comments

Comments
 (0)