Skip to content

Commit 33b4eea

Browse files
committed
Merge master and preserve rewrite rules and foreign-data grammar
Signed-off-by: minleejae <mmj9808@gmail.com>
2 parents c4a8a59 + 0de0e09 commit 33b4eea

33 files changed

Lines changed: 2213 additions & 274 deletions

‎src/main/java/net/sf/jsqlparser/parser/feature/Feature.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ public enum Feature {
580580
*/
581581
createSequence,
582582
/** Publication and subscription definitions. */
583+
createForeignDataWrapper, alterForeignDataWrapper, createServer, alterServer, createUserMapping, alterUserMapping,
584+
583585
createRule, notifyStatement,
584586

585587
createPublication, alterPublication, createSubscription, alterSubscription,
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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.schema;
11+
12+
import java.io.Serializable;
13+
14+
/** A relation target with optional PostgreSQL inheritance scope, shared by LOCK and TRUNCATE. */
15+
public class TableReference implements Serializable {
16+
private Table table;
17+
private boolean only;
18+
private boolean includeDescendants;
19+
private boolean parenthesized;
20+
21+
public TableReference(Table table) {
22+
this.table = table;
23+
}
24+
25+
public Table getTable() {
26+
return table;
27+
}
28+
29+
public void setTable(Table table) {
30+
this.table = table;
31+
}
32+
33+
public boolean isOnly() {
34+
return only;
35+
}
36+
37+
public void setOnly(boolean only) {
38+
this.only = only;
39+
if (only) {
40+
includeDescendants = false;
41+
} else {
42+
parenthesized = false;
43+
}
44+
}
45+
46+
public boolean isIncludeDescendants() {
47+
return includeDescendants;
48+
}
49+
50+
public void setIncludeDescendants(boolean includeDescendants) {
51+
this.includeDescendants = includeDescendants;
52+
if (includeDescendants) {
53+
only = false;
54+
parenthesized = false;
55+
}
56+
}
57+
58+
public boolean isParenthesized() {
59+
return parenthesized;
60+
}
61+
62+
public void setParenthesized(boolean parenthesized) {
63+
this.parenthesized = parenthesized;
64+
if (parenthesized) {
65+
only = true;
66+
includeDescendants = false;
67+
}
68+
}
69+
70+
public StringBuilder appendTo(StringBuilder builder) {
71+
if (only) {
72+
builder.append("ONLY ");
73+
}
74+
if (parenthesized) {
75+
builder.append('(');
76+
}
77+
builder.append(table.getFullyQualifiedName());
78+
if (parenthesized) {
79+
builder.append(')');
80+
}
81+
if (includeDescendants) {
82+
builder.append(" *");
83+
}
84+
return builder;
85+
}
86+
87+
@Override
88+
public String toString() {
89+
return appendTo(new StringBuilder()).toString();
90+
}
91+
}

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

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

12+
import net.sf.jsqlparser.statement.create.fdw.CreateForeignDataWrapper;
13+
import net.sf.jsqlparser.statement.alter.AlterForeignDataWrapper;
14+
import net.sf.jsqlparser.statement.create.server.CreateServer;
15+
import net.sf.jsqlparser.statement.alter.AlterServer;
16+
import net.sf.jsqlparser.statement.create.usermapping.CreateUserMapping;
17+
import net.sf.jsqlparser.statement.alter.AlterUserMapping;
1218
import net.sf.jsqlparser.statement.create.rule.CreateRule;
1319
import net.sf.jsqlparser.statement.notify.NotifyStatement;
1420
import net.sf.jsqlparser.statement.alter.AlterPolicy;
@@ -736,6 +742,54 @@ default void visit(AlterStatistics statement) {
736742
visit(statement, null);
737743
}
738744

745+
default <S> T visit(CreateForeignDataWrapper statement, S context) {
746+
return null;
747+
}
748+
749+
default void visit(CreateForeignDataWrapper statement) {
750+
visit(statement, null);
751+
}
752+
753+
default <S> T visit(AlterForeignDataWrapper statement, S context) {
754+
return null;
755+
}
756+
757+
default void visit(AlterForeignDataWrapper statement) {
758+
visit(statement, null);
759+
}
760+
761+
default <S> T visit(CreateServer statement, S context) {
762+
return null;
763+
}
764+
765+
default void visit(CreateServer statement) {
766+
visit(statement, null);
767+
}
768+
769+
default <S> T visit(AlterServer statement, S context) {
770+
return null;
771+
}
772+
773+
default void visit(AlterServer statement) {
774+
visit(statement, null);
775+
}
776+
777+
default <S> T visit(CreateUserMapping statement, S context) {
778+
return null;
779+
}
780+
781+
default void visit(CreateUserMapping statement) {
782+
visit(statement, null);
783+
}
784+
785+
default <S> T visit(AlterUserMapping statement, S context) {
786+
return null;
787+
}
788+
789+
default void visit(AlterUserMapping statement) {
790+
visit(statement, null);
791+
}
792+
739793
default <S> T visit(CreateRule statement, S context) {
740794
return null;
741795
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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;
11+
12+
import java.util.Objects;
13+
import net.sf.jsqlparser.statement.create.table.ConstraintAttributes;
14+
15+
/** Changes an existing constraint using the attributes shared with CREATE and ADD. */
16+
public class AlterConstraintAttributes extends AlterExpression {
17+
private ConstraintAttributes attributes = new ConstraintAttributes();
18+
19+
public AlterConstraintAttributes() {
20+
setOperation(AlterOperation.ALTER);
21+
setConstraintType("CONSTRAINT");
22+
}
23+
24+
public ConstraintAttributes getAttributes() {
25+
return attributes;
26+
}
27+
28+
public void setAttributes(ConstraintAttributes attributes) {
29+
this.attributes = Objects.requireNonNull(attributes, "attributes");
30+
}
31+
32+
@Override
33+
public String getConstraintName() {
34+
return getConstraintSymbol();
35+
}
36+
37+
@Override
38+
public void setConstraintName(String name) {
39+
setConstraintSymbol(name);
40+
}
41+
42+
@Override
43+
public boolean isEnforced() {
44+
return Boolean.TRUE.equals(attributes.getEnforced());
45+
}
46+
47+
@Override
48+
public void setEnforced(boolean enforced) {
49+
attributes.setEnforced(enforced);
50+
}
51+
52+
@Override
53+
protected void appendBody(StringBuilder builder) {
54+
builder.append("ALTER CONSTRAINT ").append(getConstraintSymbol());
55+
attributes.appendTo(builder);
56+
}
57+
}

‎src/main/java/net/sf/jsqlparser/statement/alter/AlterExpression.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,17 @@ public void setHasEqualForCollate(boolean hasEqualForCollate) {
15361536
public static final class ColumnDataType extends ColumnDefinition {
15371537

15381538
private final boolean withType;
1539+
private boolean useSetData;
15391540
private Expression usingExpression;
1541+
1542+
public boolean isUseSetData() {
1543+
return useSetData;
1544+
}
1545+
1546+
public void setUseSetData(boolean useSetData) {
1547+
this.useSetData = useSetData;
1548+
}
1549+
15401550
private List<IdentityAlteration> identityAlterations;
15411551

15421552
public boolean isWithType() {
@@ -1587,7 +1597,8 @@ public void appendTo(StringBuilder builder, Consumer<Expression> expressionPrint
15871597
.append(PlainSelect.getStringList(identityAlterations, false, false));
15881598
return;
15891599
}
1590-
builder.append(withType ? " TYPE " : getColDataType() == null ? "" : " ");
1600+
builder.append(withType ? (useSetData ? " SET DATA TYPE " : " TYPE ")
1601+
: getColDataType() == null ? "" : " ");
15911602
appendDataTypeAndSpecTo(builder, expressionPrinter);
15921603
if (usingExpression != null) {
15931604
builder.append(" USING ");

‎src/main/java/net/sf/jsqlparser/statement/alter/AlterExpressionTableOption.java‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,76 @@ public void setStructuredTableOption(TableOption option) {
3232
super.setUseEqual(false);
3333
}
3434

35+
@Override
36+
public AlterOperation getOperation() {
37+
if (structuredTableOption != null) {
38+
switch (structuredTableOption.getKind()) {
39+
case ENGINE:
40+
return AlterOperation.ENGINE;
41+
case KEY_BLOCK_SIZE:
42+
return AlterOperation.KEY_BLOCK_SIZE;
43+
case COMMENT:
44+
return structuredTableOption.isUseEquals()
45+
? AlterOperation.COMMENT_WITH_EQUAL_SIGN
46+
: AlterOperation.COMMENT;
47+
default:
48+
return AlterOperation.SET_TABLE_OPTION;
49+
}
50+
}
51+
return super.getOperation();
52+
}
53+
54+
@Override
55+
public String getEngineOption() {
56+
return structuredTableOption != null
57+
&& structuredTableOption.getKind() == TableOption.Kind.ENGINE
58+
? structuredTableOption.getValue()
59+
: super.getEngineOption();
60+
}
61+
62+
@Override
63+
public void setEngineOption(String value) {
64+
if (structuredTableOption != null
65+
&& structuredTableOption.getKind() == TableOption.Kind.ENGINE) {
66+
structuredTableOption.setValue(value);
67+
}
68+
super.setEngineOption(value);
69+
}
70+
71+
@Override
72+
public int getKeyBlockSize() {
73+
return structuredTableOption != null
74+
&& structuredTableOption.getKind() == TableOption.Kind.KEY_BLOCK_SIZE
75+
? Integer.parseInt(structuredTableOption.getValue())
76+
: super.getKeyBlockSize();
77+
}
78+
79+
@Override
80+
public void setKeyBlockSize(int value) {
81+
if (structuredTableOption != null
82+
&& structuredTableOption.getKind() == TableOption.Kind.KEY_BLOCK_SIZE) {
83+
structuredTableOption.setValue(Integer.toString(value));
84+
}
85+
super.setKeyBlockSize(value);
86+
}
87+
88+
@Override
89+
public String getCommentText() {
90+
return structuredTableOption != null
91+
&& structuredTableOption.getKind() == TableOption.Kind.COMMENT
92+
? structuredTableOption.getValue()
93+
: super.getCommentText();
94+
}
95+
96+
@Override
97+
public void setCommentText(String value) {
98+
if (structuredTableOption != null
99+
&& structuredTableOption.getKind() == TableOption.Kind.COMMENT) {
100+
structuredTableOption.setValue(value);
101+
}
102+
super.setCommentText(value);
103+
}
104+
35105
@Override
36106
public String getTableOption() {
37107
return structuredTableOption == null ? super.getTableOption()
@@ -60,6 +130,10 @@ public void setUseEqual(boolean useEqual) {
60130

61131
@Override
62132
protected void appendBody(StringBuilder b) {
133+
if (structuredTableOption != null) {
134+
b.append(structuredTableOption);
135+
return;
136+
}
63137
switch (getOperation()) {
64138
case SET_TABLE_OPTION:
65139
b.append(getTableOption());

0 commit comments

Comments
 (0)