Skip to content

Commit 8c994ad

Browse files
committed
Merge upstream master and reconcile shared table options
Signed-off-by: minleejae <mmj9808@gmail.com> # Conflicts: # src/main/java/net/sf/jsqlparser/statement/create/table/TableOption.java # src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
2 parents abb28d3 + 8ffa565 commit 8c994ad

37 files changed

Lines changed: 1907 additions & 150 deletions
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2026 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.statement;
11+
12+
import java.io.Serializable;
13+
import net.sf.jsqlparser.expression.StringValue;
14+
15+
/** Structured account shared by MySQL stored-object {@code DEFINER} clause. */
16+
public class MySqlDefiner implements Serializable {
17+
18+
private StringValue user;
19+
private StringValue host;
20+
private boolean currentUserParentheses;
21+
22+
public boolean isCurrentUserParentheses() {
23+
return currentUserParentheses;
24+
}
25+
26+
public void setCurrentUserParentheses(boolean currentUserParentheses) {
27+
this.currentUserParentheses = currentUserParentheses;
28+
}
29+
30+
31+
public StringValue getUser() {
32+
return user;
33+
}
34+
35+
public void setUser(StringValue user) {
36+
this.user = user;
37+
currentUserParentheses = false;
38+
}
39+
40+
public StringValue getHost() {
41+
return host;
42+
}
43+
44+
public void setHost(StringValue host) {
45+
this.host = host;
46+
}
47+
48+
@Override
49+
public String toString() {
50+
StringBuilder builder = new StringBuilder().append(user);
51+
if (currentUserParentheses) {
52+
builder.append("()");
53+
}
54+
if (host != null) {
55+
builder.append("@").append(host);
56+
}
57+
return builder.toString();
58+
}
59+
60+
public MySqlDefiner withUser(StringValue user) {
61+
setUser(user);
62+
return this;
63+
}
64+
65+
public MySqlDefiner withHost(StringValue host) {
66+
setHost(host);
67+
return this;
68+
}
69+
}

‎src/main/java/net/sf/jsqlparser/statement/StatementVisitor.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package net.sf.jsqlparser.statement;
1111

12+
import net.sf.jsqlparser.statement.alter.database.AlterDatabase;
1213
import net.sf.jsqlparser.statement.alter.schema.AlterSchema;
1314
import net.sf.jsqlparser.statement.oracle.OracleBlock;
1415
import net.sf.jsqlparser.statement.oracle.OracleAssignment;
@@ -671,4 +672,12 @@ default void visit(OracleNullStatement statement) {
671672
visit(statement, null);
672673
}
673674

675+
default <S> T visit(AlterDatabase statement, S context) {
676+
return null;
677+
}
678+
679+
default void visit(AlterDatabase statement) {
680+
visit(statement, null);
681+
}
682+
674683
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*-
2+
* #%L
3+
* JSQLParser library
4+
* %%
5+
* Copyright (C) 2004 - 2026 JSQLParser
6+
* %%
7+
* Dual licensed under GNU LGPL 2.1 or Apache License 2.0
8+
* #L%
9+
*/
10+
package net.sf.jsqlparser.statement.alter.database;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
import java.util.Optional;
15+
import net.sf.jsqlparser.statement.Statement;
16+
import net.sf.jsqlparser.statement.StatementVisitor;
17+
import net.sf.jsqlparser.statement.create.database.DatabaseOption;
18+
19+
/** MySQL ALTER DATABASE (or SCHEMA); a missing name selects the current database. */
20+
public class AlterDatabase implements Statement {
21+
private String databaseName;
22+
private boolean useSchemaKeyword;
23+
private final List<DatabaseOption> options = new ArrayList<>();
24+
25+
public String getDatabaseName() {
26+
return databaseName;
27+
}
28+
29+
public void setDatabaseName(String databaseName) {
30+
this.databaseName = databaseName;
31+
}
32+
33+
public boolean isUseSchemaKeyword() {
34+
return useSchemaKeyword;
35+
}
36+
37+
public void setUseSchemaKeyword(boolean useSchemaKeyword) {
38+
this.useSchemaKeyword = useSchemaKeyword;
39+
}
40+
41+
public List<DatabaseOption> getOptions() {
42+
return options;
43+
}
44+
45+
public Optional<DatabaseOption> getOption(DatabaseOption.Kind kind) {
46+
return options.stream().filter(option -> option.getKind() == kind).findFirst();
47+
}
48+
49+
public StringBuilder appendTo(StringBuilder builder) {
50+
builder.append(useSchemaKeyword ? "ALTER SCHEMA" : "ALTER DATABASE");
51+
if (databaseName != null) {
52+
builder.append(' ').append(databaseName);
53+
}
54+
options.forEach(option -> builder.append(' ').append(option));
55+
return builder;
56+
}
57+
58+
@Override
59+
public String toString() {
60+
return appendTo(new StringBuilder()).toString();
61+
}
62+
63+
@Override
64+
public <T, S> T accept(StatementVisitor<T> visitor, S context) {
65+
return visitor.visit(this, context);
66+
}
67+
}

