01: package liquibase.database.sql;
02:
03: import liquibase.database.Database;
04: import liquibase.database.MSSQLDatabase;
05: import liquibase.database.MySQLDatabase;
06: import liquibase.database.OracleDatabase;
07: import liquibase.exception.StatementNotSupportedOnDatabaseException;
08:
09: public class DropIndexStatement implements SqlStatement {
10:
11: private String indexName;
12: private String tableSchemaName;
13: private String tableName;
14:
15: public DropIndexStatement(String indexName, String tableSchemaName,
16: String tableName) {
17: this .tableSchemaName = tableSchemaName;
18: this .indexName = indexName;
19: this .tableName = tableName;
20: }
21:
22: public String getTableSchemaName() {
23: return tableSchemaName;
24: }
25:
26: public String getIndexName() {
27: return indexName;
28: }
29:
30: public String getTableName() {
31: return tableName;
32: }
33:
34: public String getSqlStatement(Database database)
35: throws StatementNotSupportedOnDatabaseException {
36: String schemaName = getTableSchemaName();
37:
38: if (schemaName != null && !database.supportsSchemas()) {
39: throw new StatementNotSupportedOnDatabaseException(
40: "Database does not support schemas", this , database);
41: }
42: if (database instanceof MySQLDatabase) {
43: if (getTableName() == null) {
44: throw new StatementNotSupportedOnDatabaseException(
45: "tableName is required", this , database);
46: }
47: return "DROP INDEX "
48: + getIndexName()
49: + " ON "
50: + database.escapeTableName(schemaName,
51: getTableName());
52: } else if (database instanceof MSSQLDatabase) {
53: if (getTableName() == null) {
54: throw new StatementNotSupportedOnDatabaseException(
55: "tableName is required", this , database);
56: }
57: return "DROP INDEX "
58: + database.escapeTableName(schemaName,
59: getTableName()) + "." + getIndexName();
60: }
61:
62: return "DROP INDEX " + getIndexName();
63: }
64:
65: public String getEndDelimiter(Database database) {
66: return ";";
67: }
68:
69: public boolean supportsDatabase(Database database) {
70: return true;
71: }
72: }
|