de.fesenmeyer.dbnormalizer.core
Class Table

java.lang.Object
  extended by de.fesenmeyer.dbnormalizer.core.AbstractDBItem
      extended by de.fesenmeyer.dbnormalizer.core.Table
All Implemented Interfaces:
Comparable<Table>

public class Table
extends AbstractDBItem
implements Comparable<Table>

Class representing a table. If the table is a DB-Table, i.e. if it exists in a DB or should be created in a DB (if it is part of a normalization proposal of a DB-Table), the flag dbTable must be true, otherwise it must be false. This flag can be get and set by means of the isDbTable() and setDbTable(boolean) methods.

Author:
DF

Field Summary
private  AttributeStringSet attributes
          The set of attributes belonging to this table.
private  Set<CandKey> candKeys
          The candidate keys.
private  String catalog
          The catalog this table is contained in, may be null.
private  Map<String,TableColumn> columnInfos
          A map containing tableColumn information for each attribute.
private  TableContainer container
          The TableContainer this table is contained in.
private  PK dbPK
          The PK defined in the DB.
private  boolean dbTable
          A flag which specifies if the table is a DB-Table or not.
private  List<FK> exportedKeys
          The exported keys for this table.
private  Set<FD> FDMinCover
          A minimal cover of the functional dependencies (FDs) contained in FDs.
private  Set<FD> FDs
          The set of functional dependencies (FDs) for this table, just as it has been specified by the user or imported from a file.
private  List<FK> importedKeys
          The imported keys for this table.
private  NFDeterminationResult nfDeterminationResult
          The result of the normal form determination for this table.
private  NormalizationProposal normProposal
          The normalization proposal for this table.
private  PK pk
          The PK selected by DBNormalizer when calculating candidate keys or by the user.
private  String schema
          The schema this table is contained in, may be null.
 
Constructor Summary
Table()
           
 
Method Summary
 void addColumnInfo(String colName, TableColumn col)
          Adds the TableColumn information specified by argument col for the column (attribute) specified by argument colName.
 int compareTo(Table table)
          Compares this table to another table based on the qualified names of the tables.
 boolean equals(Object o)
          Overridden Method, tests if this table is equal to the o argument based on the qualified name.
 AttributeStringSet getAttributes()
          Gets the set of attributes belonging to this table.
 Set<CandKey> getCandKeys()
          Gets this table's candidate keys (if they have already been set).
 String getCatalog()
          Gets the name of the catalog this table is contained in.
 TableColumn getColumnInfo(String colName)
          Gets TableColumn information for the column (attribute) specified by the colName argument.
 Collection<TableColumn> getColumnInfos()
          Gets TableColumn information for each of the table's columns (attributes).
 TableContainer getContainer()
          Gets the TableContainer this table is contained in.
 PK getDbPK()
          Gets the primary key (PK) defined in the DB.
 List<FK> getExportedKeys()
          Gets the exported keys.
 Set<FD> getFDMinCover()
          Gets the minimal cover of FDs for this table.
 Set<FD> getFDs()
          Gets the FDs for this table.
 List<FK> getImportedKeys()
          Gets the imported keys.
 NFDeterminationResult getNfDeterminationResult()
          Gets the result of the normal form determination for this table.
 NormalizationProposal getNormProposal()
          Gets the currently set normalization proposal for this table.
 PK getPk()
          Gets the PK for this table.
 String getQualifiedName()
          Gets the qualified name for this table.
 String getSchema()
          Gets the name of the schema this table is contained in.
 boolean isDbTable()
          States whether this table is a DB-Table or not.
 void setAttributes(AttributeStringSet attributes)
          Sets the set of attributes belonging to this table.
 void setCandKeys(Set<CandKey> candKeys)
          Sets this table's candidate keys.
 void setCatalog(String catalog)
           Sets the name of the catalog this table is contained in; must be null, if the table is not contained in a catalog.
 void setContainer(TableContainer container)
           Sets the TableContainer this table is contained in; must be null, if the table is not contained in one.
 void setDbPK(PK dbPK)
          Sets the primary key (PK) defined in the DB.
 void setDbTable(boolean dbTable)
          Sets whether this table is a DB-Table or not.
 void setExportedKeys(List<FK> exportedKeys)
          Sets the exported keys.
 void setFDMinCover(Set<FD> minCover)
          Sets the minimal cover of FDs for this table.
 void setFDs(Set<FD> fds)
          Sets the FDs for this table.
 void setImportedKeys(List<FK> importedKeys)
          Sets the imported keys.
 void setNfDeterminationResult(NFDeterminationResult nfDeterminationResult)
          Sets the result of the normal form determination for this table.
 void setNormProposal(NormalizationProposal normProposal)
          Sets the normalization proposal for this table.
 void setPk(PK pk)
          Sets the PK for this table.
 void setSchema(String schema)
           Sets the name of the schema this table is contained in; must be null, if the table is not contained in a schema.
 
