de.fesenmeyer.dbnormalizer.core.algorithms
Class FDChecker

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

public class FDChecker
extends Object

Class which gives the possibility to check if a FD is satisfied by the current content of a Table (method checkFD(String, FD)). This is done by constructing an appropriate SQL query based on the FD and running this query against the DB.

Author:
DF

Field Summary
private  Connection conn
          The SQL-Connection to be used to access the DB.
private static String DERIVED_TABLE_ALIAS
          Constant for the name of the derived table constructed by the SQL Statement.
private static DBNormalizerLogger logger
          The logger for this class.
 
Constructor Summary
FDChecker(Connection conn)
          Class constructor specifying the SQL-Connection to be used.
 
Method Summary
 FDCheckState checkFD(String qualifiedTableName, FD fd)
           Checks if the FD specified by argument fd is satisfied in the table specified by argument qualifiedTableName.
private  String getCheckFDStatement(String qualifiedTableName, FD fd)
          Creates an SQL Statement, which can be used to check if the FD specified by the fd argument is satisfied by the Table specified by the qualifiedTableName argument.
private  String getCheckNoDataStatement(String qualifiedTableName)
          Creates an SQL query to check if the table specified by argument qualifiedTableName contains any data.
 DataSet getNotSatisfiedTupels(String qualifiedTableName, FD fd)
          Returns the tuples returned by the SQL query used for checking FDs.
 
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.


conn

private Connection conn
The SQL-Connection to be used to access the DB.


DERIVED_TABLE_ALIAS

private static final String DERIVED_TABLE_ALIAS
Constant for the name of the derived table constructed by the SQL Statement.

See Also:
Constant Field Values
Constructor Detail

FDChecker

public FDChecker(Connection conn)
Class constructor specifying the SQL-Connection to be used.

Parameters:
conn - a SQL-Connection
Method Detail

checkFD

public FDCheckState checkFD(String qualifiedTableName,
                            FD fd)
                     throws DBException

Checks if the FD specified by argument fd is satisfied in the table specified by argument qualifiedTableName. As a first step, the method checks if the table contains data. If it does not contain any data, it is not possible to check the FD.

To check if the FD

 {lectureno, matrno} -> {name, semester}
 
holds in the table with the qualified name university.students, the following query is run:
 SELECT lectureno, matrno, COUNT(*) AS rhscount
 FROM   (SELECT DISTINCT lectureno, matrno, name, semester
        FROM university.students) distinctrows
 GROUP BY lectureno, matrno HAVING COUNT(*) > 1
 
If the query does not return any row, the FD is satisfied. Otherwise, it is not satisfied.

Parameters:
qualifiedTableName - the qualified name of a table
fd - a FD possibly holding in the table specified by argument qualifiedTableName
Returns:
Returns
Throws:
DBException - if an SQL Exception occurs, e.g. because the table or the attributes of the FD do not exist, or because the DBS does not support the syntax used in the created SQL query

getNotSatisfiedTupels

public DataSet getNotSatisfiedTupels(String qualifiedTableName,
                                     FD fd)
                              throws DBException
Returns the tuples returned by the SQL query used for checking FDs. These tuples are returned in a DataSet object.

Parameters:
qualifiedTableName - a qualified table name
fd - a FD
Returns:
a DataSet object, which may contain no data, if the FD is satisfied or if the table does not contain any data
Throws:
DBException - if an SQL Exception occurs, e.g. because the table or the attributes of the FD do not exist, or because the DBS does not support the syntax used in the created SQL query
See Also:
checkFD(String, FD)

getCheckNoDataStatement

private String getCheckNoDataStatement(String qualifiedTableName)
Creates an SQL query to check if the table specified by argument qualifiedTableName contains any data. This SQL query returns a single value, which is the number of rows in the table (the table's row count).

Parameters:
qualifiedTableName -
Returns:
an SQL query as described above

getCheckFDStatement

private String getCheckFDStatement(String qualifiedTableName,
                                   FD fd)
Creates an SQL Statement, which can be used to check if the FD specified by the fd argument is satisfied by the Table specified by the qualifiedTableName argument.

Parameters:
qualifiedTableName - a qualified table name
fd - a FD
Returns:
an SQL statement for checking the FD
See Also:
checkFD(String, FD)