org.dbunit.database.search
Class AbstractMetaDataBasedSearchCallback

java.lang.Object
  extended by org.dbunit.util.search.AbstractNodesFilterSearchCallback
      extended by org.dbunit.database.search.AbstractMetaDataBasedSearchCallback
All Implemented Interfaces:
ISearchCallback
Direct Known Subclasses:
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: 629 $
Author:
Felipe Leme

Field Summary
protected static int EXPORT
           
protected static int[] FK_INDEXES
           
protected static int IMPORT
           
protected static int[] PK_INDEXES
           
protected static int[] TABLENAME_INDEXES
          indexes of the column names on the MetaData result sets.
 
Fields inherited from class org.dbunit.util.search.AbstractNodesFilterSearchCallback
ALLOW_MODE, DENY_MODE, NO_MODE
 
Constructor Summary
AbstractMetaDataBasedSearchCallback(IDatabaseConnection connection)
          Defautl constructor.
 
Method Summary
protected static ForeignKeyRelationshipEdge createFKEdge(java.sql.ResultSet rs, int type, java.lang.String from, java.lang.String to, java.lang.String fkColumn, java.lang.String pkColumn)
          Creates an edge representing a foreign key relationship between 2 tables.
 IDatabaseConnection getConnection()
          Get the connection where the edges will be calculated from.
protected  java.util.SortedSet getNodesFromExportedKeys(java.lang.Object node)
          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.
protected  java.util.SortedSet getNodesFromImportAndExportKeys(java.lang.Object node)
          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.
protected  java.util.SortedSet getNodesFromImportedKeys(java.lang.Object node)
          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.
protected  IEdge newEdge(java.sql.ResultSet rs, int type, java.lang.String from, java.lang.String to, java.lang.String fkColumn, java.lang.String pkColumn)
          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).
 
Methods inherited from class org.dbunit.util.search.AbstractNodesFilterSearchCallback
getFilteredNodes, getFilteringMode, nodeAdded, searchNode, setAllowedNodes, setAllowedNodes, setDeniedNodes, setDeniedNodes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.dbunit.util.search.ISearchCallback
getEdges
 

Field Detail

IMPORT

protected static final int IMPORT
See Also:
Constant Field Values

EXPORT

protected static final int EXPORT
See Also:
Constant Field Values

TABLENAME_INDEXES

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


PK_INDEXES

protected static final int[] PK_INDEXES

FK_INDEXES

protected static final int[] FK_INDEXES
Constructor Detail

AbstractMetaDataBasedSearchCallback

public AbstractMetaDataBasedSearchCallback(IDatabaseConnection connection)
Defautl constructor.

Parameters:
connection - connection where the edges will be calculated from
Method Detail

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 java.util.SortedSet getNodesFromImportedKeys(java.lang.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 java.util.SortedSet getNodesFromExportedKeys(java.lang.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 similiar, 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 java.util.SortedSet getNodesFromImportAndExportKeys(java.lang.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(java.sql.ResultSet rs,
                                                         int type,
                                                         java.lang.String from,
                                                         java.lang.String to,
                                                         java.lang.String fkColumn,
                                                         java.lang.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(java.sql.ResultSet rs,
                        int type,
                        java.lang.String from,
                        java.lang.String to,
                        java.lang.String fkColumn,
                        java.lang.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)


Copyright © 2002-2008. All Rights Reserved.