Class AbstractMetaDataBasedSearchCallback

java.lang.Object
org.dbunit.util.search.AbstractNodesFilterSearchCallback
org.dbunit.database.search.AbstractMetaDataBasedSearchCallback
All Implemented Interfaces:
ISearchCallback
Direct Known Subclasses:
ExportedKeysSearchCallback, ImportedAndExportedKeysSearchCallback, ImportedKeysSearchCallback

public abstract class AbstractMetaDataBasedSearchCallback extends AbstractNodesFilterSearchCallback
Super-class for the ISearchCallback that implements the getEdges() method using the database meta-data.
Since:
Aug 25, 2005
Version:
$Revision$
Author:
Felipe Leme (dbunit@felipeal.net)
  • Field Details

    • IMPORT

      protected static final int IMPORT
      See Also:
    • EXPORT

      protected static final int EXPORT
      See Also:
    • TABLENAME_INDEXES

      protected static final int[] TABLENAME_INDEXES
      indexes of the column names on the MetaData result sets.
    • SCHEMANAME_INDEXES

      protected static final int[] SCHEMANAME_INDEXES
    • PK_INDEXES

      protected static final int[] PK_INDEXES
    • FK_INDEXES

      protected static final int[] FK_INDEXES
  • Constructor Details

    • AbstractMetaDataBasedSearchCallback

      public AbstractMetaDataBasedSearchCallback(IDatabaseConnection connection)
      Default constructor.
      Parameters:
      connection - connection where the edges will be calculated from
  • Method Details

    • getConnection

      public IDatabaseConnection getConnection()
      Get the connection where the edges will be calculated from.
      Returns:
      the connection where the edges will be calculated from
    • getNodesFromImportedKeys

      protected SortedSet getNodesFromImportedKeys(Object node) throws SearchException
      Get the nodes using the direct foreign key dependency, i.e, if table A has a FK for a table B, then getNodesFromImportedKeys(A) will return B.
      Parameters:
      node - table name
      Returns:
      tables with direct FK dependency from node
      Throws:
      SearchException
    • getNodesFromExportedKeys

      protected SortedSet getNodesFromExportedKeys(Object node) throws SearchException
      Get the nodes using the reverse foreign key dependency, i.e, if table C has a FK for a table A, then getNodesFromExportedKeys(A) will return C.
      NOTE: this method should be used only as an auxiliary method for sub-classes that also use getNodesFromImportedKeys() or something similar, otherwise the generated sequence of tables might not work when inserted in the database (as some tables might be missing).
      Parameters:
      node - table name
      Returns:
      tables with reverse FK dependency from node
      Throws:
      SearchException
    • getNodesFromImportAndExportKeys

      protected SortedSet getNodesFromImportAndExportKeys(Object node) throws SearchException
      Get the nodes using the both direct and reverse foreign key dependency, i.e, if table C has a FK for a table A and table A has a FK for a table B, then getNodesFromImportAndExportedKeys(A) will return B and C.
      Parameters:
      node - table name
      Returns:
      tables with reverse and direct FK dependency from node
      Throws:
      SearchException
    • createFKEdge

      protected static ForeignKeyRelationshipEdge createFKEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) throws SearchException
      Creates an edge representing a foreign key relationship between 2 tables.
      Parameters:
      rs - database meta-data result set
      type - type of relationship (IMPORT or EXPORT)
      from - name of the table representing the 'from' node
      to - name of the table representing the 'to' node
      fkColumn - name of the foreign key column
      pkColumn - name of the primary key column
      Returns:
      edge representing the relationship between the 2 tables, according to the type
      Throws:
      SearchException - not thrown in this method (but might on sub-classes)
    • newEdge

      protected IEdge newEdge(ResultSet rs, int type, String from, String to, String fkColumn, String pkColumn) throws SearchException
      This method can be overwritten by the sub-classes if they need to decorate the edge (for instance, providing an Edge that contains the primary and foreign keys used).
      Parameters:
      rs - database meta-data result set
      type - type of relationship (IMPORT or EXPORT)
      from - name of the table representing the 'from' node
      to - name of the table representing the 'to' node
      fkColumn - name of the foreign key column
      pkColumn - name of the primary key column
      Returns:
      edge representing the relationship between the 2 tables, according to the type
      Throws:
      SearchException - not thrown in this method (but might on sub-classes)