/**
   * Apply the specified exclude and include column filters to the specified table.
   *
   * @param table The table to apply the filters to.
   * @param excludeColumns The exclude filters; use null or empty array to mean exclude none.
   * @param includeColumns The include filters; use null to mean include all.
   * @return The filtered table.
   * @throws DataSetException
   */
  public ITable applyColumnFilters(ITable table, String[] excludeColumns, String[] includeColumns)
      throws DataSetException {
    ITable filteredTable = table;

    if (table == null) {
      throw new IllegalArgumentException("table is null");
    }

    // note: dbunit interprets an empty inclusion filter array as one
    // not wanting to compare anything!
    if (includeColumns == null) {
      LOG.debug("applyColumnFilters: including columns=(all)");
    } else {
      LOG.debug("applyColumnFilters: including columns='{}'", new Object[] {includeColumns});
      filteredTable = DefaultColumnFilter.includedColumnsTable(filteredTable, includeColumns);
    }

    if (excludeColumns == null || excludeColumns.length == 0) {
      LOG.debug("applyColumnFilters: excluding columns=(none)");
    } else {
      LOG.debug("applyColumnFilters: excluding columns='{}'", new Object[] {excludeColumns});
      filteredTable = DefaultColumnFilter.excludedColumnsTable(filteredTable, excludeColumns);
    }

    return filteredTable;
  }
  public void testGetPrimaryKeysWithColumnFilters() throws Exception {

    // TODO (felipeal): I don't know if PK_TABLE is a standard JDBC name or if
    // it's HSQLDB specific. Anyway, now that HSQLDB's schema is set on property,
    // we cannot add it as prefix here....
    String tableName = "PK_TABLE";
    //        String tableName = DataSetUtils.getQualifiedName(
    //                _connection.getSchema(), "PK_TABLE");

    String[] expected = {"PK0", "PK2"};

    DefaultColumnFilter filter = new DefaultColumnFilter();
    filter.includeColumn("PK0");
    filter.includeColumn("PK2");

    IDatabaseConnection connection =
        new DatabaseConnection(_connection.getConnection(), _connection.getSchema());
    connection.getConfig().setProperty(DatabaseConfig.PROPERTY_PRIMARY_KEY_FILTER, filter);

    ITableMetaData metaData = connection.createDataSet().getTableMetaData(tableName);
    Column[] columns = metaData.getPrimaryKeys();

    assertEquals("column count", expected.length, columns.length);
    for (int i = 0; i < columns.length; i++) {
      assertEquals("column name", convertString(expected[i]), columns[i].getColumnName());
    }
  }
  public void testGetColumn() throws Exception {
    Column[] cols =
        new Column[] {new Column("COL1", DataType.UNKNOWN), new Column("COL2", DataType.UNKNOWN)};
    DefaultTable table = new DefaultTable("MY_TABLE", cols);
    table.addRow(new Object[] {"value1", "value2"});

    // Filter COL1
    ITable tableFiltered = DefaultColumnFilter.excludedColumnsTable(table, new String[] {"COL1"});

    DefaultFailureHandler failureHandler = new DefaultFailureHandler(cols);
    String info = failureHandler.getAdditionalInfo(tableFiltered, tableFiltered, 0, "COL1");

    String expectedInfo =
        "Additional row info: ('COL1': expected=<value1>, actual=<value1>) ('COL2': expected=<value2>, actual=<value2>)";
    assertEquals(expectedInfo, info);
  }