01: package liquibase.database.sql;
02:
03: import liquibase.database.*;
04: import liquibase.exception.StatementNotSupportedOnDatabaseException;
05:
06: public class DropTableStatement implements SqlStatement {
07:
08: private String schemaName;
09: private String tableName;
10: private boolean cascadeConstraints;
11:
12: public DropTableStatement(String schemaName, String tableName,
13: boolean cascadeConstraints) {
14: this .schemaName = schemaName;
15: this .tableName = tableName;
16: this .cascadeConstraints = cascadeConstraints;
17: }
18:
19: public String getSchemaName() {
20: return schemaName;
21: }
22:
23: public String getTableName() {
24: return tableName;
25: }
26:
27: public boolean isCascadeConstraints() {
28: return cascadeConstraints;
29: }
30:
31: public String getSqlStatement(Database database)
32: throws StatementNotSupportedOnDatabaseException {
33: StringBuffer buffer = new StringBuffer();
34: buffer.append("DROP TABLE ").append(
35: database.escapeTableName(getSchemaName(),
36: getTableName()));
37: if (isCascadeConstraints()) {
38: if (database instanceof DerbyDatabase
39: || database instanceof DB2Database
40: || database instanceof MSSQLDatabase
41: || database instanceof FirebirdDatabase) {
42: throw new StatementNotSupportedOnDatabaseException(
43: "Database does not support drop with cascade",
44: this , database);
45: }
46: if (database instanceof OracleDatabase) {
47: buffer.append(" CASCADE CONSTRAINTS");
48: } else {
49: buffer.append(" CASCADE");
50: }
51: }
52:
53: return buffer.toString();
54:
55: }
56:
57: public String getEndDelimiter(Database database) {
58: return ";";
59: }
60:
61: public boolean supportsDatabase(Database database) {
62: return true;
63: }
64: }
|