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 java.lang.Object
implements ConnectionFactory

Abstract base class to simplify implementation of ConnectionFactory's.

Version:
$Id: ConnectionFactoryAbstractImpl.java 364802 2005-04-30 20:55:15Z mkalen $
Author:
Armin Waibel

Constructor Summary
ConnectionFactoryAbstractImpl()
           
 
Method Summary
abstract  java.sql.Connection checkOutJdbcConnection(JdbcConnectionDescriptor jcd)
          Returns a valid JDBC Connection.
 java.sql.Connection lookupConnection(JdbcConnectionDescriptor jcd)
          Lookup a connection from the connection factory implementation.
 void releaseAllResources()
          Override this method to do cleanup in your implementation.
 void releaseConnection(JdbcConnectionDescriptor jcd, java.sql.Connection con)
          Release connection - CAUTION: Release every connection after use to avoid abandoned connections.
abstract  void releaseJdbcConnection(JdbcConnectionDescriptor jcd, java.sql.Connection con)
          Releases a Connection after use.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionFactoryAbstractImpl

public ConnectionFactoryAbstractImpl()
Method Detail

checkOutJdbcConnection

public abstract java.sql.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,
                                           java.sql.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,
                              java.sql.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 java.sql.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

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


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30