Methods inherited from class de.fesenmeyer.dbnormalizer.core.AbstractDBItem
getName, setName, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

catalog

private String catalog
The catalog this table is contained in, may be null.


schema

private String schema
The schema this table is contained in, may be null.


container

private TableContainer container
The TableContainer this table is contained in.


attributes

private AttributeStringSet attributes
The set of attributes belonging to this table.


columnInfos

private Map<String,TableColumn> columnInfos
A map containing tableColumn information for each attribute. Is empty, if the table is not a DB-Table.


dbPK

private PK dbPK
The PK defined in the DB. Is null, if the table is not a DB-Table.


pk

private PK pk
The PK selected by DBNormalizer when calculating candidate keys or by the user.


exportedKeys

private List<FK> exportedKeys
The exported keys for this table.

See Also:
DatabaseMetaData.getExportedKeys(String, String, String)

importedKeys

private List<FK> importedKeys
The imported keys for this table.

See Also:
DatabaseMetaData.getImportedKeys(String, String, String)

FDs

private Set<FD> FDs
The set of functional dependencies (FDs) for this table, just as it has been specified by the user or imported from a file. May contain redundant FDs.

NOTE: Everytime you change these FDs, make sure you recompute the minimal cover and update FDMinCover, before determining candidate keys, normal form or creating a normalization proposal.


FDMinCover

private Set<FD> FDMinCover
A minimal cover of the functional dependencies (FDs) contained in FDs.


candKeys

private Set<CandKey> candKeys
The candidate keys.


nfDeterminationResult

private NFDeterminationResult nfDeterminationResult
The result of the normal form determination for this table. May be null, if the normal form has not yet been determined.


normProposal

private NormalizationProposal normProposal
The normalization proposal for this table. May be null, if the table should not be normalized or if a normalization proposal has not yet been created.


dbTable

private boolean dbTable
A flag which specifies if the table is a DB-Table or not.

See Also:
Table
Constructor Detail

Table

public Table()
Method Detail

getFDMinCover

public Set<FD> getFDMinCover()
Gets the minimal cover of FDs for this table.

Returns:
the minimal cover of FDs
See Also:
FDMinCover

setFDMinCover

public void setFDMinCover(Set<FD> minCover)
Sets the minimal cover of FDs for this table.

Parameters:
minCover - the minimal cover of FDs
See Also:
FDMinCover

getAttributes

public AttributeStringSet getAttributes()
Gets the set of attributes belonging to this table.

Returns:
the attributes

setAttributes

public void setAttributes(AttributeStringSet attributes)
Sets the set of attributes belonging to this table.

Parameters:
attributes - the attributes

getFDs

public Set<FD> getFDs()
Gets the FDs for this table.

Returns:
the FDs
See Also:
FDs

setFDs

public void setFDs(Set<FD> fds)
Sets the FDs for this table.

Parameters:
fds - the FDs
See Also:
FDs

getExportedKeys

public List<FK> getExportedKeys()
Gets the exported keys.

Returns:
the exported keys
See Also:
DatabaseMetaData.getExportedKeys(String, String, String)

setExportedKeys

public void setExportedKeys(List<FK> exportedKeys)
Sets the exported keys.

Parameters:
exportedKeys - the exported keys
See Also:
DatabaseMetaData.getExportedKeys(String, String, String)

getPk

public PK getPk()
Gets the PK for this table.

Returns:
the PK
See Also:
pk

setPk

public void setPk(PK pk)
Sets the PK for this table.

Parameters:
pk - the PK
See Also:
pk

getImportedKeys

public List<FK> getImportedKeys()
Gets the imported keys.

Returns:
the imported keys
See Also:
DatabaseMetaData.getImportedKeys(String, String, String)

setImportedKeys

public void setImportedKeys(List<FK> importedKeys)
Sets the imported keys.

Parameters:
importedKeys - the imported keys
See Also:
DatabaseMetaData.getImportedKeys(String, String, String)

equals

public boolean equals(Object o)
Overridden Method, tests if this table is equal to the o argument based on the qualified name.

Overrides:
equals in class Object
Parameters:
o - the Object to test if it is equal to this table
Returns:
true, if o is not null, is a table and the getQualifiedName() method returns equal values for both this table and the table specified by the o argument; false, otherwise

getQualifiedName

public String getQualifiedName()
Gets the qualified name for this table. This is the table's (simple) name qualified by the catalog or schema it is contained in. If it is neither contained in a catalog nor schema, the qualified name equals to the table's (simple) name.

