01: package liquibase.change;
02:
03: import liquibase.database.Database;
04: import liquibase.database.sql.DropViewStatement;
05: import liquibase.database.sql.SqlStatement;
06: import liquibase.database.structure.DatabaseObject;
07: import liquibase.database.structure.View;
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 view.
18: */
19: public class DropViewChange extends AbstractChange {
20: private String schemaName;
21: private String viewName;
22:
23: public DropViewChange() {
24: super ("dropView", "Drop View");
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 getViewName() {
36: return viewName;
37: }
38:
39: public void setViewName(String viewName) {
40: this .viewName = viewName;
41: }
42:
43: public SqlStatement[] generateStatements(Database database)
44: throws UnsupportedChangeException {
45: return new SqlStatement[] { new DropViewStatement(
46: getSchemaName() == null ? database
47: .getDefaultSchemaName() : getSchemaName(),
48: getViewName()), };
49: }
50:
51: public String getConfirmationMessage() {
52: return "View " + getViewName() + " dropped";
53: }
54:
55: public Element createNode(Document currentChangeLogFileDOM) {
56: Element element = currentChangeLogFileDOM
57: .createElement("dropView");
58: if (getSchemaName() != null) {
59: element.setAttribute("schemaName", getSchemaName());
60: }
61: element.setAttribute("viewName", getViewName());
62:
63: return element;
64: }
65:
66: public Set<DatabaseObject> getAffectedDatabaseObjects() {
67: View dbObject = new View();
68: dbObject.setName(viewName);
69:
70: return new HashSet<DatabaseObject>(Arrays.asList(dbObject));
71: }
72:
73: }
|