Skip to content

Commit 010d611

Browse files
committed
add support of a Google Spanner Interleaved table, commit timestamp options and array types
1 parent af7bc1c commit 010d611

File tree

17 files changed

+404
-166
lines changed

17 files changed

+404
-166
lines changed

pom.xml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
<groupId>org.javacc.plugin</groupId>
194194
<artifactId>javacc-maven-plugin</artifactId>
195195
<version>3.0.3</version>
196-
196+
197197
<executions>
198198
<execution>
199199
<id>javacc</id>
@@ -202,15 +202,15 @@
202202
<goal>jjtree-javacc</goal>
203203
</goals>
204204
</execution>
205-
205+
206206
<!-- execute JJTree explicitely in order to generate the *.jj file needed for JJDoc -->
207207
<execution>
208208
<id>jjtree</id>
209209
<phase>generate-sources</phase>
210210
<goals>
211211
<goal>jjtree</goal>
212212
</goals>
213-
</execution>
213+
</execution>
214214
</executions>
215215
<dependencies>
216216
<dependency>
@@ -394,7 +394,7 @@
394394
<useStandardDocletOptions>true</useStandardDocletOptions>
395395
<maxmemory>800m</maxmemory>
396396
<doclint>none</doclint>
397-
397+
398398
<!-- Doclint does not work on the Test Sources
399399
<doclint>all,-missing</doclint>
400400
<excludePackageNames>net.sf.jsqlparser.parser</excludePackageNames>
@@ -414,10 +414,10 @@
414414
<artifactId>maven-jxr-plugin</artifactId>
415415
<version>3.0.0</version>
416416
</plugin>
417-
417+
418418
<!-- Cobertura is broken with Java 1.8 and there is not fix
419419
please refer to https://github.com/cobertura/cobertura/issues/248
420-
420+
421421
<plugin>
422422
<groupId>org.codehaus.mojo</groupId>
423423
<artifactId>cobertura-maven-plugin</artifactId>
@@ -428,13 +428,13 @@
428428
</configuration>
429429
</plugin>
430430
-->
431-
431+
432432
<plugin>
433433
<groupId>org.codehaus.mojo</groupId>
434434
<artifactId>findbugs-maven-plugin</artifactId>
435435
<version>3.0.5</version>
436436
</plugin>
437-
437+
438438
<!-- Obsolete or Unused
439439
<plugin>
440440
<groupId>org.apache.maven.plugins</groupId>
@@ -444,60 +444,60 @@
444444
</configuration>
445445
</plugin>
446446
-->
447-
447+
448448
<!-- JJDoc report generating the BNF documentation -->
449449
<plugin>
450450
<groupId>org.codehaus.mojo</groupId>
451451
<artifactId>javacc-maven-plugin</artifactId>
452452
<version>2.6</version>
453453
<configuration>
454-
<!--
454+
<!--
455455
/**
456456
* A flag to specify the output format for the generated documentation. If set to <code>true</code>, JJDoc will
457457
* generate a plain text description of the BNF. Some formatting is done via tab characters, but the intention is to
458458
* leave it as plain as possible. Specifying <code>false</code> causes JJDoc to generate a hyperlinked HTML document
459459
* unless the parameter {@link #bnf} has been set to <code>true</code>. Default value is <code>false</code>.
460-
*
460+
*
461461
* @parameter expression="${text}"
462462
*/
463463
-->
464464
<text>false</text>
465-
465+
466466
<!--
467467
/**
468468
* A flag whether to generate a plain text document with the unformatted BNF. Note that setting this option to
469469
* <code>true</code> is only effective if the parameter {@link #text} is <code>false</code>. Default value is
470470
* <code>false</code>.
471-
*
471+
*
472472
* @parameter expression="${bnf}"
473473
* @since 2.6
474474
*/
475475
-->
476476
<bnf>false</bnf>
477-
477+
478478
<!--
479479
/**
480480
* This option controls the structure of the generated HTML output. If set to <code>true</code>, a single HTML
481481
* table for the entire BNF is generated. Setting it to <code>false</code> will produce one table for every
482482
* production in the grammar.
483-
*
483+
*
484484
* @parameter expression="${oneTable}" default-value=true
485485
*/
486486
-->
487487
<oneTable>false</oneTable>
488-
488+
489489
<!--
490490
/**
491491
* The hypertext reference to an optional CSS file for the generated HTML documents. If specified, this CSS file
492492
* will be included via a <code>&lt;link&gt;</code> element in the HTML documents. Otherwise, the default style will
493493
* be used.
494-
*
494+
*
495495
* @parameter expression="${cssHref}"
496496
* @since 2.5
497-
*/
497+
*/
498498
-->
499499
<!-- <cssHref></cssHref> -->
500-
500+
501501
<outputDirectory>${project.reporting.outputDirectory}</outputDirectory>
502502
</configuration>
503503
</plugin>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public void visit(NamedExpressionList namedExpressionList) {
375375

376376
@Override
377377
public void visit(MultiExpressionList multiExprList) {
378-
for (ExpressionList list : multiExprList.getExprList()) {
378+
for (ExpressionList list : multiExprList.getExpressionLists()) {
379379
visit(list);
380380
}
381381
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2021 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.schema.Table;
13+
14+
import java.util.Collections;
15+
import java.util.List;
16+
17+
public class SpannerInterleaveIn {
18+
19+
public enum OnDelete {
20+
CASCADE,
21+
NO_ACTION
22+
}
23+
24+
private Table table;
25+
private OnDelete onDelete;
26+
27+
public SpannerInterleaveIn() {
28+
29+
}
30+
31+
public SpannerInterleaveIn(Table table, OnDelete action) {
32+
setTable(table);
33+
setOnDelete(action);
34+
}
35+
36+
public SpannerInterleaveIn(List<String> nameParts) {
37+
this(new Table(nameParts), null);
38+
}
39+
40+
public SpannerInterleaveIn(String tableName) {
41+
this(Collections.singletonList(tableName));
42+
}
43+
44+
public Table getTable() {
45+
return table;
46+
}
47+
48+
public void setTable(Table table) {
49+
this.table = table;
50+
}
51+
52+
public OnDelete getOnDelete() {
53+
return onDelete;
54+
}
55+
56+
public void setOnDelete(OnDelete action) {
57+
this.onDelete = action;
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return "INTERLEAVE IN PARENT " + getTable().getName() +
63+
(getOnDelete() == null ? "" : " ON DELETE " + (getOnDelete() == OnDelete.CASCADE ? "CASCADE" : "NO ACTION"));
64+
}
65+
66+
public SpannerInterleaveIn withTable(Table table) {
67+
this.setTable(table);
68+
return this;
69+
}
70+
71+
public SpannerInterleaveIn withOnDelete(OnDelete action) {
72+
this.setOnDelete(action);
73+
return this;
74+
}
75+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void visit(ExpressionList expressionList) {
3131

3232
@Override
3333
public void visit(MultiExpressionList multiExprList) {
34-
for (ExpressionList list : multiExprList.getExprList()) {
34+
for (ExpressionList list : multiExprList.getExpressionLists()) {
3535
visit(list);
3636
}
3737
}

src/main/java/net/sf/jsqlparser/statement/create/table/CreateTable.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616
import java.util.Optional;
1717

18+
import net.sf.jsqlparser.expression.SpannerInterleaveIn;
1819
import net.sf.jsqlparser.schema.Table;
1920
import net.sf.jsqlparser.statement.Statement;
2021
import net.sf.jsqlparser.statement.StatementVisitor;
@@ -37,6 +38,7 @@ public class CreateTable implements Statement {
3738
private boolean orReplace = false;
3839

3940
private RowMovement rowMovement;
41+
private SpannerInterleaveIn interleaveIn = null;
4042

4143
@Override
4244
public void accept(StatementVisitor statementVisitor) {
@@ -186,18 +188,21 @@ public String toString() {
186188
sql += ")";
187189
}
188190
String options = PlainSelect.getStringList(tableOptionsStrings, false, false);
189-
if (options != null && options.length() > 0) {
191+
if (!options.isEmpty()) {
190192
sql += " " + options;
191193
}
192194

193195
if (rowMovement != null) {
194196
sql += " " + rowMovement.getMode().toString() + " ROW MOVEMENT";
195197
}
196198
if (select != null) {
197-
sql += " AS " + (selectParenthesis ? "(" : "") + select.toString() + (selectParenthesis ? ")" : "");
199+
sql += " AS " + (selectParenthesis ? "(" : "") + select + (selectParenthesis ? ")" : "");
198200
}
199201
if (likeTable != null) {
200-
sql += " LIKE " + (selectParenthesis ? "(" : "") + likeTable.toString() + (selectParenthesis ? ")" : "");
202+
sql += " LIKE " + (selectParenthesis ? "(" : "") + likeTable + (selectParenthesis ? ")" : "");
203+
}
204+
if (interleaveIn != null) {
205+
sql += ", " + interleaveIn;
201206
}
202207
return sql;
203208
}
@@ -299,4 +304,17 @@ public CreateTable addIndexes(Collection<? extends Index> indexes) {
299304
collection.addAll(indexes);
300305
return this.withIndexes(collection);
301306
}
307+
308+
public SpannerInterleaveIn getSpannerInterleaveIn() {
309+
return interleaveIn;
310+
}
311+
312+
public void setSpannerInterleaveIn(SpannerInterleaveIn spannerInterleaveIn) {
313+
this.interleaveIn = spannerInterleaveIn;
314+
}
315+
316+
public CreateTable withSpannerInterleaveIn(SpannerInterleaveIn spannerInterleaveIn) {
317+
this.interleaveIn = spannerInterleaveIn;
318+
return this;
319+
}
302320
}

src/main/java/net/sf/jsqlparser/statement/select/ValuesList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public String toString() {
8888
StringBuilder b = new StringBuilder();
8989

9090
b.append("(VALUES ");
91-
for (Iterator<ExpressionList> it = getMultiExpressionList().getExprList().iterator(); it.
91+
for (Iterator<ExpressionList> it = getMultiExpressionList().getExpressionLists().iterator(); it.
9292
hasNext();) {
9393
b.append(PlainSelect.getStringList(it.next().getExpressions(), true, !isNoBrackets()));
9494
if (it.hasNext()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ public void visit(LateralSubSelect lateralSubSelect) {
496496

497497
@Override
498498
public void visit(MultiExpressionList multiExprList) {
499-
for (ExpressionList exprList : multiExprList.getExprList()) {
499+
for (ExpressionList exprList : multiExprList.getExpressionLists()) {
500500
exprList.accept(this);
501501
}
502502
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void deParse(CreateIndex createIndex) {
4444

4545
if (index.getColumnsNames() != null) {
4646
buffer.append(" (");
47-
buffer.append(index.getColumnWithParams().stream()
47+
buffer.append(index.getColumns().stream()
4848
.map(cp -> cp.columnName + (cp.getParams() != null ? " " + String.join(" ", cp.getParams()) : ""))
4949
.collect(joining(", ")));
5050
buffer.append(")");

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ public void deParse(CreateTable createTable) {
120120
buffer.append(")");
121121
}
122122
}
123+
if (createTable.getSpannerInterleaveIn() != null) {
124+
buffer.append(", ").append(createTable.getSpannerInterleaveIn());
125+
}
123126
}
124127

125128
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public void deParse(DeclareStatement declare) {
3131
declare.getUserVariable().accept(expressionVisitor);
3232
}
3333

34-
if (declare.getType() == DeclareType.AS) {
34+
if (declare.getDeclareType() == DeclareType.AS) {
3535
buffer.append(" AS ");
3636
buffer.append(declare.getTypeName());
3737
return;
3838
}
3939

40-
if (declare.getType() == DeclareType.TABLE) {
40+
if (declare.getDeclareType() == DeclareType.TABLE) {
4141
buffer.append(" TABLE (");
4242
for (int i = 0; i < declare.getColumnDefinitions().size(); i++) {
4343
if (i > 0) {

0 commit comments

Comments
 (0)