1 | |
package liquibase.statement.core; |
2 | |
|
3 | |
import java.util.Arrays; |
4 | |
import java.util.HashSet; |
5 | |
import java.util.Set; |
6 | |
|
7 | |
import liquibase.statement.AbstractSqlStatement; |
8 | |
import liquibase.statement.AutoIncrementConstraint; |
9 | |
import liquibase.statement.ColumnConstraint; |
10 | |
import liquibase.statement.NotNullConstraint; |
11 | |
import liquibase.statement.PrimaryKeyConstraint; |
12 | |
import liquibase.statement.UniqueConstraint; |
13 | |
|
14 | |
public class AddColumnStatement extends AbstractSqlStatement { |
15 | |
|
16 | |
private String schemaName; |
17 | |
private String tableName; |
18 | |
private String columnName; |
19 | |
private String columnType; |
20 | |
private Object defaultValue; |
21 | 182 | private Set<ColumnConstraint> constraints = new HashSet<ColumnConstraint>(); |
22 | |
|
23 | |
public AddColumnStatement(String schemaName, String tableName, String columnName, String columnType, |
24 | 182 | Object defaultValue, ColumnConstraint... constraints) { |
25 | 182 | this.schemaName = schemaName; |
26 | 182 | this.tableName = tableName; |
27 | 182 | this.columnName = columnName; |
28 | 182 | this.columnType = columnType; |
29 | 182 | this.defaultValue = defaultValue; |
30 | 182 | if (constraints != null) { |
31 | 182 | this.constraints.addAll(Arrays.asList(constraints)); |
32 | |
} |
33 | 182 | } |
34 | |
|
35 | |
public String getSchemaName() { |
36 | 60 | return schemaName; |
37 | |
} |
38 | |
|
39 | |
public String getTableName() { |
40 | 101 | return tableName; |
41 | |
} |
42 | |
|
43 | |
public String getColumnName() { |
44 | 101 | return columnName; |
45 | |
} |
46 | |
|
47 | |
public String getColumnType() { |
48 | 101 | return columnType; |
49 | |
} |
50 | |
|
51 | |
public Set<ColumnConstraint> getConstraints() { |
52 | 323 | return constraints; |
53 | |
} |
54 | |
|
55 | |
public boolean isAutoIncrement() { |
56 | 38 | for (ColumnConstraint constraint : getConstraints()) { |
57 | 61 | if (constraint instanceof AutoIncrementConstraint) { |
58 | 35 | return true; |
59 | |
} |
60 | |
} |
61 | 3 | return false; |
62 | |
} |
63 | |
|
64 | |
public boolean isPrimaryKey() { |
65 | 210 | for (ColumnConstraint constraint : getConstraints()) { |
66 | 204 | if (constraint instanceof PrimaryKeyConstraint) { |
67 | 72 | return true; |
68 | |
} |
69 | |
} |
70 | 138 | return false; |
71 | |
} |
72 | |
|
73 | |
public boolean isNullable() { |
74 | 60 | if (isPrimaryKey()) { |
75 | 0 | return false; |
76 | |
} |
77 | 60 | for (ColumnConstraint constraint : getConstraints()) { |
78 | 30 | if (constraint instanceof NotNullConstraint) { |
79 | 30 | return false; |
80 | |
} |
81 | |
} |
82 | 30 | return true; |
83 | |
} |
84 | |
|
85 | |
public boolean isUnique() { |
86 | 0 | for (ColumnConstraint constraint : getConstraints()) { |
87 | 0 | if (constraint instanceof UniqueConstraint) { |
88 | 0 | return true; |
89 | |
} |
90 | |
} |
91 | 0 | return false; |
92 | |
} |
93 | |
|
94 | |
public Object getDefaultValue() { |
95 | 0 | return defaultValue; |
96 | |
} |
97 | |
} |