proper.database
Class RelationDiscoverer

java.lang.Object
  extended by proper.core.ProperObject
      extended by proper.database.ConnectorObject
          extended by proper.database.RelationDiscoverer
All Implemented Interfaces:
ProperInterface

public class RelationDiscoverer
extends ConnectorObject

This class discovers from a table all the tables that are dependent on it, i.e. whether other tables have the same index-names. Unfortunately does the MySQL jdbc-driver not support foreign key relations, s.t. we'll have to work on column names. From a given table as starting point it determines from this table's indexes all the other tables that reference these indexes. The result is a tree structure of related tables, where the UserObject in the nodes contains a Table-Object. E.g. the east-west-challenge looks then like this:

   train
   |-car
   | |-load
 

Version:
$Revision: 1.3 $
Author:
FracPete
See Also:
Join

Field Summary
 
Fields inherited from interface proper.core.ProperInterface
VERSION
 
Constructor Summary
RelationDiscoverer(Connector conn)
          initializes the object
 
Method Summary
 JoinTreeNode discover()
          discovers the relation between the tables in the given database and returns the root element of the built tree
 java.util.Vector getExcludes()
          returns the tables excluded from discovery
 int getMaxDepth()
          returns the current maximal depth to search
 java.lang.String getTable()
          returns the name of the table to read from
 boolean getUseForeignKeys()
          returns whether foreign keys are used for discovering relations between tables or only matching column names
 java.util.Vector leftOverTables()
          returns all the tables that are not in this tree
 java.util.Vector leftOverTables(JoinTreeNode root)
          returns all the tables that are not in this tree
 void setExcludes(java.lang.String excludes)
          sets the tables (String) to exclude from discovery
 void setExcludes(java.util.Vector excludes)
          sets the tables (String) to exclude from discovery
 void setMaxDepth(int maxDepth)
          sets the maximal depth of the tree to search, -1 means no limit
 void setTable(java.lang.String table)
          sets the name of the table to use
 void setUseForeignKeys(boolean useForeignKeys)
          whether to use foreign keys or matching column names for discovering table relations
 java.lang.String toString()
          the object in a string representation
 
Methods inherited from class proper.database.ConnectorObject
getConnector
 
Methods inherited from class proper.core.ProperObject
addListener, addOutput, classInVerbose, debugprint, debugprint, debugprint, debugprint, debugprintln, debugprintln, debugprintln, debugprintln, debugprintln, getListeners, getRuntime, getVerbose, getVerboseLevel, getVerboseLevelForClass, getVerboseString, getVerboseStringForClass, notifyListener, notifyListeners, print, print, print, print, println, println, println, println, println, printMemory, removeListener, setOutput, setVerbose, setVerboseLevel, setVerboseString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RelationDiscoverer

public RelationDiscoverer(Connector conn)
initializes the object

Method Detail

setTable

public void setTable(java.lang.String table)
sets the name of the table to use


getTable

public java.lang.String getTable()
returns the name of the table to read from


setExcludes

public void setExcludes(java.util.Vector excludes)
sets the tables (String) to exclude from discovery


setExcludes

public void setExcludes(java.lang.String excludes)
sets the tables (String) to exclude from discovery


getExcludes

public java.util.Vector getExcludes()
returns the tables excluded from discovery


setMaxDepth

public void setMaxDepth(int maxDepth)
sets the maximal depth of the tree to search, -1 means no limit


getMaxDepth

public int getMaxDepth()
returns the current maximal depth to search


setUseForeignKeys

public void setUseForeignKeys(boolean useForeignKeys)
whether to use foreign keys or matching column names for discovering table relations

Parameters:
useForeignKeys - whether to use foreign keys or matching column names

getUseForeignKeys

public boolean getUseForeignKeys()
returns whether foreign keys are used for discovering relations between tables or only matching column names

Returns:
whether foreign keys or matching column names are used for discovering table relations

discover

public JoinTreeNode discover()
discovers the relation between the tables in the given database and returns the root element of the built tree

Returns:
the resulting tree of relations

leftOverTables

public java.util.Vector leftOverTables()
returns all the tables that are not in this tree

Returns:
the tables not in the tree

leftOverTables

public java.util.Vector leftOverTables(JoinTreeNode root)
returns all the tables that are not in this tree

Parameters:
root - the generated tree from a previous run
Returns:
the tables not in the tree

toString

public java.lang.String toString()
the object in a string representation

Overrides:
toString in class ProperObject