de.fesenmeyer.dbnormalizer.core.algorithms
Class NormalizationFKsDetermination

java.lang.Object
  extended by de.fesenmeyer.dbnormalizer.core.algorithms.NormalizationFKsDetermination

public class NormalizationFKsDetermination
extends Object

Class which can be used for determination of the foreign keys (FKs) which should be defined for the tables of a normalization proposal. The implementation is based on the assumption that foreign keys cannot reference arbitrary candidate keys, but only primary keys.

NOTE: The current implementation only leads to an optimal solution, if each of the created tables of the normalization proposal just contains one candidate key. For a better solution, the selection of the primary keys for the created tables could possibly be made dependent on which foreign keys can be defined between the tables.

Author:
DF
See Also:
NormalizationFKsProposal

Field Summary
private static DBNormalizerLogger logger
          The logger for this class.
private  NormalizationProposal normProposal
          The normalization proposal for which FKs should be proposed.
 
Constructor Summary
NormalizationFKsDetermination(NormalizationProposal normProposal)
          Class constructor specifying the normalization proposal for which FKs should be proposed.
 
Method Summary
private  void addExportedKeysToTables(Collection<FK> fks, Collection<Table> tables)
          Helper method which adds each FK given by the fks argument as exported key to the appropriate table contained in the collection given by the tables argument, if possible.
private  void addImportedKeysToTables(Collection<FK> fks, Collection<Table> tables)
          Helper method which adds each FK given by the fks argument as imported key to the appropriate table contained in the collection given by the tables argument, if possible.
private  ArrayList<FK> computeExportedFKs()
          Helper method which computes FKs to be defined due to the old table's exported keys.
private  ArrayList<FK> computeHierarchicalFKs()
          Helper method which computes FKs to be defined due to FKs between the old table's attributes ("hierarchical FKs").
private  ArrayList<FK> computeImportedFKs()
          Helper method which computes FKs to be defined due to the old table's imported keys.
private  ArrayList<FK> computeInnerFKs()
          Helper method which computes FKs to be defined between the created tables of the normalization proposal.
 NormalizationFKsProposal getNormalizationFKsProposal()
          Computes a proposal of FKs to be defined and sets these FKs for the tables which are returned by the NormalizationProposal.getCreatedTables() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static DBNormalizerLogger logger
The logger for this class.


normProposal

private NormalizationProposal normProposal
The normalization proposal for which FKs should be proposed.

Constructor Detail

NormalizationFKsDetermination

public NormalizationFKsDetermination(NormalizationProposal normProposal)
Class constructor specifying the normalization proposal for which FKs should be proposed.

Parameters:
normProposal - the normalization proposal
Method Detail

getNormalizationFKsProposal

public NormalizationFKsProposal getNormalizationFKsProposal()
Computes a proposal of FKs to be defined and sets these FKs for the tables which are returned by the NormalizationProposal.getCreatedTables() method.

Returns:
the FKs proposal
See Also:
NormalizationFKsProposal

addExportedKeysToTables

private void addExportedKeysToTables(Collection<FK> fks,
                                     Collection<Table> tables)
Helper method which adds each FK given by the fks argument as exported key to the appropriate table contained in the collection given by the tables argument, if possible.

Parameters:
fks - a collection of FKs
tables - a collection of tables

addImportedKeysToTables

private void addImportedKeysToTables(Collection<FK> fks,
                                     Collection<Table> tables)
Helper method which adds each FK given by the fks argument as imported key to the appropriate table contained in the collection given by the tables argument, if possible.

Parameters:
fks - a collection of FKs
tables - a collection of tables

computeExportedFKs

private ArrayList<FK> computeExportedFKs()
Helper method which computes FKs to be defined due to the old table's exported keys.

Returns:
the list of FKs

computeImportedFKs

private ArrayList<FK> computeImportedFKs()
Helper method which computes FKs to be defined due to the old table's imported keys.

Returns:
the list of FKs

computeInnerFKs

private ArrayList<FK> computeInnerFKs()
Helper method which computes FKs to be defined between the created tables of the normalization proposal.

Returns:
the list of FKs

computeHierarchicalFKs

private ArrayList<FK> computeHierarchicalFKs()
Helper method which computes FKs to be defined due to FKs between the old table's attributes ("hierarchical FKs").

Returns:
the list of FKs