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:
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 Summary
protected static int EXPORT
           
protected static int[] FK_INDEXES
           
protected static int IMPORT
           
protected static int[] PK_INDEXES
           
protected static int[] SCHEMANAME_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)
          Default constructor.
 
Method Summary
protected static ForeignKeyRelationshipEdge createFKEdge(ResultSet rs, int type, String from, String to, String fkColumn, 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  SortedSet getNodesFromExportedKeys(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.
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).
protected  SortedSet getNodesFromImportAndExportKeys(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  SortedSet getNodesFromImportedKeys(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(ResultSet rs, int type, String from, String to, String fkColumn, 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.


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 Detail

AbstractMetaDataBasedSearchCallback

public AbstractMetaDataBasedSearchCallback(IDatabaseConnection connection)
Default 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 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)


Copyright © 2002–2014. All rights reserved.