org.enableit.db
Class ConnectionFactory

java.lang.Object
  |
  +--org.enableit.db.ConnectionFactory

public class ConnectionFactory
extends java.lang.Object

General class intended to hide the process of obtaining database connections to any database

The connection properties such as server name, username/password etc are all stored in a file named db.properties in the package level directory matching this class (ie thestephensons.db)

Internal methods then arrange these in the way to construct a Connection of the required type. Because this may vary from one vendor to the next, internally specific methods exist for each database driver vendor

Supported database drivers currently are:

Version:
v1.0
Author:
chris.pettifer@enableit.org

Field Summary
static java.lang.String about
          Information on the exact CVS version accessible after compilation
protected static org.apache.log4j.Category cat
          The Log4J Category doing the logging.
private static ConnectionFactory me
          Reference to the singleton instance NB the singleton status is not enforced via a synchronise statement
private static java.util.Properties props
          The current database properties to make connections with
 
Constructor Summary
private ConnectionFactory()
          Default Constructor
 
Method Summary
static java.sql.Connection getConnection()
          Returns a connection to the database identified by the class's resource properties
protected static java.sql.Connection getConnection(java.util.Properties props)
          Returns a connection to the database identified by the Properties supplied
static java.sql.Connection getConnection(java.lang.String driver, java.lang.String database, java.lang.String server, java.lang.String port, java.lang.String protocol, java.lang.String user, java.lang.String password)
          Returns a connection to the database identified by the supplied properties
static ConnectionFactory getInstance()
          Factory method
private static java.sql.Connection getMySQLConnection(java.util.Properties props)
           
private static java.sql.Connection getSybConnection(java.util.Properties props)
           
static void setProperty(java.lang.String key, java.lang.String value)
          Set a connection property dynamically
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

cat

protected static org.apache.log4j.Category cat
The Log4J Category doing the logging. Same Category is used throughout the package.

me

private static ConnectionFactory me
Reference to the singleton instance NB the singleton status is not enforced via a synchronise statement

props

private static java.util.Properties props
The current database properties to make connections with

about

public static final java.lang.String about
Information on the exact CVS version accessible after compilation
Constructor Detail

ConnectionFactory

private ConnectionFactory()
Default Constructor
Method Detail

getInstance

public static ConnectionFactory getInstance()
Factory method

setProperty

public static void setProperty(java.lang.String key,
                               java.lang.String value)
Set a connection property dynamically

getConnection

public static java.sql.Connection getConnection()
                                         throws DBException
Returns a connection to the database identified by the class's resource properties
Returns:
Connection
Throws:
DBException - in the event of a problem creating the connection

getConnection

public static java.sql.Connection getConnection(java.lang.String driver,
                                                java.lang.String database,
                                                java.lang.String server,
                                                java.lang.String port,
                                                java.lang.String protocol,
                                                java.lang.String user,
                                                java.lang.String password)
                                         throws DBException

Returns a connection to the database identified by the supplied properties

Parameters may be empty strings, but may not be null

Parameters:
driver -  
database -  
server -  
port -  
protocol -  
user -  
password -  
Returns:
Connection
Throws:
DBException - in the event of a problem creating the connection

getConnection

protected static java.sql.Connection getConnection(java.util.Properties props)
                                            throws DBException
Returns a connection to the database identified by the Properties supplied
Returns:
Connection
Throws:
DBException - in the event of a problem creating the connection

getMySQLConnection

private static java.sql.Connection getMySQLConnection(java.util.Properties props)
                                               throws java.sql.SQLException,
                                                      DBException

getSybConnection

private static java.sql.Connection getSybConnection(java.util.Properties props)
                                             throws java.sql.SQLException,
                                                    DBException


Copyright © enableIT.org 1999,2000,2001,2002 All Rights Reserved.