public void check(Database database, DatabaseChangeLog changeLog, ChangeSet changeSet)
      throws PreconditionFailedException, PreconditionErrorException {
    Column example = new Column();
    if (StringUtils.trimToNull(getTableName()) != null) {
      example.setRelation(
          new Table()
              .setName(database.correctObjectName(getTableName(), Table.class))
              .setSchema(new Schema(getCatalogName(), getSchemaName())));
    }
    example.setName(database.correctObjectName(getColumnName(), Column.class));

    try {
      if (!SnapshotGeneratorFactory.getInstance().has(example, database)) {
        throw new PreconditionFailedException(
            "Column '"
                + database.escapeColumnName(
                    catalogName, schemaName, getTableName(), getColumnName())
                + "' does not exist",
            changeLog,
            this);
      }
    } catch (LiquibaseException e) {
      throw new PreconditionErrorException(e, changeLog, this);
    }
  }
  @Override
  protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot)
      throws DatabaseException {
    Database database = snapshot.getDatabase();
    String objectName = example.getName();
    Schema schema = example.getSchema();

    List<CachedRow> rs = null;
    try {
      JdbcDatabaseSnapshot.CachingDatabaseMetaData metaData =
          ((JdbcDatabaseSnapshot) snapshot).getMetaData();
      rs =
          metaData.getTables(
              ((AbstractJdbcDatabase) database).getJdbcCatalogName(schema),
              ((AbstractJdbcDatabase) database).getJdbcSchemaName(schema),
              database.correctObjectName(objectName, Table.class),
              new String[] {"TABLE"});

      Table table;
      if (rs.size() > 0) {
        table = readTable(rs.get(0), database);
      } else {
        return null;
      }

      return table;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    }
  }
 /**
  * Generates the {@link Index} example (taken from {@link IndexExistsPrecondition}).
  *
  * @param database the database instance.
  * @param schema the schema instance.
  * @param tableName the table name of the index.
  * @return the index example.
  */
 protected Index getIndexExample(
     final Database database, final Schema schema, final String tableName) {
   final Index example = new Index();
   if (tableName != null) {
     example.setTable(
         (Table)
             new Table()
                 .setName(database.correctObjectName(getTableName(), Table.class))
                 .setSchema(schema));
   }
   example.setName(database.correctObjectName(getIndexName(), Index.class));
   if (StringUtils.trimToNull(getColumnNames()) != null) {
     for (final String columnName : getColumnNames().split("\\s*,\\s*")) {
       final Column column = new Column(database.correctObjectName(columnName, Column.class));
       example.getColumns().add(column);
     }
   }
   return example;
 }
  /**
   * Creates an example of the database object for which to check.
   *
   * @param database the database instance.
   * @param tableName the table name of the index.
   * @return the database object example.
   */
  public DatabaseObject getExample(final Database database, final String tableName) {
    final Schema schema = new Schema(getCatalogName(), getSchemaName());
    final DatabaseObject example;

    // For GeoDB, the index is another table.
    if (database instanceof DerbyDatabase || database instanceof H2Database) {
      final String correctedTableName =
          database.correctObjectName(getHatboxTableName(), Table.class);
      example = new Table().setName(correctedTableName).setSchema(schema);
    } else {
      example = getIndexExample(database, schema, tableName);
    }
    return example;
  }