com.iplanet.jato
Class SQLConnectionManagerBase

java.lang.Object
  |
  +--com.iplanet.jato.SQLConnectionManagerBase
All Implemented Interfaces:
SQLConnectionManager

public class SQLConnectionManagerBase
extends java.lang.Object
implements SQLConnectionManager

A base implementation of the SQLConnectionManager interface. This implementation goes beyond that specified by the SQLConnectionManager interface to provide static methods that can be used outside the scope of a request. This is helpful for initialization of certain JATO objects.

Developers need not create any instances of this class. A single instance is automatically created at the beginning of the request and stored in the request context.

This class supports two alternative, mutually exclusive policies for obtaining connection objects. The preferred policy is to use JNDI lookups as specified by the JDBC 2.0 Standard Extension to obtain connections. The other less prefered policy is to obtain connections directly from the JDBC DriverManager using datasource to JDBC URL mappings. This policy may be very useful during development, but once an application is running in a properly configured J2EE container, the JNDI policy should always be used for performance reasons.

The actual mapping of datasource names to their respective connection strings can only be done at the application level. Therefore, this class is designed to be the base class implementation for an application-specific SQLConnectionManagerImpl class.

Version:
JATO/1.2.2 $Id: SQLConnectionManagerBase.java,v 1.25 2002/07/13 02:34:09 todd Exp $

Constructor Summary
SQLConnectionManagerBase()
          Default constructor
 
Method Summary
static void addDataSourceMapping(java.lang.String dataSourceName, java.lang.String mappedValue)
          Adds a datasource name mapping.
 java.sql.Connection getConnection(java.lang.String dataSource)
          Return a JDBC Connection for the specified datasource.
 java.sql.Connection getConnection(java.lang.String dataSource, java.lang.String user, java.lang.String password)
          Return a JDBC Connection from the specified datasource with the provided user and password.
protected static java.lang.String getMappedDataSourceName(java.lang.String dataSourceName)
          Returns the mapped value for a datasource name, if any
static boolean isUsingJNDI()
          Return whether or not the JNDI lookup is the current connection retreival policy
static java.sql.Connection obtainConnection(java.lang.String dataSource)
          Return a JDBC Connection for the specified datasource.
static java.sql.Connection obtainConnection(java.lang.String dataSource, java.lang.String user, java.lang.String password)
          Return a JDBC Connection for the specified datasource.
static void setUsingJNDI(boolean value)
          Set whether or not the JNDI lookup is the current connection retreival policy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLConnectionManagerBase

public SQLConnectionManagerBase()
Default constructor
Method Detail

getConnection

public java.sql.Connection getConnection(java.lang.String dataSource)
                                  throws java.sql.SQLException
Return a JDBC Connection for the specified datasource. This method will attempt to map the provided datasource name to the actual datasource name using the existing datasource mappings. If a mapping doesn't exist for the provided name, the name will be used to obtain a connection.
Specified by:
getConnection in interface SQLConnectionManager
Following copied from interface: com.iplanet.jato.SQLConnectionManager
Parameters:
dataSource - The desired datasource name. This parameter may either be the actual JNDI lookup string or an arbitrary logical name.
Returns:
The JDBC connection corresponding to the specified datasource
Throws:
java.sql.SQLException - Thrown if there is a problem getting a connection

getConnection

public java.sql.Connection getConnection(java.lang.String dataSource,
                                         java.lang.String user,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Return a JDBC Connection from the specified datasource with the provided user and password. This method will attempt to map the provided datasource name to the actual datasource name using the existing datasource mappings. If a mapping doesn't exist for the provided name, the name will be used to obtain a connection.
Specified by:
getConnection in interface SQLConnectionManager
Following copied from interface: com.iplanet.jato.SQLConnectionManager
Parameters:
dataSource - The desired datasource name. This parameter may either be the actual JNDI lookup string or an arbitrary logical name.
user - The user ID for the desired connection
password - The password for the desired connection
Returns:
The JDBC connection corresponding to the specified datasource
Throws:
java.sql.SQLException - Thrown if there is a problem getting a connection

obtainConnection

public static java.sql.Connection obtainConnection(java.lang.String dataSource)
                                            throws java.sql.SQLException
Return a JDBC Connection for the specified datasource. This method is comparable to the non-static getConnection( String dataSource) method. This static method provides a way to obtain a JDBC connection outside the scope of a request. This is useful for objects that retrieve data outside the scope of a request, for example during static initialization. Objects within the scope of a request should use the non-static method equivalent.
Parameters:
dataSource - The desired datasource name. This parameter may either be the actual JNDI lookup string or an arbitrary logical name.
Returns:
The JDBC connection corresponding to the specified datasource
Throws:
java.sql.SQLException - Thrown if there is a problem getting a connection

obtainConnection

public static java.sql.Connection obtainConnection(java.lang.String dataSource,
                                                   java.lang.String user,
                                                   java.lang.String password)
                                            throws java.sql.SQLException
Return a JDBC Connection for the specified datasource. This method is comparable to the non-static getConnection( String dataSource, String user, String password) method. This static method provides a way to obtain a JDBC connection outside the scope of a request. This is useful for objects that retrieve data outside the scope of a request, for example during static initialization. Objects within the scope of a request should use the non-static method equivalent.
Parameters:
dataSource - The desired datasource name. This parameter may either be the actual JNDI lookup string or an arbitrary logical name.
user - The user ID for the desired connection
password - The password for the desired connection
Returns:
The JDBC connection corresponding to the specified datasource
Throws:
java.sql.SQLException - Thrown if there is a problem getting a connection

addDataSourceMapping

public static void addDataSourceMapping(java.lang.String dataSourceName,
                                        java.lang.String mappedValue)
Adds a datasource name mapping. This method should only be called during the initialization of an application, preferranby in the static initializer of the application-specific subclass of this class.
Parameters:
dataSourceName - The desired datasource name. This parameter may either be the actual JNDI lookup string or an arbitrary logical name.
value - This value can be a JNDI datasource name or a JDBC URL. The appropriate value depends on the current policy for obtaining connections.

getMappedDataSourceName

protected static java.lang.String getMappedDataSourceName(java.lang.String dataSourceName)
Returns the mapped value for a datasource name, if any
Parameters:
dataSourceName - The desired datasource name. This parameter may either be the actual JNDI lookup string or an arbitrary logical name.
Returns:
The mapped value for the datasource name, or null if one does not exist

isUsingJNDI

public static boolean isUsingJNDI()
Return whether or not the JNDI lookup is the current connection retreival policy

setUsingJNDI

public static void setUsingJNDI(boolean value)
Set whether or not the JNDI lookup is the current connection retreival policy