Skip to content

Commit 1d4eb9e

Browse files
Merge branch 'master' into Keywords
2 parents 0c6f0e4 + 15ff843 commit 1d4eb9e

13 files changed

Lines changed: 255 additions & 31 deletions

File tree

build.gradle

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group = 'com.github.jsqlparser'
15-
version = '4.5-SNAPSHOT'
15+
version = '4.6-SNAPSHOT'
1616
description = 'JSQLParser library'
1717
java.sourceCompatibility = JavaVersion.VERSION_1_8
1818

@@ -42,11 +42,8 @@ dependencies {
4242
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.+'
4343

4444
// https://mvnrepository.com/artifact/org.mockito/mockito-junit-jupiter
45-
testImplementation 'org.mockito:mockito-junit-jupiter:4.5.1'
46-
47-
implementation 'net.java.dev.javacc:javacc:7.0.11'
48-
49-
testImplementation "org.junit.jupiter:junit-jupiter-params:5.+"
45+
testImplementation 'org.mockito:mockito-junit-jupiter:4.+'
46+
testImplementation 'org.junit.jupiter:junit-jupiter-params:+'
5047

5148
// enforce latest version of JavaCC
5249
javacc 'net.java.dev.javacc:javacc:7.0.12'

pom.xml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<dependency>
3636
<groupId>commons-io</groupId>
3737
<artifactId>commons-io</artifactId>
38-
<version>2.7</version>
38+
<version>2.11.0</version>
3939
<scope>test</scope>
4040
</dependency>
4141
<dependency>
@@ -47,31 +47,31 @@
4747
<dependency>
4848
<groupId>org.mockito</groupId>
4949
<artifactId>mockito-core</artifactId>
50-
<version>3.12.4</version>
50+
<version>4.7.0</version>
5151
<scope>test</scope>
5252
</dependency>
5353
<dependency>
5454
<groupId>org.mockito</groupId>
5555
<artifactId>mockito-junit-jupiter</artifactId>
56-
<version>3.12.4</version>
56+
<version>4.8.0</version>
5757
<scope>test</scope>
5858
</dependency>
5959
<dependency>
6060
<groupId>org.assertj</groupId>
6161
<artifactId>assertj-core</artifactId>
62-
<version>3.16.1</version>
62+
<version>3.23.1</version>
6363
<scope>test</scope>
6464
</dependency>
6565
<dependency>
6666
<groupId>org.apache.commons</groupId>
6767
<artifactId>commons-lang3</artifactId>
68-
<version>3.10</version>
68+
<version>3.12.0</version>
6969
<scope>test</scope>
7070
</dependency>
7171
<dependency>
7272
<groupId>com.h2database</groupId>
7373
<artifactId>h2</artifactId>
74-
<version>1.4.200</version>
74+
<version>2.1.210</version>
7575
<scope>test</scope>
7676
</dependency>
7777
<dependency>
@@ -189,7 +189,7 @@
189189
</plugin>
190190
<plugin>
191191
<artifactId>maven-compiler-plugin</artifactId>
192-
<version>3.7.0</version>
192+
<version>3.10.1</version>
193193
<configuration>
194194
<source>1.8</source>
195195
<target>1.8</target>
@@ -233,15 +233,15 @@
233233
<plugin>
234234
<groupId>org.apache.maven.plugins</groupId>
235235
<artifactId>maven-resources-plugin</artifactId>
236-
<version>2.6</version>
236+
<version>3.3.0</version>
237237
<configuration>
238238
<encoding>${project.build.sourceEncoding}</encoding>
239239
</configuration>
240240
</plugin>
241241
<plugin>
242242
<groupId>org.codehaus.mojo</groupId>
243243
<artifactId>license-maven-plugin</artifactId>
244-
<version>1.17</version>
244+
<version>2.0.0</version>
245245
<configuration>
246246
<verbose>false</verbose>
247247
<addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
@@ -262,7 +262,7 @@
262262
<plugin>
263263
<groupId>org.apache.maven.plugins</groupId>
264264
<artifactId>maven-release-plugin</artifactId>
265-
<version>2.5.3</version>
265+
<version>3.0.0-M6</version>
266266
<configuration>
267267
<localCheckout>true</localCheckout>
268268
<pushChanges>false</pushChanges>
@@ -292,7 +292,7 @@
292292
<plugin>
293293
<groupId>org.apache.maven.plugins</groupId>
294294
<artifactId>maven-javadoc-plugin</artifactId>
295-
<version>3.1.1</version>
295+
<version>3.4.1</version>
296296
<executions>
297297
<execution>
298298
<id>attach-javadocs</id>
@@ -308,7 +308,7 @@
308308
</plugin>
309309
<plugin>
310310
<artifactId>maven-site-plugin</artifactId>
311-
<version>3.7.1</version>
311+
<version>3.12.1</version>
312312
<executions>
313313
<execution>
314314
<id>attach-descriptor</id>
@@ -324,7 +324,7 @@
324324
<plugin>
325325
<groupId>org.eluder.coveralls</groupId>
326326
<artifactId>coveralls-maven-plugin</artifactId>
327-
<version>3.1.0</version>
327+
<version>4.3.0</version>
328328
</plugin>
329329
<plugin>
330330
<groupId>org.codehaus.mojo</groupId>
@@ -343,21 +343,21 @@
343343
<plugin>
344344
<groupId>org.apache.felix</groupId>
345345
<artifactId>maven-bundle-plugin</artifactId>
346-
<version>3.0.1</version>
346+
<version>5.1.8</version>
347347
<extensions>true</extensions>
348348
</plugin>
349349
<plugin>
350350
<groupId>org.apache.maven.plugins</groupId>
351351
<artifactId>maven-surefire-plugin</artifactId>
352-
<version>3.0.0-M5</version>
352+
<version>3.0.0-M7</version>
353353
<configuration>
354354
<trimStackTrace>false</trimStackTrace>
355355
</configuration>
356356
</plugin>
357357
<plugin>
358358
<groupId>org.jacoco</groupId>
359359
<artifactId>jacoco-maven-plugin</artifactId>
360-
<version>0.8.7</version>
360+
<version>0.8.8</version>
361361
<executions>
362362
<execution>
363363
<goals>
@@ -381,15 +381,15 @@
381381
<plugin>
382382
<groupId>org.apache.maven.plugins</groupId>
383383
<artifactId>maven-surefire-report-plugin</artifactId>
384-
<version>3.0.0-M5</version>
384+
<version>3.0.0-M7</version>
385385
<configuration>
386386
<outputDirectory>${project.reporting.outputDirectory}/testresults</outputDirectory>
387387
</configuration>
388388
</plugin>
389389
<plugin>
390390
<groupId>org.apache.maven.plugins</groupId>
391391
<artifactId>maven-javadoc-plugin</artifactId>
392-
<version>3.1.1</version>
392+
<version>3.4.1</version>
393393
<configuration>
394394
<useStandardDocletOptions>true</useStandardDocletOptions>
395395
<maxmemory>800m</maxmemory>
@@ -407,12 +407,12 @@
407407
<plugin>
408408
<groupId>org.apache.maven.plugins</groupId>
409409
<artifactId>maven-project-info-reports-plugin</artifactId>
410-
<version>3.0.0</version>
410+
<version>3.4.1</version>
411411
</plugin>
412412
<plugin>
413413
<groupId>org.apache.maven.plugins</groupId>
414414
<artifactId>maven-jxr-plugin</artifactId>
415-
<version>3.0.0</version>
415+
<version>3.3.0</version>
416416
</plugin>
417417

418418
<!-- Cobertura is broken with Java 1.8 and there is not fix

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public interface ExpressionVisitor {
119119

120120
void visit(TryCastExpression cast);
121121

122+
void visit(SafeCastExpression cast);
123+
122124
void visit(Modulo modulo);
123125

124126
void visit(AnalyticExpression aexpr);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,11 @@ public void visit(TryCastExpression expr) {
315315
expr.getLeftExpression().accept(this);
316316
}
317317

318+
@Override
319+
public void visit(SafeCastExpression expr) {
320+
expr.getLeftExpression().accept(this);
321+
}
322+
318323
@Override
319324
public void visit(Modulo expr) {
320325
visitBinaryExpression(expr);
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
package net.sf.jsqlparser.expression;
11+
12+
import net.sf.jsqlparser.parser.ASTNodeAccessImpl;
13+
import net.sf.jsqlparser.statement.create.table.ColDataType;
14+
15+
public class SafeCastExpression extends ASTNodeAccessImpl implements Expression {
16+
17+
private Expression leftExpression;
18+
private ColDataType type;
19+
private RowConstructor rowConstructor;
20+
private boolean useCastKeyword = true;
21+
22+
public RowConstructor getRowConstructor() {
23+
return rowConstructor;
24+
}
25+
26+
public void setRowConstructor(RowConstructor rowConstructor) {
27+
this.rowConstructor = rowConstructor;
28+
this.type = null;
29+
}
30+
31+
public SafeCastExpression withRowConstructor(RowConstructor rowConstructor) {
32+
setRowConstructor(rowConstructor);
33+
return this;
34+
}
35+
36+
public ColDataType getType() {
37+
return type;
38+
}
39+
40+
public void setType(ColDataType type) {
41+
this.type = type;
42+
this.rowConstructor = null;
43+
}
44+
45+
public Expression getLeftExpression() {
46+
return leftExpression;
47+
}
48+
49+
public void setLeftExpression(Expression expression) {
50+
leftExpression = expression;
51+
}
52+
53+
@Override
54+
public void accept(ExpressionVisitor expressionVisitor) {
55+
expressionVisitor.visit(this);
56+
}
57+
58+
public boolean isUseCastKeyword() {
59+
return useCastKeyword;
60+
}
61+
62+
public void setUseCastKeyword(boolean useCastKeyword) {
63+
this.useCastKeyword = useCastKeyword;
64+
}
65+
66+
@Override
67+
public String toString() {
68+
if (useCastKeyword) {
69+
return rowConstructor!=null
70+
? "SAFE_CAST(" + leftExpression + " AS " + rowConstructor.toString() + ")"
71+
: "SAFE_CAST(" + leftExpression + " AS " + type.toString() + ")";
72+
} else {
73+
return leftExpression + "::" + type.toString();
74+
}
75+
}
76+
77+
public SafeCastExpression withType(ColDataType type) {
78+
this.setType(type);
79+
return this;
80+
}
81+
82+
public SafeCastExpression withUseCastKeyword(boolean useCastKeyword) {
83+
this.setUseCastKeyword(useCastKeyword);
84+
return this;
85+
}
86+
87+
public SafeCastExpression withLeftExpression(Expression leftExpression) {
88+
this.setLeftExpression(leftExpression);
89+
return this;
90+
}
91+
92+
public <E extends Expression> E getLeftExpression(Class<E> type) {
93+
return type.cast(getLeftExpression());
94+
}
95+
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,25 @@ public void setSchemaName(String schemaName) {
103103
}
104104

105105
public String getName() {
106-
return getIndex(NAME_IDX);
106+
String name = getIndex(NAME_IDX);
107+
if (name!=null && name.contains("@")) {
108+
int pos = name.lastIndexOf('@');
109+
if (pos>0) {
110+
name = name.substring(0, pos );
111+
}
112+
}
113+
return name;
114+
}
115+
116+
public String getDBLinkName() {
117+
String name = getIndex(NAME_IDX);
118+
if (name!=null && name.contains("@")) {
119+
int pos = name.lastIndexOf('@');
120+
if (pos>0 && name.length()>1) {
121+
name = name.substring(pos+1);
122+
}
123+
}
124+
return name;
107125
}
108126

109127
public Table withName(String name) {
@@ -241,4 +259,8 @@ public Table withSqlServerHints(SQLServerHints sqlServerHints) {
241259
this.setSqlServerHints(sqlServerHints);
242260
return this;
243261
}
262+
263+
public List<String> getNameParts() {
264+
return partItems;
265+
}
244266
}

src/main/java/net/sf/jsqlparser/statement/insert/InsertConflictAction.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@
3232
*/
3333

3434
public class InsertConflictAction {
35-
ConflictActionType conflictActionType;
36-
3735
private final ArrayList<UpdateSet> updateSets = new ArrayList<>();
36+
ConflictActionType conflictActionType;
3837
Expression whereExpression;
39-
4038
public InsertConflictAction(ConflictActionType conflictActionType) {
4139
this.conflictActionType = Objects.requireNonNull(conflictActionType, "The Conflict Action Type is mandatory and must not be Null.");
4240
}
4341

42+
public ArrayList<UpdateSet> getUpdateSets() {
43+
return updateSets;
44+
}
45+
4446
public ConflictActionType getConflictActionType() {
4547
return conflictActionType;
4648
}

src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ public void visit(TryCastExpression cast) {
474474
cast.getLeftExpression().accept(this);
475475
}
476476

477+
@Override
478+
public void visit(SafeCastExpression cast) {
479+
cast.getLeftExpression().accept(this);
480+
}
481+
477482
@Override
478483
public void visit(Modulo modulo) {
479484
visitBinaryExpression(modulo);

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ public void visit(TryCastExpression cast) {
622622
}
623623
}
624624

625+
@Override
626+
public void visit(SafeCastExpression cast) {
627+
if (cast.isUseCastKeyword()) {
628+
buffer.append("SAFE_CAST(");
629+
cast.getLeftExpression().accept(this);
630+
buffer.append(" AS ");
631+
buffer.append(cast.getRowConstructor() != null ? cast.getRowConstructor() : cast.getType());
632+
buffer.append(")");
633+
} else {
634+
cast.getLeftExpression().accept(this);
635+
buffer.append("::");
636+
buffer.append(cast.getType());
637+
}
638+
639+
}
640+
625641
@Override
626642
public void visit(Modulo modulo) {
627643
visitBinaryExpression(modulo, " % ");

0 commit comments

Comments
 (0)