| 1 |  |  package liquibase.sqlgenerator.core; | 
  | 2 |  |   | 
  | 3 |  |  import liquibase.database.Database; | 
  | 4 |  |  import liquibase.database.core.OracleDatabase; | 
  | 5 |  |  import liquibase.exception.DatabaseException; | 
  | 6 |  |  import liquibase.exception.UnexpectedLiquibaseException; | 
  | 7 |  |  import liquibase.exception.ValidationErrors; | 
  | 8 |  |  import liquibase.sql.Sql; | 
  | 9 |  |  import liquibase.sql.UnparsedSql; | 
  | 10 |  |  import liquibase.sqlgenerator.SqlGenerator; | 
  | 11 |  |  import liquibase.sqlgenerator.SqlGeneratorChain; | 
  | 12 |  |  import liquibase.statement.core.FindForeignKeyConstraintsStatement; | 
  | 13 |  |   | 
  | 14 | 11 |  public class FindForeignKeyConstraintsGeneratorOracle extends AbstractSqlGenerator<FindForeignKeyConstraintsStatement> { | 
  | 15 |  |      @Override | 
  | 16 |  |      public int getPriority() { | 
  | 17 | 1 |          return PRIORITY_DATABASE; | 
  | 18 |  |      } | 
  | 19 |  |   | 
  | 20 |  |      @Override | 
  | 21 |  |      public boolean supports(FindForeignKeyConstraintsStatement statement, Database database) { | 
  | 22 | 1 |          return database instanceof OracleDatabase; | 
  | 23 |  |      } | 
  | 24 |  |   | 
  | 25 |  |      public ValidationErrors validate(FindForeignKeyConstraintsStatement findForeignKeyConstraintsStatement, | 
  | 26 |  |              Database database, SqlGeneratorChain sqlGeneratorChain) { | 
  | 27 | 0 |          ValidationErrors validationErrors = new ValidationErrors(); | 
  | 28 | 0 |          validationErrors.checkRequiredField("baseTableName", findForeignKeyConstraintsStatement.getBaseTableName()); | 
  | 29 | 0 |          return validationErrors; | 
  | 30 |  |      } | 
  | 31 |  |   | 
  | 32 |  |      public Sql[] generateSql(FindForeignKeyConstraintsStatement statement, Database database, | 
  | 33 |  |              SqlGeneratorChain sqlGeneratorChain) { | 
  | 34 | 0 |          StringBuilder sb = new StringBuilder(); | 
  | 35 |  |   | 
  | 36 | 0 |          sb.append("SELECT "); | 
  | 37 | 0 |          sb.append("BASE.TABLE_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME) | 
  | 38 |  |                  .append(", "); | 
  | 39 | 0 |          sb.append("BCOLS.COLUMN_NAME as ") | 
  | 40 |  |                  .append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_COLUMN_NAME).append(", "); | 
  | 41 | 0 |          sb.append("FRGN.TABLE_NAME ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_TABLE_NAME) | 
  | 42 |  |                  .append(", "); | 
  | 43 | 0 |          sb.append("FCOLS.COLUMN_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_FOREIGN_COLUMN_NAME) | 
  | 44 |  |                  .append(", "); | 
  | 45 | 0 |          sb.append("BASE.CONSTRAINT_NAME as ").append(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME) | 
  | 46 |  |                  .append(" "); | 
  | 47 | 0 |          sb.append("FROM ALL_CONSTRAINTS BASE,"); | 
  | 48 | 0 |          sb.append("     ALL_CONSTRAINTS FRGN,"); | 
  | 49 | 0 |          sb.append("     ALL_CONS_COLUMNS BCOLS,"); | 
  | 50 | 0 |          sb.append("     ALL_CONS_COLUMNS FCOLS "); | 
  | 51 | 0 |          sb.append("WHERE BASE.R_OWNER = FRGN.OWNER "); | 
  | 52 | 0 |          sb.append("AND BASE.R_CONSTRAINT_NAME = FRGN.CONSTRAINT_NAME "); | 
  | 53 | 0 |          sb.append("AND BASE.OWNER = BCOLS.OWNER "); | 
  | 54 | 0 |          sb.append("AND BASE.CONSTRAINT_NAME = BCOLS.CONSTRAINT_NAME "); | 
  | 55 | 0 |          sb.append("AND FRGN.OWNER = FCOLS.OWNER "); | 
  | 56 | 0 |          sb.append("AND FRGN.CONSTRAINT_NAME = FCOLS.CONSTRAINT_NAME "); | 
  | 57 | 0 |          sb.append("AND BASE.TABLE_NAME =  '").append(statement.getBaseTableName().toUpperCase()).append("' "); | 
  | 58 | 0 |          sb.append("AND BASE.CONSTRAINT_TYPE = 'R' "); | 
  | 59 |  |          try { | 
  | 60 | 0 |              sb.append("AND BASE.OWNER = '") | 
  | 61 |  |                      .append(database.convertRequestedSchemaToSchema(statement.getBaseTableSchemaName())).append("'"); | 
  | 62 | 0 |          } catch (DatabaseException e) { | 
  | 63 | 0 |              throw new UnexpectedLiquibaseException(e); | 
  | 64 | 0 |          } | 
  | 65 |  |   | 
  | 66 | 0 |          return new Sql[] { new UnparsedSql(sb.toString()) }; | 
  | 67 |  |      } | 
  | 68 |  |  } |