1 | |
package liquibase.sqlgenerator.core; |
2 | |
|
3 | |
import liquibase.database.Database; |
4 | |
import liquibase.database.core.DB2Database; |
5 | |
import liquibase.exception.ValidationErrors; |
6 | |
import liquibase.sql.Sql; |
7 | |
import liquibase.sql.UnparsedSql; |
8 | |
import liquibase.sqlgenerator.SqlGenerator; |
9 | |
import liquibase.sqlgenerator.SqlGeneratorChain; |
10 | |
import liquibase.statement.core.FindForeignKeyConstraintsStatement; |
11 | |
|
12 | 11 | public class FindForeignKeyConstraintsGeneratorDB2 extends AbstractSqlGenerator<FindForeignKeyConstraintsStatement> { |
13 | |
@Override |
14 | |
public int getPriority() { |
15 | 1 | return PRIORITY_DATABASE; |
16 | |
} |
17 | |
|
18 | |
@Override |
19 | |
public boolean supports(FindForeignKeyConstraintsStatement statement, Database database) { |
20 | 1 | return database instanceof DB2Database; |
21 | |
} |
22 | |
|
23 | |
public ValidationErrors validate(FindForeignKeyConstraintsStatement findForeignKeyConstraintsStatement, |
24 | |
Database database, SqlGeneratorChain sqlGeneratorChain) { |
25 | 0 | ValidationErrors validationErrors = new ValidationErrors(); |
26 | 0 | validationErrors.checkRequiredField("baseTableName", findForeignKeyConstraintsStatement.getBaseTableName()); |
27 | 0 | return validationErrors; |
28 | |
} |
29 | |
|
30 | |
public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database database, |
31 | |
SqlGeneratorChain sqlGeneratorChain) { |
32 | 0 | StringBuilder sb = new StringBuilder(); |
33 | |
|
34 | 0 | sb.append("SELECT "); |
35 | 0 | sb.append("TABNAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME).append(", "); |
36 | 0 | sb.append("PK_COLNAMES as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_COLUMN_NAME) |
37 | |
.append(", "); |
38 | 0 | sb.append("REFTABNAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_TABLE_NAME) |
39 | |
.append(", "); |
40 | 0 | sb.append("FK_COLNAMES as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_COLUMN_NAME) |
41 | |
.append(","); |
42 | 0 | sb.append("CONSTNAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME).append(" "); |
43 | 0 | sb.append("FROM SYSCAT.REFERENCES "); |
44 | 0 | sb.append("WHERE TABNAME='").append(statement.getBaseTableName()).append("'"); |
45 | |
|
46 | 0 | return new Sql[] { new UnparsedSql(sb.toString()) }; |
47 | |
} |
48 | |
} |