01: package liquibase.database.sql;
02:
03: import liquibase.database.*;
04: import liquibase.exception.StatementNotSupportedOnDatabaseException;
05:
06: public class DropDefaultValueStatement implements SqlStatement {
07:
08: private String schemaName;
09: private String tableName;
10: private String columnName;
11:
12: public DropDefaultValueStatement(String schemaName,
13: String tableName, String columnName) {
14: this .schemaName = schemaName;
15: this .tableName = tableName;
16: this .columnName = columnName;
17: }
18:
19: public String getSchemaName() {
20: return schemaName;
21: }
22:
23: public String getTableName() {
24: return tableName;
25: }
26:
27: public String getColumnName() {
28: return columnName;
29: }
30:
31: public String getSqlStatement(Database database)
32: throws StatementNotSupportedOnDatabaseException {
33: if (database instanceof MSSQLDatabase) {
34: //smarter drop return new SqlStatement[]{new RawSqlStatement("ALTER TABLE " + SqlUtil.escapeTableName(getTableName(), database) + " DROP CONSTRAINT select d.name from syscolumns c,sysobjects d, sysobjects t where c.id=t.id AND d.parent_obj=t.id AND d.type='D' AND t.type='U' AND c.name='"+getColumnName()+"' AND t.name='"+getTableName()+"'"),};
35: return "ALTER TABLE "
36: + database.escapeTableName(getSchemaName(),
37: getTableName())
38: + " DROP CONSTRAINT "
39: + ((MSSQLDatabase) database)
40: .generateDefaultConstraintName(
41: getTableName(), getColumnName());
42: } else if (database instanceof MySQLDatabase) {
43: return "ALTER TABLE "
44: + database.escapeTableName(getSchemaName(),
45: getTableName()) + " ALTER "
46: + database.escapeColumnName(getColumnName())
47: + " DROP DEFAULT";
48: } else if (database instanceof OracleDatabase) {
49: return "ALTER TABLE "
50: + database.escapeTableName(getSchemaName(),
51: getTableName()) + " MODIFY "
52: + database.escapeColumnName(getColumnName())
53: + " DEFAULT NULL";
54: } else if (database instanceof DerbyDatabase) {
55: return "ALTER TABLE "
56: + database.escapeTableName(getSchemaName(),
57: getTableName()) + " ALTER COLUMN "
58: + database.escapeColumnName(getColumnName())
59: + " WITH DEFAULT NULL";
60: } else if (database instanceof MaxDBDatabase) {
61: return "ALTER TABLE "
62: + database.escapeTableName(getSchemaName(),
63: getTableName()) + " COLUMN "
64: + database.escapeColumnName(getColumnName())
65: + " DROP DEFAULT";
66: }
67:
68: return "ALTER TABLE "
69: + database.escapeTableName(getSchemaName(),
70: getTableName()) + " ALTER COLUMN "
71: + database.escapeColumnName(getColumnName())
72: + " SET DEFAULT NULL";
73: }
74:
75: public String getEndDelimiter(Database database) {
76: return ";";
77: }
78:
79: public boolean supportsDatabase(Database database) {
80: return true;
81: }
82: }
|