org.enableit.db
Class ConnectionFactory

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

Deprecated. This is just the legacy code, things of ongoing use are in the new ancestor.

public class ConnectionFactory
extends ConnFactory

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

Over time this class has evolved to fulfil different goals, but is maintained for backwards compatibility. There are two principle uses:

  1. Connection to a single database when no runtime configuration mechanism (e.g. JNDI / user login form) exists.
  2. Connection to one or more databases whether or not runtime configuration exists (If such a mechanism exists you are advised to use it).
It is important not to mix these two usages as unexpected results may ensue.

In the first case, 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 (i.e. org.enableit.db). These may be overridden by the use of the setProperty method.

In the second case this class is simply for encapsulation. In other words it offers a way to hide the actual mechanism of finding the database connection to the higher level (application) logic. This allows a J2EE application to use JNDI to obtain connections and a thick-client application configured by a logon screen to both employ common logic whilst this factory takes care of how to find connections at runtime.

This class has been tested with the following database drivers:

Version:
v1.0
Author:
__AUTHOR__

Field Summary
static java.lang.String ABOUT
          Deprecated. Information on the exact CVS version accessible after compilation
protected static org.apache.log4j.Category logger
          Deprecated. The Log4J Category doing the logging.
 
Method Summary
static java.sql.Connection getConnection()
          Deprecated. Returns a connection to the database identified by the class's resource properties.
static java.sql.Connection getConnection(java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String password)
          Deprecated. Returns a connection to the database identified by the supplied properties.
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)
          Deprecated. Returns a connection to the database identified by the supplied properties.
 java.util.Set getConnectionNames()
          Deprecated. Returns the names of configured database connections.
protected  java.lang.Object getDriver(java.lang.String className)
          Deprecated. Obtain a JDBC driver class.
static org.enableit.db.ConnectionFactory getInstance()
          Deprecated. Factory method to obtain the connection factory itself.
 org.enableit.db.beans.Provider getProvider(java.lang.String name)
          Deprecated. Obtain connection details for the named configuration.
static void setProperty(java.lang.String key, java.lang.String value)
          Deprecated. Set a connection property dynamically.
 
Methods inherited from class org.enableit.db.ConnFactory
getConnection, getConnection, registerDriver, registerDriverFromUrl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

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


ABOUT

public static final java.lang.String ABOUT
Deprecated. 
Information on the exact CVS version accessible after compilation

See Also:
Constant Field Values
Method Detail

getInstance

public static org.enableit.db.ConnectionFactory getInstance()
Deprecated. 
Factory method to obtain the connection factory itself.

Returns:
The ConnectionFactory singleton.

setProperty

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

This will override defaults changing the behaviour of the ConnectionFactory singleton.


getConnectionNames

public java.util.Set getConnectionNames()
Deprecated. 
Returns the names of configured database connections.

These are names that may be used successfully with .

Returns:
java.util.Set of connection names (of type String).
See Also:
getProvider(java.lang.String)

getProvider

public org.enableit.db.beans.Provider getProvider(java.lang.String name)
                                           throws DBException
Deprecated. 
Obtain connection details for the named configuration.

Parameters:
name - configuration name.
Returns:
Provider holding the connection details
Throws:
DBException - If the named configuration is not found.
See Also:
getConnectionNames()

getConnection

public static java.sql.Connection getConnection()
                                         throws DBException
Deprecated. 
Returns a connection to the database identified by the class's resource properties.

This is a very simplistic configuration option for applications that do not have any JNDI or user-maintained configuration options. It is not recommended.

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
Deprecated. 
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

public static java.sql.Connection getConnection(java.lang.String driver,
                                                java.lang.String url,
                                                java.lang.String user,
                                                java.lang.String password)
                                         throws DBException
Deprecated. 
Returns a connection to the database identified by the supplied properties.

Parameters may be empty strings, but may not be null.

Parameters:
driver -
url -
user -
password -
Returns:
Connection
Throws:
DBException - in the event of a problem creating the connection

getDriver

protected java.lang.Object getDriver(java.lang.String className)
                              throws DBException
Deprecated. 
Obtain a JDBC driver class.

DBException


Copyright © 1999-2004 enableIT.org. All Rights Reserved.