net.toften.jlips.persist.db
Class DBConnectionFactory

java.lang.Object
  extended by net.toften.jlips.persist.db.DBConnectionFactory

public final class DBConnectionFactory
extends Object

This class act as a factory for database connections. Because

Version:
$Revision: 1.6 $
Author:
thomas

Constructor Summary
DBConnectionFactory()
           
 
Method Summary
static DBStatement createStatement()
          Returns a new SQL statement from the statement manager
static Connection getConnection()
          Request a connection from the associated connection handler
static DBProperties getDBProperties()
          Get the DBProperties object
static DBTableColumnInfo getPrimaryKeyField(DBTableInfo tableName)
          Get the last primary key field name for the specified table
static List getTableFields(DBTableInfo tableName)
          Returns a List containing DBTableColumnInfo objects for all the fields in the specified table
static List getTableNames()
          Returns a List containing DBTableInfo objects for all the tables in the database
static void init(DBProperties connectionProperties)
          Initialises the database connectivity with provided DBProperties object.
static void init(Map dbInitProp)
          This method initialises the Database Connection Factory The method will validate, that all parameters has been supplied are correct.
static void releaseConnection(Connection theConnection)
          Release a requested connection After the application is done using the connection, it should invoke this method to inform the connection handler that it doesn't need the connection anymore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBConnectionFactory

public DBConnectionFactory()
Method Detail

init

public static void init(Map dbInitProp)
                 throws ClassNotFoundException,
                        IllegalAccessException,
                        InstantiationException,
                        DBBadPropertiesException,
                        SQLException
This method initialises the Database Connection Factory The method will validate, that all parameters has been supplied are correct. The method will load an instantiate the supplied database properties

Parameters:
dbInitProp - The database properties that was supplied
Throws:
ClassNotFoundException - Thrown if the classes specified in the database properties could not be loaded or instantiated
IllegalAccessException - See Class.forName(java.lang.String)
InstantiationException - See Class.forName(java.lang.String)
DBBadPropertiesException - Thrown if the properties provided to jLips are wrong
SQLException - Thrown if the database metadata could not be read
See Also:
EntityFactory.init(Properties, Map)

init

public static void init(DBProperties connectionProperties)
                 throws ClassNotFoundException,
                        IllegalAccessException,
                        InstantiationException,
                        DBBadPropertiesException,
                        SQLException
Initialises the database connectivity with provided DBProperties object. This method will use the database connection properties provided in the supplied DBProperties object instead of loading and instantiating a named connection properties object. It will also use the default statement manager and connection manager

Parameters:
connectionProperties - Database connection properties object
Throws:
ClassNotFoundException - Thrown if the classes specified in the database properties could not be loaded or instantiated
IllegalAccessException - See Class.newInstance()
InstantiationException - See Class.newInstance()
DBBadPropertiesException - Thrown if the properties provided to jLips are wrong
SQLException - Thrown if the database metadata could not be read
See Also:
DEFAULT_CON, DEFAULT_STM

getConnection

public static Connection getConnection()
                                throws SQLException
Request a connection from the associated connection handler

Returns:
A Connection object to the database
Throws:
SQLException
See Also:
DataSource.getConnection()

releaseConnection

public static void releaseConnection(Connection theConnection)
Release a requested connection After the application is done using the connection, it should invoke this method to inform the connection handler that it doesn't need the connection anymore

Parameters:
theConnection - The not needed connection

getDBProperties

public static DBProperties getDBProperties()
Get the DBProperties object

Returns:
A reference to the database connection properties

getTableNames

public static List getTableNames()
                          throws SQLException
Returns a List containing DBTableInfo objects for all the tables in the database

Returns:
List containing DBTableInfo objects
Throws:
SQLException

getTableFields

public static List getTableFields(DBTableInfo tableName)
                           throws SQLException
Returns a List containing DBTableColumnInfo objects for all the fields in the specified table

Parameters:
tableName - The table info of the table
Returns:
List containing DBTableColumnInfo objects
Throws:
SQLException

getPrimaryKeyField

public static DBTableColumnInfo getPrimaryKeyField(DBTableInfo tableName)
                                            throws SQLException
Get the last primary key field name for the specified table

Parameters:
tableName - The table info of the table
Returns:
A column handler for the primary key
Throws:
SQLException

createStatement

public static DBStatement createStatement()
                                   throws InstantiationException,
                                          IllegalAccessException
Returns a new SQL statement from the statement manager

Returns:
Instance of new SQL statement
Throws:
InstantiationException - See Class.newInstance()
IllegalAccessException - See Class.newInstance()