‎src/main/java/net/sf/jsqlparser/statement/alter/sequence/AlterSequence.java‎

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,79 @@
1818
*/
1919
public class AlterSequence implements Statement {
2020

21+
public enum Action {
22+
PARAMETERS, RENAME, OWNER, SET_SCHEMA, SET_LOGGED, SET_UNLOGGED
23+
}
24+
2125
public Sequence sequence;
26+
private boolean ifExists;
27+
private Action action = Action.PARAMETERS;
28+
private String newName;
29+
private String owner;
30+
private String schemaName;
31+
32+
public boolean isIfExists() {
33+
return ifExists;
34+
}
35+
36+
public void setIfExists(boolean ifExists) {
37+
this.ifExists = ifExists;
38+
}
39+
40+
public Action getAction() {
41+
return action;
42+
}
43+
44+
public void setAction(Action action) {
45+
this.action = java.util.Objects.requireNonNull(action, "action");
46+
}
47+
48+
public String getNewName() {
49+
return newName;
50+
}
51+
52+
public void setNewName(String newName) {
53+
this.newName = newName;
54+
}
55+
56+
public String getOwner() {
57+
return owner;
58+
}
59+
60+
public void setOwner(String owner) {
61+
this.owner = owner;
62+
}
63+
64+
public String getSchemaName() {
65+
return schemaName;
66+
}
67+
68+
public void setSchemaName(String schemaName) {
69+
this.schemaName = schemaName;
70+
}
71+
72+
public StringBuilder appendTo(StringBuilder builder) {
73+
builder.append("ALTER SEQUENCE ");
74+
if (ifExists) {
75+
builder.append("IF EXISTS ");
76+
}
77+
builder.append(action == Action.PARAMETERS ? sequence : sequence.getFullyQualifiedName());
78+
switch (action) {
79+
case RENAME:
80+
return builder.append(" RENAME TO ").append(newName);
81+
case OWNER:
82+
return builder.append(" OWNER TO ").append(owner);
83+
case SET_SCHEMA:
84+
return builder.append(" SET SCHEMA ").append(schemaName);
85+
case SET_LOGGED:
86+
return builder.append(" SET LOGGED");
87+
case SET_UNLOGGED:
88+
return builder.append(" SET UNLOGGED");
89+
default:
90+
return builder;
91+
}
92+
}
93+
2294

2395
public Sequence getSequence() {
2496
return sequence;
@@ -35,9 +107,7 @@ public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
35107

36108
@Override
37109
public String toString() {
38-
String sql;
39-
sql = "ALTER SEQUENCE " + sequence;
40-
return sql;
110+
return appendTo(new StringBuilder()).toString();
41111
}
42112

43113
public AlterSequence withSequence(Sequence sequence) {

‎src/main/java/net/sf/jsqlparser/statement/create/database/DatabaseOption.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
import java.util.Collections;
1515
import java.util.List;
1616

17-
/** A structured option shared by MySQL {@code CREATE DATABASE} and {@code CREATE SCHEMA}. */
17+
/**
18+
* A structured option shared by MySQL {@code CREATE/ALTER DATABASE} and
19+
* {@code CREATE/ALTER SCHEMA}.
20+
*/
1821
public class DatabaseOption implements Serializable {
1922

2023
public enum Kind {
21-
CHARACTER_SET, COLLATE, ENCRYPTION, OTHER
24+
CHARACTER_SET, COLLATE, ENCRYPTION, READ_ONLY, OTHER
2225
}
2326

2427
private Kind kind = Kind.OTHER;

‎src/main/java/net/sf/jsqlparser/statement/create/sequence/CreateSequence.java‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,42 @@
1818
*/
1919
public class CreateSequence implements Statement {
2020

21+
public enum Persistence {
22+
TEMP, TEMPORARY, UNLOGGED, LOCAL_TEMP, LOCAL_TEMPORARY, GLOBAL_TEMP, GLOBAL_TEMPORARY
23+
}
24+
2125
public Sequence sequence;
26+
private Persistence persistence;
27+
private boolean ifNotExists;
28+
29+
public Persistence getPersistence() {
30+
return persistence;
31+
}
32+
33+
public void setPersistence(Persistence persistence) {
34+
this.persistence = persistence;
35+
}
36+
37+
public boolean isIfNotExists() {
38+
return ifNotExists;
39+
}
40+
41+
public void setIfNotExists(boolean ifNotExists) {
42+
this.ifNotExists = ifNotExists;
43+
}
44+
45+
public StringBuilder appendTo(StringBuilder builder) {
46+
builder.append("CREATE ");
47+
if (persistence != null) {
48+
builder.append(persistence.name().replace('_', ' ')).append(' ');
49+
}
50+
builder.append("SEQUENCE ");
51+
if (ifNotExists) {
52+
builder.append("IF NOT EXISTS ");
53+
}
54+
return builder.append(sequence);
55+
}
56+
2257

2358
public Sequence getSequence() {
2459
return sequence;
@@ -35,9 +70,7 @@ public <T, S> T accept(StatementVisitor<T> statementVisitor, S context) {
3570

3671
@Override
3772
public String toString() {
38-
String sql;
39-
sql = "CREATE SEQUENCE " + sequence;
40-
return sql;
73+
return appendTo(new StringBuilder()).toString();
4174
}
4275

4376
public CreateSequence withSequence(Sequence sequence) {

‎src/main/java/net/sf/jsqlparser/statement/create/table/ColDataType.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ public enum CharacterSetSyntax {
4848
private CharacterSetSyntax characterSetSyntax = CharacterSetSyntax.CHARACTER_SET;
4949
private IntervalQualifier intervalQualifier;
5050
private List<Integer> arrayData = new ArrayList<Integer>();
51+
private boolean usingArrayKeyword;
52+
53+
/** ARRAY or ARRAY[n] spelling; arrayData still contains the single dimension. */
54+
public boolean isUsingArrayKeyword() {
55+
return usingArrayKeyword;
56+
}
57+
58+
public void setUsingArrayKeyword(boolean usingArrayKeyword) {
59+
this.usingArrayKeyword = usingArrayKeyword;
60+
}
61+
5162
private Signedness signedness;
5263
private boolean zerofill;
5364
private BigInteger precision;
@@ -365,7 +376,13 @@ public void setScale(Integer scale) {
365376
@Override
366377
public String toString() {
367378
StringBuilder arraySpec = new StringBuilder();
379+
if (usingArrayKeyword && !arrayData.isEmpty()) {
380+
arraySpec.append(" ARRAY");
381+
}
368382
for (Integer item : arrayData) {
383+
if (usingArrayKeyword && item == null) {
384+
continue;
385+
}
369386
arraySpec.append("[");
370387
if (item != null) {
371388
arraySpec.append(item);
@@ -498,6 +515,7 @@ public final boolean equals(Object o) {
498515
&& characterSetSyntax == that.characterSetSyntax
499516
&& Objects.equals(intervalQualifier, that.intervalQualifier)
500517
&& Objects.equals(arrayData, that.arrayData)
518+
&& usingArrayKeyword == that.usingArrayKeyword
501519
&& signedness == that.signedness
502520
&& zerofill == that.zerofill
503521
&& Objects.equals(typeModifiers, that.typeModifiers)
@@ -516,6 +534,7 @@ public int hashCode() {
516534
result = 31 * result + Objects.hashCode(characterSetSyntax);
517535
result = 31 * result + Objects.hashCode(intervalQualifier);
518536
result = 31 * result + Objects.hashCode(arrayData);
537+
result = 31 * result + Boolean.hashCode(usingArrayKeyword);
519538
result = 31 * result + Objects.hashCode(signedness);
520539
result = 31 * result + Boolean.hashCode(zerofill);
521540
result = 31 * result + Objects.hashCode(typeModifiers);

0 commit comments

Comments
 (0)