org.apache.ojb.broker.accesslayer
Class ConnectionFactoryAbstractImpl

java.lang.Object
  extended by org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl
All Implemented Interfaces:
ConnectionFactory
Direct Known Subclasses:
ConnectionFactoryDBCPImpl, ConnectionFactoryNotPooledImpl, ConnectionFactoryPooledImpl

public abstract class ConnectionFactoryAbstractImpl
extends Object
implements ConnectionFactory

Abstract base class to simplify implementation of ConnectionFactory's.

Version:
$Id: ConnectionFactoryAbstractImpl.java,v 1.1 2007-08-24 22:17:30 ewestfal Exp $
Author:
Armin Waibel

Constructor Summary
ConnectionFactoryAbstractImpl()
           
 
Method Summary
abstract  Connection checkOutJdbcConnection(JdbcConnectionDescriptor jcd)
          Returns a valid JDBC Connection.
protected  String getDbURL(JdbcConnectionDescriptor jcd)
           
protected  String getJcdDescription(JdbcConnectionDescriptor jcd)
           
protected  Properties getJdbcProperties(JdbcConnectionDescriptor jcd)
           
protected  Properties getJdbcProperties(JdbcConnectionDescriptor jcd, String user, String password)
          Returns connection properties for passing to DriverManager, after merging JDBC driver-specific configuration settings with name/password from connection descriptor.
protected  void initializeJdbcConnection(Connection con, JdbcConnectionDescriptor jcd)
          Initialize the connection with the specified properties in OJB configuration files and platform depended properties.
 Connection lookupConnection(JdbcConnectionDescriptor jcd)
          Lookup a connection from the connection factory implementation.
protected  Connection newConnectionFromDataSource(JdbcConnectionDescriptor jcd)
          Creates a new connection from the data source that the connection descriptor represents.
protected  Connection newConnectionFromDriverManager(JdbcConnectionDescriptor jcd)
          Returns a new created connection
 void releaseAllResources()
          Override this method to do cleanup in your implementation.
 void releaseConnection(JdbcConnectionDescriptor jcd, Connection con)
          Release connection - CAUTION: Release every connection after use to avoid abandoned connections.
abstract  void releaseJdbcConnection(JdbcConnectionDescriptor jcd, Connection con)
          Releases a Connection after use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionFactoryAbstractImpl

public ConnectionFactoryAbstractImpl()
Method Detail

checkOutJdbcConnection

public abstract Connection checkOutJdbcConnection(JdbcConnectionDescriptor jcd)
                                           throws LookupException
Returns a valid JDBC Connection. Implement this method in concrete subclasses. Concrete implementations using Connection pooling are responsible for any validation and pool removal management.

Note: This method is never called for a jdbc-connection-descriptor that uses datasources, OJB only manages connections from DriverManager.

Note: If the concrete implementation does not callback to newConnectionFromDriverManager(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor) when creating a new Connection, it must call initializeJdbcConnection(java.sql.Connection, org.apache.ojb.broker.metadata.JdbcConnectionDescriptor) so that the platform implementation can peform any RDBMS-specific init tasks for newly created Connection objetcs.

Parameters:
jcd - the connection descriptor for which to return a validated Connection
Returns:
a valid Connection, never null. Specific implementations must guarantee that the connection is not null and that it is valid.
Throws:
LookupException - if a valid Connection could not be obtained

releaseJdbcConnection

public abstract void releaseJdbcConnection(JdbcConnectionDescriptor jcd,
                                           Connection con)
                                    throws LookupException
Releases a Connection after use. Implement this method in concrete subclasses. Concrete implementations using Connection pooling are responsible for any validation and pool removal management.

Note: This method is never called for a jdbc-connection-descriptor that uses datasources, OJB only manages connections from DriverManager.

Parameters:
jcd - the connection descriptor for which the connection was created
con - the connection to release. Callers must guarantee that the passed connection was obtained by calling checkOutJdbcConnection(org.apache.ojb.broker.metadata.JdbcConnectionDescriptor).
Throws:
LookupException - if errors occured during release of object. Typically happens if return of object to pool fails in a pooled implementation.

releaseConnection

public void releaseConnection(JdbcConnectionDescriptor jcd,
                              Connection con)
Description copied from interface: ConnectionFactory
Release connection - CAUTION: Release every connection after use to avoid abandoned connections. Depending on the used implementation connection will be closed, returned to pool, ...

Specified by:
releaseConnection in interface ConnectionFactory

lookupConnection

public Connection lookupConnection(JdbcConnectionDescriptor jcd)
                            throws LookupException
Description copied from interface: ConnectionFactory
Lookup a connection from the connection factory implementation.

Specified by:
lookupConnection in interface ConnectionFactory
Throws:
LookupException

initializeJdbcConnection

protected void initializeJdbcConnection(Connection con,
                                        JdbcConnectionDescriptor jcd)
                                 throws LookupException
Initialize the connection with the specified properties in OJB configuration files and platform depended properties. Invoke this method after a NEW connection is created, not if re-using from pool.

Throws:
LookupException
See Also:
PlatformFactory, Platform

releaseAllResources

public void releaseAllResources()
Override this method to do cleanup in your implementation. Do a super.releaseAllResources() in your method implementation to free resources used by this class.

Specified by:
releaseAllResources in interface ConnectionFactory

newConnectionFromDataSource

protected Connection newConnectionFromDataSource(JdbcConnectionDescriptor jcd)
                                          throws LookupException
Creates a new connection from the data source that the connection descriptor represents. If the connection descriptor does not directly contain the data source then a JNDI lookup is performed to retrieve the data source.

Parameters:
jcd - The connection descriptor
Returns:
A connection instance
Throws:
LookupException - if we can't get a connection from the datasource either due to a naming exception, a failed sanity check, or a SQLException.

newConnectionFromDriverManager

protected Connection newConnectionFromDriverManager(JdbcConnectionDescriptor jcd)
                                             throws LookupException
Returns a new created connection

Parameters:
jcd - the connection descriptor
Returns:
an instance of Connection from the drivermanager
Throws:
LookupException

getJdbcProperties

protected Properties getJdbcProperties(JdbcConnectionDescriptor jcd,
                                       String user,
                                       String password)
Returns connection properties for passing to DriverManager, after merging JDBC driver-specific configuration settings with name/password from connection descriptor.

Parameters:
jcd - the connection descriptor with driver-specific settings
user - the jcd username (or null if not using authenticated login)
password - the jcd password (only used when user != null)
Returns:
merged properties object to pass to DriverManager

getJdbcProperties

protected Properties getJdbcProperties(JdbcConnectionDescriptor jcd)

getDbURL

protected String getDbURL(JdbcConnectionDescriptor jcd)

getJcdDescription

protected String getJcdDescription(JdbcConnectionDescriptor jcd)


Copyright © 2004-2012 The Kuali Foundation. All Rights Reserved.