1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.database.typeconversion.TypeConverterFactory; |
5 | |
import liquibase.database.core.OracleDatabase; |
6 | |
import liquibase.database.structure.Column; |
7 | |
import liquibase.database.structure.Table; |
8 | |
import liquibase.sql.Sql; |
9 | |
import liquibase.sql.UnparsedSql; |
10 | |
import liquibase.sqlgenerator.SqlGeneratorChain; |
11 | |
import liquibase.statement.core.AddDefaultValueStatement; |
12 | |
|
13 | 75 | public class AddDefaultValueGeneratorOracle extends AddDefaultValueGenerator { |
14 | |
@Override |
15 | |
public int getPriority() { |
16 | 5 | return PRIORITY_DATABASE; |
17 | |
} |
18 | |
|
19 | |
@Override |
20 | |
public boolean supports(AddDefaultValueStatement statement, Database database) { |
21 | 65 | return database instanceof OracleDatabase; |
22 | |
} |
23 | |
|
24 | |
@Override |
25 | |
public Sql[] generateSql(AddDefaultValueStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { |
26 | 0 | Object defaultValue = statement.getDefaultValue(); |
27 | 0 | return new Sql[] { new UnparsedSql("ALTER TABLE " |
28 | |
+ database.escapeTableName(statement.getSchemaName(), statement.getTableName()) |
29 | |
+ " MODIFY " |
30 | |
+ database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), |
31 | |
statement.getColumnName()) |
32 | |
+ " DEFAULT " |
33 | |
+ TypeConverterFactory.getInstance().findTypeConverter(database).getDataType(defaultValue) |
34 | |
.convertObjectToString(defaultValue, database), new Column().setTable( |
35 | |
new Table(statement.getTableName()).setSchema(statement.getSchemaName())).setName( |
36 | |
statement.getColumnName())) }; |
37 | |
} |
38 | |
} |