Class PrimaryKeyFilter

All Implemented Interfaces:
ITableFilter, ITableFilterSimple

public class PrimaryKeyFilter extends AbstractTableFilter
Filter a table given a map of the allowed rows based on primary key values.
It uses a depth-first algorithm (although not recursive - it might be refactored in the future) to define which rows are allowed, as well which rows are necessary (and hence allowed) because of dependencies with the allowed rows.
NOTE: multi-column primary keys are not supported at the moment. TODO: test cases
Since:
Sep 9, 2005
Version:
$Revision$ $Date$
Author:
Felipe Leme (dbunit@felipeal.net), Last changed by: $Author$
  • Field Details

    • logger

      protected final org.slf4j.Logger logger
      Logger for this class.
  • Constructor Details

    • PrimaryKeyFilter

      public PrimaryKeyFilter(IDatabaseConnection connection, PrimaryKeyFilter.PkTableMap allowedPKs, boolean reverseDependency)
      Default constructor, it takes as input a map with desired rows in a final dataset; the filter will ensure that the rows necessary by these initial rows are also allowed (and so on...).
      Parameters:
      connection - database connection
      allowedPKs - map of allowed rows, based on the primary keys (key is the name of a table; value is a Set with allowed primary keys for that table)
      reverseDependency - flag indicating if the rows that depend on a row should also be allowed by the filter
  • Method Details

    • nodeAdded

      public void nodeAdded(Object node)
      Records the given node as a known table name.
      Parameters:
      node - the table name node added to the dependency graph.
    • edgeAdded

      public void edgeAdded(ForeignKeyRelationshipEdge edge)
      Records the given foreign key relationship in the direct and reverse edge caches.
      Parameters:
      edge - the foreign key relationship added to the dependency graph.
    • isValidName

      public boolean isValidName(String tableName) throws DataSetException
      Description copied from class: AbstractTableFilter
      Returns true if specified table is allowed by this filter. This legacy method, now replaced by accept, still exist for compatibily with older environment
      Specified by:
      isValidName in class AbstractTableFilter
      Parameters:
      tableName - the name of the table to check.
      Returns:
      true if specified table is allowed by this filter.
      Throws:
      DataSetException - if the check fails.
      See Also:
    • iterator

      public ITableIterator iterator(IDataSet dataSet, boolean reversed) throws DataSetException
      Description copied from interface: ITableFilter
      Returns iterator of tables allowed by this filter from the specified dataset.
      Specified by:
      iterator in interface ITableFilter
      Overrides:
      iterator in class AbstractTableFilter
      Parameters:
      dataSet - the filtered dataset
      reversed - true to iterate in reverse order.
      Returns:
      the iterator of tables allowed by this filter.
      Throws:
      DataSetException - if creating the iterator fails.
    • toString

      public String toString()
      Overrides:
      toString in class Object