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 private Set<ColumnConstraint> constraints = new HashSet<ColumnConstraint>(); 22 23 public AddColumnStatement(String schemaName, String tableName, String columnName, String columnType, 24 Object defaultValue, ColumnConstraint... constraints) { 25 this.schemaName = schemaName; 26 this.tableName = tableName; 27 this.columnName = columnName; 28 this.columnType = columnType; 29 this.defaultValue = defaultValue; 30 if (constraints != null) { 31 this.constraints.addAll(Arrays.asList(constraints)); 32 } 33 } 34 35 public String getSchemaName() { 36 return schemaName; 37 } 38 39 public String getTableName() { 40 return tableName; 41 } 42 43 public String getColumnName() { 44 return columnName; 45 } 46 47 public String getColumnType() { 48 return columnType; 49 } 50 51 public Set<ColumnConstraint> getConstraints() { 52 return constraints; 53 } 54 55 public boolean isAutoIncrement() { 56 for (ColumnConstraint constraint : getConstraints()) { 57 if (constraint instanceof AutoIncrementConstraint) { 58 return true; 59 } 60 } 61 return false; 62 } 63 64 public boolean isPrimaryKey() { 65 for (ColumnConstraint constraint : getConstraints()) { 66 if (constraint instanceof PrimaryKeyConstraint) { 67 return true; 68 } 69 } 70 return false; 71 } 72 73 public boolean isNullable() { 74 if (isPrimaryKey()) { 75 return false; 76 } 77 for (ColumnConstraint constraint : getConstraints()) { 78 if (constraint instanceof NotNullConstraint) { 79 return false; 80 } 81 } 82 return true; 83 } 84 85 public boolean isUnique() { 86 for (ColumnConstraint constraint : getConstraints()) { 87 if (constraint instanceof UniqueConstraint) { 88 return true; 89 } 90 } 91 return false; 92 } 93 94 public Object getDefaultValue() { 95 return defaultValue; 96 } 97 }