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