01: package liquibase.change;
02:
03: import liquibase.database.Database;
04: import liquibase.database.sql.DropDefaultValueStatement;
05: import liquibase.database.sql.SqlStatement;
06: import liquibase.database.structure.Column;
07: import liquibase.database.structure.DatabaseObject;
08: import liquibase.database.structure.Table;
09: import liquibase.exception.UnsupportedChangeException;
10: import org.w3c.dom.Document;
11: import org.w3c.dom.Element;
12:
13: import java.util.Arrays;
14: import java.util.HashSet;
15: import java.util.Set;
16:
17: /**
18: * Removes the default value from an existing column.
19: */
20: public class DropDefaultValueChange extends AbstractChange {
21:
22: private String schemaName;
23: private String tableName;
24: private String columnName;
25:
26: public DropDefaultValueChange() {
27: super ("dropDefaultValue", "Drop Default Value");
28: }
29:
30: public String getSchemaName() {
31: return schemaName;
32: }
33:
34: public void setSchemaName(String schemaName) {
35: this .schemaName = schemaName;
36: }
37:
38: public String getTableName() {
39: return tableName;
40: }
41:
42: public void setTableName(String tableName) {
43: this .tableName = tableName;
44: }
45:
46: public String getColumnName() {
47: return columnName;
48: }
49:
50: public void setColumnName(String columnName) {
51: this .columnName = columnName;
52: }
53:
54: public SqlStatement[] generateStatements(Database database)
55: throws UnsupportedChangeException {
56:
57: return new SqlStatement[] { new DropDefaultValueStatement(
58: getSchemaName() == null ? database
59: .getDefaultSchemaName() : getSchemaName(),
60: getTableName(), getColumnName()), };
61: }
62:
63: public String getConfirmationMessage() {
64: return "Default value dropped from " + getTableName() + "."
65: + getColumnName();
66: }
67:
68: public Element createNode(Document currentChangeLogFileDOM) {
69: Element node = currentChangeLogFileDOM
70: .createElement(getTagName());
71:
72: if (getSchemaName() != null) {
73: node.setAttribute("schemaName", getSchemaName());
74: }
75:
76: node.setAttribute("tableName", getTableName());
77: node.setAttribute("columnName", getColumnName());
78:
79: return node;
80: }
81:
82: public Set<DatabaseObject> getAffectedDatabaseObjects() {
83: Column column = new Column();
84:
85: Table table = new Table(getTableName());
86: column.setTable(table);
87:
88: column.setName(columnName);
89:
90: return new HashSet<DatabaseObject>(Arrays.asList(table, column));
91:
92: }
93:
94: }
|