de.fesenmeyer.dbnormalizer.core
Class DBNormalizerSession

java.lang.Object
  extended by de.fesenmeyer.dbnormalizer.core.DBNormalizerSession

public class DBNormalizerSession
extends Object

DBNormalizerSession is a class holding all information needed and collected by DBNormalizer during the analysis of one or more tables (for example, a DB Schema). It provides a context, which is used by several classes from DBNormalizer to retrieve or store information.

Author:
DF

Field Summary
private  DBConfig dbConfig
          The DB-configuration data for this session.
private static DBNormalizerLogger logger
          The logger for this class.
private  String sessionName
          The (unique) name of the session.
private  net.sourceforge.squirrel_sql.fw.sql.SQLConnection sqlConnection
          A SQuirreL-SQL-Connection object which is used for retrieving database information.
private  TreeMap<TableContainer,Set<Table>> tables2normalize
          A Map containing sets of tables to be normalized.
 
Constructor Summary
DBNormalizerSession()
          Class Constructor for creating a session without DB-Configuration.
DBNormalizerSession(DBConfig dbConfig)
          Class Constructor for creating a session with DB-Configuration.
 
Method Summary
 boolean addTable2Normalize(TableContainer tableContainer, Table table)
          Adds a table to the set of tables to be normalized.
 boolean addTableContainer2Normalize(TableContainer tableContainer)
          Adds a TableContainer to the session.
 void addTableInformation(Collection<TableContainerConfig> tableContainerConfigs)
          Adds tables to be normalized to this session, based on configuration data.
private  void assignFrom(DBConfig dbConfig)
          Assign a DB-Configuration to this session.
 void closeSession()
          Closes the session by closing the connection to the DB.
private  void createAndAddTable2Normalize(TableContainer tableContainer, TableConfig tableConfig, boolean loadFromDB)
          Helper method for creating one table and its FDs based on configuration data and adding this information to the tables2normalize Map.
private  AttributeSetConfig createAttributeSetConfig(AttributeStringSet attributes)
           
 SessionConfig createSessionConfig(String configFileName)
          Creates a session configuration from the current state of the session.
private  void createTables2normalizeFromConfig(Collection<TableContainerConfig> tableContainerConfigs)
          Adds the tables given in the tableContainerConfigs argument (with their FDs) to the tables2normalize map
private  Table findTableFromDB(Table table)
          Helper Method for retrieving table information from the database.
 Connection getConnection()
          Gets the SQuirreL-SQL-Connection, if a connection to a DB exists.
 DBConfig getDbConfig()
          Gets the DB-Configuration used to establish a connection to a DB.
 net.sourceforge.squirrel_sql.fw.sql.SQLConnection getSqlConnection()
           
 Set<TableContainer> getTableContainers2Normalize()
          Gets all TableContainers which contain tables which are in the set of tables to be normalized.
 Set<Table> getTables2Normalize(TableContainer tableContainer)
          Gets all tables which are in the set of tables to be normalized and are contained in the TableContainer specified by argument tableContainer.
 void removeTableContainer2Normalize(TableContainer tableContainer)
          Removes the TableContainer specified by argument tableContainer and all tables, which are in the set of tables to be normalized and are contained in this tableContainer, from the internal data representation.
 void startSession()
          Starts the session by creating a connection to the DB specified by the dbConfig member.
 
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.


sessionName

private String sessionName
The (unique) name of the session.


dbConfig

private DBConfig dbConfig
The DB-configuration data for this session.


sqlConnection

private net.sourceforge.squirrel_sql.fw.sql.SQLConnection sqlConnection
A SQuirreL-SQL-Connection object which is used for retrieving database information.


tables2normalize

private TreeMap<TableContainer,Set<Table>> tables2normalize
A Map containing sets of tables to be normalized. They are separated by TableContainer, the key of the map.

Constructor Detail

DBNormalizerSession

public DBNormalizerSession()
Class Constructor for creating a session without DB-Configuration.


DBNormalizerSession

public DBNormalizerSession(DBConfig dbConfig)
                    throws DBException
Class Constructor for creating a session with DB-Configuration.

Parameters:
dbConfig - the DB-Configuration object
Throws:
DBException - If an exception occurs when accessing the DB.
Method Detail

addTableInformation

