Skip to content

Commit cbddd24

Browse files
committed
Align access DDL field layout and simplify trigger rendering
1 parent 1696af3 commit cbddd24

12 files changed

Lines changed: 72 additions & 116 deletions

File tree

src/main/java/net/sf/jsqlparser/statement/create/trigger/CreateTrigger.java

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public enum Order {
3434
FOLLOWS, PRECEDES
3535
}
3636

37-
private TriggerDefiner definer;
38-
private Table trigger;
39-
private Timing timing;
40-
4137
public enum Orientation {
4238
ROW, STATEMENT
4339
}
@@ -46,6 +42,23 @@ public enum ExecuteKeyword {
4642
}
4743

4844
private List<TriggerEvent> events = new ArrayList<>();
45+
private TriggerDefiner definer;
46+
private Table trigger;
47+
private Timing timing;
48+
private boolean orReplace;
49+
private boolean constraint;
50+
private Table referencedTable;
51+
private Orientation orientation;
52+
private boolean useEach;
53+
private Expression whenExpression;
54+
private ExecuteKeyword executeKeyword = ExecuteKeyword.FUNCTION;
55+
private Function routine;
56+
private Table table;
57+
private Order order;
58+
private Table otherTrigger;
59+
private Statement body;
60+
private ConstraintAttributes constraintAttributes = new ConstraintAttributes();
61+
private List<TransitionRelation> transitionRelations = new ArrayList<>();
4962

5063
public List<TriggerEvent> getEvents() {
5164
return events;
@@ -55,8 +68,6 @@ public void setEvents(List<TriggerEvent> events) {
5568
this.events = events;
5669
}
5770

58-
private boolean orReplace;
59-
6071
public boolean isOrReplace() {
6172
return orReplace;
6273
}
@@ -65,8 +76,6 @@ public void setOrReplace(boolean orReplace) {
6576
this.orReplace = orReplace;
6677
}
6778

68-
private boolean constraint;
69-
7079
public boolean isConstraint() {
7180
return constraint;
7281
}
@@ -75,8 +84,6 @@ public void setConstraint(boolean constraint) {
7584
this.constraint = constraint;
7685
}
7786

78-
private Table referencedTable;
79-
8087
public Table getReferencedTable() {
8188
return referencedTable;
8289
}
@@ -85,8 +92,6 @@ public void setReferencedTable(Table referencedTable) {
8592
this.referencedTable = referencedTable;
8693
}
8794

88-
private ConstraintAttributes constraintAttributes = new ConstraintAttributes();
89-
9095
public ConstraintAttributes getConstraintAttributes() {
9196
return constraintAttributes;
9297
}
@@ -95,8 +100,6 @@ public void setConstraintAttributes(ConstraintAttributes constraintAttributes) {
95100
this.constraintAttributes = constraintAttributes;
96101
}
97102

98-
private List<TransitionRelation> transitionRelations = new ArrayList<>();
99-
100103
public List<TransitionRelation> getTransitionRelations() {
101104
return transitionRelations;
102105
}
@@ -105,8 +108,6 @@ public void setTransitionRelations(List<TransitionRelation> transitionRelations)
105108
this.transitionRelations = transitionRelations;
106109
}
107110

108-
private Orientation orientation;
109-
110111
public Orientation getOrientation() {
111112
return orientation;
112113
}
@@ -115,8 +116,6 @@ public void setOrientation(Orientation orientation) {
115116
this.orientation = orientation;
116117
}
117118

118-
private boolean useEach;
119-
120119
public boolean isUseEach() {
121120
return useEach;
122121
}
@@ -125,8 +124,6 @@ public void setUseEach(boolean useEach) {
125124
this.useEach = useEach;
126125
}
127126

128-
private Expression whenExpression;
129-
130127
public Expression getWhenExpression() {
131128
return whenExpression;
132129
}
@@ -135,8 +132,6 @@ public void setWhenExpression(Expression whenExpression) {
135132
this.whenExpression = whenExpression;
136133
}
137134

138-
private ExecuteKeyword executeKeyword = ExecuteKeyword.FUNCTION;
139-
140135
public ExecuteKeyword getExecuteKeyword() {
141136
return executeKeyword;
142137
}
@@ -145,8 +140,6 @@ public void setExecuteKeyword(ExecuteKeyword executeKeyword) {
145140
this.executeKeyword = executeKeyword;
146141
}
147142

