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