public void addTableInformation(Collection<TableContainerConfig> tableContainerConfigs)
Adds tables to be normalized to this session, based on configuration data.

Parameters:
tableContainerConfigs - configuration data

assignFrom

private void assignFrom(DBConfig dbConfig)
                 throws DBException
Assign a DB-Configuration to this session.

Parameters:
dbConfig - the DB-Configuration
Throws:
DBException - If an exception occurs when accessing the DB.

createTables2normalizeFromConfig

private void createTables2normalizeFromConfig(Collection<TableContainerConfig> tableContainerConfigs)
Adds the tables given in the tableContainerConfigs argument (with their FDs) to the tables2normalize map

Parameters:
tableContainerConfigs - the tableContainer configuration data

createAndAddTable2Normalize

private void createAndAddTable2Normalize(TableContainer tableContainer,
                                         TableConfig tableConfig,
                                         boolean loadFromDB)
Helper method for creating one table and its FDs based on configuration data and adding this information to the tables2normalize Map.

Parameters:
tableContainer - the tableContainer containing the table
tableConfig - the configuration data of the table
loadFromDB - true, if table information (such as attribute names) should be loaded from a DB; false, otherwise (that means attribute names must be stored in the configuration)

findTableFromDB

private Table findTableFromDB(Table table)
Helper Method for retrieving table information from the database.

Parameters:
table - a table object at least containing name, catalog and schema information
Returns:
the table found in the database;null, if the table could not be found

startSession

public void startSession()
                  throws DBException
Starts the session by creating a connection to the DB specified by the dbConfig member. If there is no DB-Configuration given, the method does nothing.

Throws:
DBException - If an exception occurs when connecting to the DB.

closeSession

public void closeSession()
                  throws DBException
Closes the session by closing the connection to the DB. If there is no DB-Configuration given, the method does nothing.

Throws:
DBException - If an exception occurs when closing the connection.

getConnection

public Connection getConnection()
Gets the SQuirreL-SQL-Connection, if a connection to a DB exists.

Returns:
the SQuirrel-SQL-Connection, if a connection to a DB exists; null, otherwise.

getDbConfig

public DBConfig getDbConfig()
Gets the DB-Configuration used to establish a connection to a DB.

Returns:
the DB-Configuration, if one is specified; null, otherwise.

getTableContainers2Normalize

public Set<TableContainer> getTableContainers2Normalize()
Gets all TableContainers which contain tables which are in the set of tables to be normalized.

Returns:
a set of TableContainers, which may be empty.

getTables2Normalize

public Set<Table> getTables2Normalize(TableContainer tableContainer)
Gets all tables which are in the set of tables to be normalized and are contained in the TableContainer specified by argument tableContainer.

Parameters:
tableContainer - a TableContainer
Returns:
a set of Tables, which may be empty.

addTableContainer2Normalize

public boolean addTableContainer2Normalize(TableContainer tableContainer)
Adds a TableContainer to the session. This method just adds a tableContainer to the internal data representation, which makes it possible to add tables to to be normalized to this container.

Parameters:
tableContainer - a TableContainer
Returns:
true, if it has been successfully added; false, otherwise (if it has already been added before this method call).

addTable2Normalize

public boolean addTable2Normalize(TableContainer tableContainer,
                                  Table table)
Adds a table to the set of tables to be normalized. Because the tables are grouped by TableContainer internally, not only the table argument, but also the tableContainer argument has to be specified.

Parameters:
tableContainer - the TableContainer the table is contained in
table - the table
Returns:
true, if the table has been successfully added; false, otherwise (if it has already been added before this method call).

removeTableContainer2Normalize

public void removeTableContainer2Normalize(TableContainer tableContainer)
Removes the TableContainer specified by argument tableContainer and all tables, which are in the set of tables to be normalized and are contained in this tableContainer, from the internal data representation.

Parameters:
tableContainer - a TableContainer

createSessionConfig

public SessionConfig createSessionConfig(String configFileName)
Creates a session configuration from the current state of the session. This session configuration can then be saved to a file by means of the ConfigurationWriter class.

Parameters:
configFileName - the file where the session configuration should be saved
Returns:
the created session configuration

createAttributeSetConfig

private AttributeSetConfig createAttributeSetConfig(AttributeStringSet attributes)

getSqlConnection

public net.sourceforge.squirrel_sql.fw.sql.SQLConnection getSqlConnection()