Returns:
the table's qualified name

getCatalog

public String getCatalog()
Gets the name of the catalog this table is contained in.

Returns:
the name of the table's catalog, if it is contained in one; null, otherwise

setCatalog

public void setCatalog(String catalog)

Sets the name of the catalog this table is contained in; must be null, if the table is not contained in a catalog.

NOTE: If this method is called, the setContainer(TableContainer) method should also be called in order to avoid inconsistencies.

Parameters:
catalog - the catalog's name or null

getSchema

public String getSchema()
Gets the name of the schema this table is contained in.

Returns:
the name of the table's schema, if it is contained in one; null, otherwise

setSchema

public void setSchema(String schema)

Sets the name of the schema this table is contained in; must be null, if the table is not contained in a schema.

NOTE: If this method is called, the setContainer(TableContainer) method should also be called in order to avoid inconsistencies.

Parameters:
schema - the schema's name or null

getContainer

public TableContainer getContainer()
Gets the TableContainer this table is contained in.

Returns:
the TableContainer this table is contained in, if it is contained in one; null, otherwise
See Also:
TableContainer

setContainer

public void setContainer(TableContainer container)

Sets the TableContainer this table is contained in; must be null, if the table is not contained in one.

NOTE: If this method is called, the setCatalog(String) and/or setSchema(String) method(s) should also be called in order to avoid inconsistencies.

Parameters:
container - the table's container or null

getCandKeys

public Set<CandKey> getCandKeys()
Gets this table's candidate keys (if they have already been set).

Returns:
this table's candidate keys, if they have already been set; an empty set, otherwise

setCandKeys

public void setCandKeys(Set<CandKey> candKeys)
Sets this table's candidate keys. If necessary, You should also reset this table's primary key by means of the setPk(PK) method.

Parameters:
candKeys - this table's candidate keys

getNfDeterminationResult

public NFDeterminationResult getNfDeterminationResult()
Gets the result of the normal form determination for this table.

Returns:
the result of the normal form determination for this table; null, if it has not yet been set for this table.

setNfDeterminationResult

public void setNfDeterminationResult(NFDeterminationResult nfDeterminationResult)
Sets the result of the normal form determination for this table.

Parameters:
nfDeterminationResult - the result of the normal form determination

isDbTable

public boolean isDbTable()
States whether this table is a DB-Table or not.

Returns:
true, if it is a DB-Table; false, otherwise
See Also:
Table

setDbTable

public void setDbTable(boolean dbTable)
Sets whether this table is a DB-Table or not.

Parameters:
dbTable - must be true, if it is a DB-Table; false, otherwise
See Also:
Table

getDbPK

public PK getDbPK()
Gets the primary key (PK) defined in the DB.

Returns:
the PK defined in the DB;null, if none has been defined in the DB

setDbPK

public void setDbPK(PK dbPK)
Sets the primary key (PK) defined in the DB.

Parameters:
dbPK - the PK defined in the DB; must be null, if none has been defined in the DB

getColumnInfo

public TableColumn getColumnInfo(String colName)
Gets TableColumn information for the column (attribute) specified by the colName argument.

Parameters:
colName - the column's name
Returns:
a TableColumn object, if this table is a DB-Table and the column specified by the colName argument exists; null, otherwise.

getColumnInfos

public Collection<TableColumn> getColumnInfos()
Gets TableColumn information for each of the table's columns (attributes).

Returns:
a Collection of TableColumn objects, if this table is a DB-Table; an empty set, otherwise

addColumnInfo

public void addColumnInfo(String colName,
                          TableColumn col)
Adds the TableColumn information specified by argument col for the column (attribute) specified by argument colName. NOTE: The colName argument must be an element of the set returned by the getAttributes() method.

Parameters:
colName - the column (attribute) name
col - the TableColumn object

getNormProposal

public NormalizationProposal getNormProposal()
Gets the currently set normalization proposal for this table.

Returns:
the (currently set) normalization proposal; null, if a normalization proposal has not yet been set

setNormProposal

public void setNormProposal(NormalizationProposal normProposal)
Sets the normalization proposal for this table. Overrides a previously set normalization proposal.

Parameters:
normProposal - a normalization proposal

compareTo

public int compareTo(Table table)
Compares this table to another table based on the qualified names of the tables. Can be used to order the tables alphabetically.

Specified by:
compareTo in interface Comparable<Table>
Parameters:
table - another table
Returns:
Returns
  • an int value smaller than 0, if this table's qualified name is smaller than the other table's qualified name in terms of the alphabetical order.
  • 0, if this table's qualified name exactly equals the other table's qualified name.
  • an int value greater than 0, if this table's qualified name is greater than the other table's qualified name in terms of the alphabetical order.