1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.database.core.DB2Database; |
5 | |
import liquibase.database.structure.Column; |
6 | |
import liquibase.database.structure.Table; |
7 | |
import liquibase.sql.Sql; |
8 | |
import liquibase.sql.UnparsedSql; |
9 | |
import liquibase.sqlgenerator.SqlGeneratorChain; |
10 | |
import liquibase.statement.core.AddAutoIncrementStatement; |
11 | |
|
12 | 77 | public class AddAutoIncrementGeneratorDB2 extends AddAutoIncrementGenerator { |
13 | |
|
14 | |
@Override |
15 | |
public int getPriority() { |
16 | 6 | return PRIORITY_DATABASE; |
17 | |
} |
18 | |
|
19 | |
@Override |
20 | |
public boolean supports(AddAutoIncrementStatement statement, Database database) { |
21 | 61 | return database instanceof DB2Database; |
22 | |
} |
23 | |
|
24 | |
@Override |
25 | |
public Sql[] generateSql(AddAutoIncrementStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { |
26 | 0 | return new Sql[] { new UnparsedSql("ALTER TABLE " |
27 | |
+ database.escapeTableName(statement.getSchemaName(), statement.getTableName()) |
28 | |
+ " ALTER COLUMN " |
29 | |
+ database.escapeColumnName(statement.getSchemaName(), statement.getTableName(), |
30 | |
statement.getColumnName()) + " SET GENERATED ALWAYS AS IDENTITY", new Column().setTable( |
31 | |
new Table(statement.getTableName()).setSchema(statement.getSchemaName())).setName( |
32 | |
statement.getColumnName())) }; |
33 | |
} |
34 | |
} |