de.fesenmeyer.dbnormalizer.core.algorithms
Class NFDetermination

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

public class NFDetermination
extends Object

This class implements an algorithm for the determination of the normal form of a table (from 1NF to BCNF). The algorithms are based on the definitions in [Fundamentals of database systems, 5th Ed., Elmasri/Navathe, 2007].

Author:
DF

Field Summary
private  Set<AttributeStringSet> candidateKeys
          The candidate keys of the table.
private  Set<FD> fds
          The FDs of the table.
private static DBNormalizerLogger logger
          The logger for this class.
private  boolean onlySimpleKeys
          flag, which is true, if the table only contains "simple" keys (keys consisting of one attribute)
private  Table table
          The table for which the normal form should be determined.
private  Map<NormalForm,Set<FD>> violatingFDs
          Map, which holds for each key (normal form) the FDs which violate this normal form
 
Constructor Summary
NFDetermination(Table table)
          Class Constructor specifying the table for which the normal form should be determined.
 
Method Summary
private  void addToViolatingFDs(NormalForm nf, FD fd)
          Helper method which adds a FD to the map of violating FDs.
 NFDeterminationResult determine()
           The normal form determination algorithm, which returns the normal form and the FDs violating one of the normal forms 2NF, 3NF or BCNF.
private  void initialize(Table table)
          Helper method for initialization of the member variables of this class.
private  boolean isKeyAttribute(String attr)
          Helper method which looks if the attribute specified by argument attr is part of a candidate key (a prime attribute).
private  boolean violates2NF(FD fd)
          Checks if a FD violates 2NF.
private  boolean violates3NF(FD fd)
          Checks if a FD violates 3NF.
private  boolean violatesBCNF(FD fd)
          Checks if a FD violates BCNF.
 
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.


candidateKeys

private Set<AttributeStringSet> candidateKeys
The candidate keys of the table.


table

private Table table
The table for which the normal form should be determined.


fds

private Set<FD> fds
The FDs of the table.


onlySimpleKeys

private boolean onlySimpleKeys
flag, which is true, if the table only contains "simple" keys (keys consisting of one attribute)


violatingFDs

private Map<NormalForm,Set<FD>> violatingFDs
Map, which holds for each key (normal form) the FDs which violate this normal form

Constructor Detail

NFDetermination

public NFDetermination(Table table)
Class Constructor specifying the table for which the normal form should be determined.

Parameters:
table - a Table object
Method Detail

initialize

private void initialize(Table table)
                 throws DBNormalizerException
Helper method for initialization of the member variables of this class.

Parameters:
table - the table
Throws:
DBNormalizerException

determine

public NFDeterminationResult determine()
                                throws DBNormalizerException

The normal form determination algorithm, which returns the normal form and the FDs violating one of the normal forms 2NF, 3NF or BCNF.

NOTE: Before applying this method to a table, make sure that it contains all the necessary data such as minimal cover (Table.setFDMinCover(java.util.Set)) and candidate keys (Table.setCandKeys(java.util.Set)). The methods for calculating this data can be found in the FDAlgorithms class.

Returns:
the result of the normal form determination
Throws:
DBNormalizerException
See Also:
NFDeterminationResult

violates2NF

private boolean violates2NF(FD fd)
Checks if a FD violates 2NF.

Parameters:
fd - the FD to be checked
Returns:
true, if the FD violates 2NF; false, otherwise

violates3NF

private boolean violates3NF(FD fd)
Checks if a FD violates 3NF.

Parameters:
fd - the FD to be checked
Returns:
true, if the FD violates 3NF; false, otherwise

violatesBCNF

private boolean violatesBCNF(FD fd)
Checks if a FD violates BCNF.

Parameters:
fd - the FD to be checked
Returns:
true, if the FD violates BCNF; false, otherwise

isKeyAttribute

private boolean isKeyAttribute(String attr)
Helper method which looks if the attribute specified by argument attr is part of a candidate key (a prime attribute).

Parameters:
attr - an attribute name
Returns:
true, if the attribute is part of a candidate key; false, otherwise

addToViolatingFDs

private void addToViolatingFDs(NormalForm nf,
                               FD fd)
Helper method which adds a FD to the map of violating FDs.

Parameters:
nf - the normal form which is violated by the FD
fd - the FD