Esempio n. 1
0
  /*
   * Generates rollback statements from the inverse changes returned by createInverses().
   * Throws RollbackImpossibleException if the changes created by createInverses() is not supported for the passed database.
   *
   */
  private SqlStatement[] generateRollbackStatementsFromInverse(Database database)
      throws RollbackImpossibleException {
    Change[] inverses = createInverses();
    if (inverses == null) {
      throw new RollbackImpossibleException("No inverse to " + getClass().getName() + " created");
    }

    List<SqlStatement> statements = new ArrayList<SqlStatement>();

    try {
      for (Change inverse : inverses) {
        if (!inverse.supports(database)) {
          throw new RollbackImpossibleException(
              ChangeFactory.getInstance().getChangeMetaData(inverse).getName()
                  + " is not supported on "
                  + database.getShortName());
        }
        statements.addAll(Arrays.asList(inverse.generateStatements(database)));
      }
    } catch (LiquibaseException e) {
      throw new RollbackImpossibleException(e);
    }

    return statements.toArray(new SqlStatement[statements.size()]);
  }