01: package liquibase.change;
02:
03: import liquibase.database.Database;
04: import liquibase.database.sql.DropPrimaryKeyStatement;
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 primary key.
17: */
18: public class DropPrimaryKeyChange extends AbstractChange {
19: private String schemaName;
20: private String tableName;
21: private String constraintName;
22:
23: public DropPrimaryKeyChange() {
24: super ("dropPrimaryKey", "Drop Primary Key");
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 DropPrimaryKeyStatement(
54: getSchemaName() == null ? database
55: .getDefaultSchemaName() : getSchemaName(),
56: getTableName(), getConstraintName()), };
57: }
58:
59: public String getConfirmationMessage() {
60: return "Primary key dropped from " + getTableName();
61: }
62:
63: public Element createNode(Document currentChangeLogFileDOM) {
64: Element node = currentChangeLogFileDOM
65: .createElement(getTagName());
66: if (getSchemaName() != null) {
67: node.setAttribute("schemaName", getSchemaName());
68: }
69:
70: node.setAttribute("tableName", getTableName());
71: if (getConstraintName() != null) {
72: node.setAttribute("constraintName", getConstraintName());
73: }
74: return node;
75: }
76:
77: public Set<DatabaseObject> getAffectedDatabaseObjects() {
78:
79: Set<DatabaseObject> dbObjects = new HashSet<DatabaseObject>();
80:
81: Table table = new Table(getTableName());
82: dbObjects.add(table);
83:
84: return dbObjects;
85:
86: }
87:
88: }
|