01: package liquibase.change;
02:
03: import liquibase.database.Database;
04: import liquibase.database.sql.DropIndexStatement;
05: import liquibase.database.sql.SqlStatement;
06: import liquibase.database.structure.DatabaseObject;
07: import liquibase.database.structure.Index;
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: * Drops an existing index.
19: */
20: public class DropIndexChange extends AbstractChange {
21:
22: private String schemaName;
23: private String indexName;
24: private String tableName;
25:
26: public DropIndexChange() {
27: super ("dropIndex", "Drop Index");
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 getIndexName() {
39: return indexName;
40: }
41:
42: public void setIndexName(String indexName) {
43: this .indexName = indexName;
44: }
45:
46: public String getTableName() {
47: return tableName;
48: }
49:
50: public void setTableName(String tableName) {
51: this .tableName = tableName;
52: }
53:
54: public SqlStatement[] generateStatements(Database database)
55: throws UnsupportedChangeException {
56: return new SqlStatement[] { new DropIndexStatement(
57: getIndexName(), getSchemaName() == null ? database
58: .getDefaultSchemaName() : getSchemaName(),
59: getTableName()) };
60: }
61:
62: public String getConfirmationMessage() {
63: return "Index " + getIndexName() + " dropped from table "
64: + getTableName();
65: }
66:
67: public Element createNode(Document currentChangeLogFileDOM) {
68: Element element = currentChangeLogFileDOM
69: .createElement("dropIndex");
70: if (getSchemaName() != null) {
71: element.setAttribute("schemaName", getSchemaName());
72: }
73:
74: element.setAttribute("indexName", getIndexName());
75: element.setAttribute("tableName", getTableName());
76:
77: return element;
78: }
79:
80: public Set<DatabaseObject> getAffectedDatabaseObjects() {
81: Index index = new Index();
82: index.setTable(new Table(tableName));
83: index.setName(indexName);
84:
85: Table table = new Table(getTableName());
86:
87: return new HashSet<DatabaseObject>(Arrays.asList(index, table));
88: }
89:
90: }
|