de.fesenmeyer.dbnormalizer.core.dbaccess
Class DBConnectionManager

java.lang.Object
  extended by de.fesenmeyer.dbnormalizer.core.dbaccess.DBConnectionManager

public final class DBConnectionManager
extends Object

Singleton class to create, get and remove SQuirreL-DB connections. Provides a single access for DB-Connections and the possibility to work with more than one session at once.

Author:
DF

Field Summary
private  HashMap<String,net.sourceforge.squirrel_sql.fw.sql.SQLConnection> connections
          HashMap holding the connections (keyed by a session name).
private static DBConnectionManager INSTANCE
          The singleton instance.
 
Constructor Summary
private DBConnectionManager()
          Makes the constructor inaccessible.
 
Method Summary
 net.sourceforge.squirrel_sql.fw.sql.SQLConnection createAndAddConnection(String sessionName, DBConfig dbConfig)
          Creates, adds and returns a connection for the session with the specified name and DB configuration.
 net.sourceforge.squirrel_sql.fw.sql.SQLConnection getConnection(String sessionName)
          Returns the connection for the session specified by argument sessionName.
static DBConnectionManager getInstance()
          Gets the single instance of the class.
 void removeConnection(String sessionName)
          Removes and closes the connection for the session specified by argument sessionName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connections

private HashMap<String,net.sourceforge.squirrel_sql.fw.sql.SQLConnection> connections
HashMap holding the connections (keyed by a session name).


INSTANCE

private static DBConnectionManager INSTANCE
The singleton instance.

Constructor Detail

DBConnectionManager

private DBConnectionManager()
Makes the constructor inaccessible.

Method Detail

getInstance

public static DBConnectionManager getInstance()
Gets the single instance of the class.

Returns:
the DBConnectionManager instance

createAndAddConnection

public net.sourceforge.squirrel_sql.fw.sql.SQLConnection createAndAddConnection(String sessionName,
                                                                                DBConfig dbConfig)
                                                                         throws DBException
Creates, adds and returns a connection for the session with the specified name and DB configuration.

Parameters:
sessionName - the session name
dbConfig - the DB-Configuration
Returns:
a SQuirreL-SQLConnection object
Throws:
DBException - if an Exception occurs creating the connection. Can have many reasons, e.g.:
  • The DB-URL is incorrect or the specified DB does not exist.
  • The path specified for the JDBC-Driver is incorrect.
  • The driver class can not be loaded, e.g. because the specified class name is incorrect.
  • The specified username or password for the DB is incorrect.

getConnection

public net.sourceforge.squirrel_sql.fw.sql.SQLConnection getConnection(String sessionName)
Returns the connection for the session specified by argument sessionName.

Parameters:
sessionName - the session name
Returns:
a SQuirreL-SQLConnection, if a connection has already been added for the specified session; null, otherwise

removeConnection

public void removeConnection(String sessionName)
                      throws DBException
Removes and closes the connection for the session specified by argument sessionName.

Parameters:
sessionName - the session name
Throws:
DBException - If an exception occurs when closing the connection