-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
AddColumnStatement.java
227 lines (186 loc) · 6.24 KB
/
AddColumnStatement.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package liquibase.statement.core;
import liquibase.statement.*;
import java.util.*;
public class AddColumnStatement extends AbstractSqlStatement {
private String catalogName;
private String schemaName;
private String tableName;
private String columnName;
private String columnType;
private Object defaultValue;
private String defaultValueConstraintName;
private String remarks;
private String addAfterColumn;
private String addBeforeColumn;
private Integer addAtPosition;
private Boolean computed;
private Set<ColumnConstraint> constraints = new HashSet<>();
private List<AddColumnStatement> columns = new ArrayList<>();
public AddColumnStatement(String catalogName, String schemaName, String tableName, String columnName, String columnType, Object defaultValue, ColumnConstraint... constraints) {
this.catalogName = catalogName;
this.schemaName = schemaName;
this.tableName = tableName;
this.columnName = columnName;
this.columnType = columnType;
this.defaultValue = defaultValue;
if (constraints != null) {
this.constraints.addAll(Arrays.asList(constraints));
}
}
public AddColumnStatement(String catalogName, String schemaName, String tableName, String columnName, String columnType, Object defaultValue, String remarks,ColumnConstraint... constraints) {
this(catalogName,schemaName,tableName,columnName,columnType,defaultValue,constraints);
this.remarks = remarks;
}
public AddColumnStatement(List<AddColumnStatement> columns) {
this.columns.addAll(columns);
}
public AddColumnStatement(AddColumnStatement... columns) {
this(Arrays.asList(columns));
}
public boolean isMultiple() {
return !columns.isEmpty();
}
public List<AddColumnStatement> getColumns() {
return columns;
}
public String getCatalogName() {
return catalogName;
}
public String getSchemaName() {
return schemaName;
}
public String getTableName() {
return tableName;
}
public String getColumnName() {
return columnName;
}
public String getColumnType() {
return columnType;
}
public String getRemarks() {
return remarks;
}
public Set<ColumnConstraint> getConstraints() {
return constraints;
}
public boolean isAutoIncrement() {
for (ColumnConstraint constraint : getConstraints()) {
if (constraint instanceof AutoIncrementConstraint) {
return true;
}
}
return false;
}
public AutoIncrementConstraint getAutoIncrementConstraint() {
AutoIncrementConstraint autoIncrementConstraint = null;
for (ColumnConstraint constraint : getConstraints()) {
if (constraint instanceof AutoIncrementConstraint) {
autoIncrementConstraint = (AutoIncrementConstraint) constraint;
break;
}
}
return autoIncrementConstraint;
}
public boolean isPrimaryKey() {
for (ColumnConstraint constraint : getConstraints()) {
if (constraint instanceof PrimaryKeyConstraint) {
return true;
}
}
return false;
}
public boolean isNullable() {
if (isPrimaryKey()) {
return false;
}
for (ColumnConstraint constraint : getConstraints()) {
if (constraint instanceof NotNullConstraint) {
return false;
}
}
return true;
}
public boolean shouldValidateNullable() {
if (isPrimaryKey()) {
return false;
}
for (ColumnConstraint constraint : getConstraints()) {
if (constraint instanceof NotNullConstraint) {
if (!((NotNullConstraint) constraint).shouldValidateNullable()) {
return false;
}
}
}
return true;
}
public boolean shouldValidateUnique() {
for (ColumnConstraint constraint : getConstraints()) {
if (constraint instanceof UniqueConstraint) {
if (!((UniqueConstraint) constraint).shouldValidateUnique()) {
return false;
}
}
}
return true;
}
public boolean shouldValidatePrimaryKey() {
for (ColumnConstraint constraint : getConstraints()) {
if (constraint instanceof PrimaryKeyConstraint) {
if (!((PrimaryKeyConstraint) constraint).shouldValidatePrimaryKey()) {
return false;
}
}
}
return true;
}
public boolean isUnique() {
for (ColumnConstraint constraint : getConstraints()) {
if (constraint instanceof UniqueConstraint) {
return true;
}
}
return false;
}
public String getUniqueStatementName() {
for (ColumnConstraint constraint : getConstraints()) {
if (constraint instanceof UniqueConstraint) {
return ((UniqueConstraint) constraint).getConstraintName();
}
}
return null;
}
public Object getDefaultValue() {
return defaultValue;
}
public String getAddAfterColumn() {
return addAfterColumn;
}
public void setAddAfterColumn(String addAfterColumn) {
this.addAfterColumn = addAfterColumn;
}
public String getAddBeforeColumn() {
return addBeforeColumn;
}
public void setAddBeforeColumn(String addBeforeColumn) {
this.addBeforeColumn = addBeforeColumn;
}
public Integer getAddAtPosition() {
return addAtPosition;
}
public void setAddAtPosition(Integer addAtPosition) {
this.addAtPosition = addAtPosition;
}
public String getDefaultValueConstraintName() {
return defaultValueConstraintName;
}
public void setDefaultValueConstraintName(String defaultValueConstraintName) {
this.defaultValueConstraintName = defaultValueConstraintName;
}
public Boolean getComputed() {
return computed;
}
public void setComputed(Boolean computed) {
this.computed = computed;
}
}