148-
private Function routine;
149-
150143
public Function getRoutine() {
151144
return routine;
152145
}
@@ -155,11 +148,6 @@ public void setRoutine(Function routine) {
155148
this.routine = routine;
156149
}
157150

158-
private Table table;
159-
private Order order;
160-
private Table otherTrigger;
161-
private Statement body;
162-
163151
public TriggerDefiner getDefiner() {
164152
return definer;
165153
}
@@ -257,6 +245,18 @@ public void appendTo(StringBuilder sql, Consumer<Expression> visitor) {
257245
sql.append(mysqlSql());
258246
return;
259247
}
248+
appendPostgreSqlHeader(sql, visitor);
249+
appendPostgreSqlTarget(sql);
250+
if (whenExpression != null) {
251+
sql.append(" WHEN (");
252+
visitor.accept(whenExpression);
253+
sql.append(')');
254+
}
255+
sql.append(" EXECUTE ").append(executeKeyword).append(' ');
256+
visitor.accept(routine);
257+
}
258+
259+
private void appendPostgreSqlHeader(StringBuilder sql, Consumer<Expression> visitor) {
260260
sql.append("CREATE ");
261261
if (orReplace) {
262262
sql.append("OR REPLACE ");
@@ -272,6 +272,9 @@ public void appendTo(StringBuilder sql, Consumer<Expression> visitor) {
272272
}
273273
events.get(i).appendTo(sql, visitor);
274274
}
275+
}
276+
277+
private void appendPostgreSqlTarget(StringBuilder sql) {
275278
sql.append(" ON ").append(table);
276279
if (referencedTable != null) {
277280
sql.append(" FROM ").append(referencedTable);
@@ -286,13 +289,6 @@ public void appendTo(StringBuilder sql, Consumer<Expression> visitor) {
286289
if (orientation != null) {
287290
sql.append(" FOR ").append(useEach ? "EACH " : "").append(orientation);
288291
}
289-
if (whenExpression != null) {
290-
sql.append(" WHEN (");
291-
visitor.accept(whenExpression);
292-
sql.append(')');
293-
}
294-
sql.append(" EXECUTE ").append(executeKeyword).append(' ');
295-
visitor.accept(routine);
296292
}
297293

298294
@Override

src/main/java/net/sf/jsqlparser/statement/create/trigger/TransitionRelation.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public enum Image {
1717
}
1818

1919
private Image image;
20+
private String name;
21+
private boolean useAs;
2022

2123
public Image getImage() {
2224
return image;
@@ -26,8 +28,6 @@ public void setImage(Image image) {
2628
this.image = image;
2729
}
2830

29-
private String name;
30-
3131
public String getName() {
3232
return name;
3333
}
@@ -36,8 +36,6 @@ public void setName(String name) {
3636
this.name = name;
3737
}
3838

39-
private boolean useAs;
40-
4139
public boolean isUseAs() {
4240
return useAs;
4341
}

src/main/java/net/sf/jsqlparser/statement/create/trigger/TriggerEvent.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
public class TriggerEvent implements Serializable {
1919
private CreateTrigger.Event event;
20+
private ExpressionList<Column> columns;
2021

2122
public CreateTrigger.Event getEvent() {
2223
return event;
@@ -26,8 +27,6 @@ public void setEvent(CreateTrigger.Event event) {
2627
this.event = event;
2728
}
2829

29-
private ExpressionList<Column> columns;
30-
3130
public ExpressionList<Column> getColumns() {
3231
return columns;
3332
}

src/main/java/net/sf/jsqlparser/statement/grant/AlterDefaultPrivileges.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public enum RoleKeyword {
2121
}
2222

2323
private RoleKeyword roleKeyword;
24+
private List<String> roles;
25+
private List<String> schemas;
26+
private Grant grant;
27+
private Revoke revoke;
2428

2529
public RoleKeyword getRoleKeyword() {
2630
return roleKeyword;
@@ -30,8 +34,6 @@ public void setRoleKeyword(RoleKeyword roleKeyword) {
3034
this.roleKeyword = roleKeyword;
3135
}
3236

33-
private List<String> roles;
34-
3537
public List<String> getRoles() {
3638
return roles;
3739
}
@@ -40,8 +42,6 @@ public void setRoles(List<String> roles) {
4042
this.roles = roles;
4143
}
4244

43-
private List<String> schemas;
44-
4545
public List<String> getSchemas() {
4646
return schemas;
4747
}
@@ -50,8 +50,6 @@ public void setSchemas(List<String> schemas) {
5050
this.schemas = schemas;
5151
}
5252

53-
private Grant grant;
54-
5553
public Grant getGrant() {
5654
return grant;
5755
}
@@ -60,8 +58,6 @@ public void setGrant(Grant grant) {
6058
this.grant = grant;
6159
}
6260

63-
private Revoke revoke;
64-
6561
public Revoke getRevoke() {
6662
return revoke;
6763
}

src/main/java/net/sf/jsqlparser/statement/grant/GrantOption.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public enum Value {
2020
}
2121

2222
private Kind kind;
23+
private Value value = Value.OPTION;
2324

2425
public Kind getKind() {
2526
return kind;
@@ -29,8 +30,6 @@ public void setKind(Kind kind) {
2930
this.kind = kind;
3031
}
3132

32-
private Value value = Value.OPTION;
33-
3433
public Value getValue() {
3534
return value;
3635
}

src/main/java/net/sf/jsqlparser/statement/grant/Privilege.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
import net.sf.jsqlparser.schema.Column;
1717

1818
public class Privilege implements Serializable {
19-
private String legacyName;
20-
2119
public enum Kind {
2220
ALL, SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, MAINTAIN, USAGE, CREATE, CONNECT, TEMPORARY, TEMP, EXECUTE, SET, ALTER_SYSTEM, ALTER, DROP
2321
}
2422

23+
private String legacyName;
2524
private Kind kind;
25+
private boolean usePrivileges;
26+
private ExpressionList<Column> columns;
2627

2728
public Kind getKind() {
2829
return kind;
@@ -32,8 +33,6 @@ public void setKind(Kind kind) {
3233
this.kind = kind;
3334
}
3435

35-
private boolean usePrivileges;
36-
3736
public boolean isUsePrivileges() {
3837
return usePrivileges;
3938
}
@@ -42,8 +41,6 @@ public void setUsePrivileges(boolean usePrivileges) {
4241
this.usePrivileges = usePrivileges;
4342
}
4443

45-
private ExpressionList<Column> columns;
46-
4744
public ExpressionList<Column> getColumns() {
4845
return columns;
4946
}

src/main/java/net/sf/jsqlparser/statement/grant/PrivilegeClause.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
/** Shared, editable GRANT/REVOKE payload. Null privileges denote role membership. */
2020
public class PrivilegeClause implements Serializable {
2121
private List<Privilege> privileges;
22+
private List<String> grantees;
23+
private String grantedBy;
24+
private List<String> roles = new ArrayList<>();
25+
private PrivilegeTarget target = new PrivilegeTarget();
2226

2327
public List<Privilege> getPrivileges() {
2428
return privileges;
@@ -28,8 +32,6 @@ public void setPrivileges(List<Privilege> privileges) {
2832
this.privileges = privileges;
2933
}
3034

31-
private List<String> roles = new ArrayList<>();
32-
3335
public List<String> getRoles() {
3436
return roles;
3537
}
@@ -38,8 +40,6 @@ public void setRoles(List<String> roles) {
3840
this.roles = roles;
3941
}
4042

41-
private PrivilegeTarget target = new PrivilegeTarget();
42-
4343
public PrivilegeTarget getTarget() {
4444
return target;
4545
}
@@ -48,8 +48,6 @@ public void setTarget(PrivilegeTarget target) {
4848
this.target = target;
4949
}
5050

51-
private List<String> grantees;
52-
5351
public List<String> getGrantees() {
5452
return grantees;
5553
}
@@ -58,8 +56,6 @@ public void setGrantees(List<String> grantees) {
5856
this.grantees = grantees;
5957
}
6058

61-
private String grantedBy;
62-
6359
public String getGrantedBy() {
6460
return grantedBy;
6561
}

0 commit comments

Comments
 (0)