1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.database.core.DB2Database; |
5 | |
import liquibase.exception.DatabaseException; |
6 | |
import liquibase.exception.ValidationErrors; |
7 | |
import liquibase.sql.Sql; |
8 | |
import liquibase.sql.UnparsedSql; |
9 | |
import liquibase.sqlgenerator.SqlGenerator; |
10 | |
import liquibase.sqlgenerator.SqlGeneratorChain; |
11 | |
import liquibase.statement.core.ReorganizeTableStatement; |
12 | |
|
13 | 51 | public class ReorganizeTableGeneratorDB2 extends AbstractSqlGenerator<ReorganizeTableStatement> { |
14 | |
@Override |
15 | |
public int getPriority() { |
16 | 1 | return PRIORITY_DATABASE; |
17 | |
} |
18 | |
|
19 | |
@Override |
20 | |
public boolean supports(ReorganizeTableStatement statement, Database database) { |
21 | 33 | return database instanceof DB2Database; |
22 | |
} |
23 | |
|
24 | |
public ValidationErrors validate(ReorganizeTableStatement reorganizeTableStatement, Database database, |
25 | |
SqlGeneratorChain sqlGeneratorChain) { |
26 | 8 | ValidationErrors validationErrors = new ValidationErrors(); |
27 | 8 | validationErrors.checkRequiredField("tableName", reorganizeTableStatement.getTableName()); |
28 | 8 | return validationErrors; |
29 | |
} |
30 | |
|
31 | |
public Sql[] generateSql(ReorganizeTableStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { |
32 | |
try { |
33 | 0 | if (database.getDatabaseMajorVersion() >= 9) { |
34 | 0 | return new Sql[] { new UnparsedSql("CALL SYSPROC.ADMIN_CMD ('REORG TABLE " |
35 | |
+ database.escapeTableName(statement.getSchemaName(), statement.getTableName()) + "')") }; |
36 | |
} else { |
37 | 0 | return null; |
38 | |
} |
39 | 0 | } catch (DatabaseException e) { |
40 | 0 | throw new RuntimeException(e); |
41 | |
} |
42 | |
} |
43 | |
} |