01: package liquibase.database.sql;
02:
03: import liquibase.database.Database;
04: import liquibase.database.FirebirdDatabase;
05: import liquibase.database.MSSQLDatabase;
06: import liquibase.database.PostgresDatabase;
07: import liquibase.exception.StatementNotSupportedOnDatabaseException;
08:
09: public class DropPrimaryKeyStatement implements SqlStatement {
10:
11: private String schemaName;
12: private String tableName;
13: private String constraintName;
14:
15: public DropPrimaryKeyStatement(String schemaName, String tableName,
16: String constraintName) {
17: this .schemaName = schemaName;
18: this .tableName = tableName;
19: this .constraintName = constraintName;
20: }
21:
22: public String getSchemaName() {
23: return schemaName;
24: }
25:
26: public String getTableName() {
27: return tableName;
28: }
29:
30: public String getConstraintName() {
31: return constraintName;
32: }
33:
34: public String getSqlStatement(Database database)
35: throws StatementNotSupportedOnDatabaseException {
36: if (getConstraintName() == null) {
37: if (database instanceof MSSQLDatabase
38: || database instanceof PostgresDatabase
39: || database instanceof FirebirdDatabase) {
40: throw new StatementNotSupportedOnDatabaseException(
41: "Database requires a constraint name to drop the primary key",
42: this , database);
43: }
44: }
45:
46: if (database instanceof MSSQLDatabase) {
47: return "ALTER TABLE "
48: + database.escapeTableName(getSchemaName(),
49: getTableName()) + " DROP CONSTRAINT "
50: + getConstraintName();
51: } else if (database instanceof PostgresDatabase) {
52: return "ALTER TABLE "
53: + database.escapeTableName(getSchemaName(),
54: getTableName()) + " DROP CONSTRAINT "
55: + getConstraintName();
56: } else if (database instanceof FirebirdDatabase) {
57: return "ALTER TABLE "
58: + database.escapeTableName(getSchemaName(),
59: getTableName()) + " DROP CONSTRAINT "
60: + getConstraintName();
61: }
62:
63: return "ALTER TABLE "
64: + database.escapeTableName(getSchemaName(),
65: getTableName()) + " DROP PRIMARY KEY";
66: }
67:
68: public String getEndDelimiter(Database database) {
69: return ";";
70: }
71:
72: public boolean supportsDatabase(Database database) {
73: return true;
74: }
75: }
|