01: package liquibase.database.sql;
02:
03: import liquibase.database.Database;
04: import liquibase.database.MaxDBDatabase;
05: import liquibase.database.MySQLDatabase;
06: import liquibase.exception.StatementNotSupportedOnDatabaseException;
07:
08: public class DropForeignKeyConstraintStatement implements SqlStatement {
09:
10: private String baseTableSchemaName;
11: private String baseTableName;
12: private String constraintName;
13:
14: public DropForeignKeyConstraintStatement(
15: String baseTableSchemaName, String baseTableName,
16: String constraintName) {
17: this .baseTableSchemaName = baseTableSchemaName;
18: this .baseTableName = baseTableName;
19: this .constraintName = constraintName;
20: }
21:
22: public String getBaseTableSchemaName() {
23: return baseTableSchemaName;
24: }
25:
26: public String getBaseTableName() {
27: return baseTableName;
28: }
29:
30: public String getConstraintName() {
31: return constraintName;
32: }
33:
34: public String getSqlStatement(Database database)
35: throws StatementNotSupportedOnDatabaseException {
36: if (getBaseTableSchemaName() != null
37: && !database.supportsSchemas()) {
38: throw new StatementNotSupportedOnDatabaseException(
39: "Database does not support schemas", this , database);
40: }
41:
42: if (database instanceof MySQLDatabase
43: || database instanceof MaxDBDatabase) {
44: return "ALTER TABLE "
45: + database.escapeTableName(
46: getBaseTableSchemaName(),
47: getBaseTableName()) + " DROP FOREIGN KEY "
48: + getConstraintName();
49: } else {
50: return "ALTER TABLE "
51: + database.escapeTableName(
52: getBaseTableSchemaName(),
53: getBaseTableName()) + " DROP CONSTRAINT "
54: + getConstraintName();
55: }
56: }
57:
58: public String getEndDelimiter(Database database) {
59: return ";";
60: }
61:
62: public boolean supportsDatabase(Database database) {
63: return true;
64: }
65: }
|