01: package liquibase.change;
02:
03: import liquibase.database.Database;
04: import liquibase.database.sql.DropTableStatement;
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.Arrays;
13: import java.util.HashSet;
14: import java.util.Set;
15:
16: /**
17: * Drops an existing table.
18: */
19: public class DropTableChange extends AbstractChange {
20:
21: private String schemaName;
22: private String tableName;
23: private Boolean cascadeConstraints;
24:
25: public DropTableChange() {
26: super ("dropTable", "Drop Table");
27: }
28:
29: public String getSchemaName() {
30: return schemaName;
31: }
32:
33: public void setSchemaName(String schemaName) {
34: this .schemaName = schemaName;
35: }
36:
37: public String getTableName() {
38: return tableName;
39: }
40:
41: public void setTableName(String tableName) {
42: this .tableName = tableName;
43: }
44:
45: public Boolean isCascadeConstraints() {
46: return cascadeConstraints;
47: }
48:
49: public void setCascadeConstraints(Boolean cascadeConstraints) {
50: this .cascadeConstraints = cascadeConstraints;
51: }
52:
53: public SqlStatement[] generateStatements(Database database)
54: throws UnsupportedChangeException {
55: boolean constraints = false;
56: if (isCascadeConstraints() != null) {
57: constraints = isCascadeConstraints();
58: }
59:
60: return new SqlStatement[] { new DropTableStatement(
61: getSchemaName() == null ? database
62: .getDefaultSchemaName() : getSchemaName(),
63: getTableName(), constraints) };
64: }
65:
66: public String getConfirmationMessage() {
67: return "Table " + getTableName() + " dropped";
68: }
69:
70: public Element createNode(Document currentChangeLogFileDOM) {
71: Element element = currentChangeLogFileDOM
72: .createElement("dropTable");
73: if (getSchemaName() != null) {
74: element.setAttribute("schemaName", getSchemaName());
75: }
76:
77: element.setAttribute("tableName", getTableName());
78:
79: if (isCascadeConstraints() != null) {
80: element.setAttribute("cascadeConstraints",
81: isCascadeConstraints().toString());
82: }
83:
84: return element;
85: }
86:
87: public Set<DatabaseObject> getAffectedDatabaseObjects() {
88: Table dbObject = new Table(getTableName());
89:
90: return new HashSet<DatabaseObject>(Arrays.asList(dbObject));
91: }
92:
93: }
|