org.springframework.jdbc.support.nativejdbc
Class CommonsDbcpNativeJdbcExtractor

java.lang.Object
  extended byorg.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor
All Implemented Interfaces:
NativeJdbcExtractor

public class CommonsDbcpNativeJdbcExtractor
extends java.lang.Object
implements NativeJdbcExtractor

Implementation of the NativeJdbcExtractor interface for the Jakarta Commons DBCP connection pool. Returns the underlying native Connection, Statement, ResultSet etc to application code instead of DBCP's wrapper implementations. The returned JDBC classes can then safely be cast, e.g. to OracleResultSet.

This NativeJdbcExtractor can be set just to allow working with a Commons DBCP DataSource: If a given object is not a Commons DBCP wrapper, it will be returned as-is.

Note: Before Commons DBCP 1.1, DelegatingCallableStatement and DelegatingResultSet have not offered any means to access underlying delegates. Therefore, getNativeCallableStatement and getNativeResultSet will just work with DBCP 1.1. But getNativeResultSet will not be invoked by JdbcTemplate for a wrapped ResultSet anyway, because getNativeStatement/getNativePreparedStatement will already have returned the underlying delegate before.

Since:
25.08.2003
Author:
Juergen Hoeller
See Also:
JdbcTemplate.setNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor)

Constructor Summary
CommonsDbcpNativeJdbcExtractor()
           
 
Method Summary
 java.sql.CallableStatement getNativeCallableStatement(java.sql.CallableStatement cs)
          Retrieve the underlying native JDBC CallableStatement for the given statement.
 java.sql.Connection getNativeConnection(java.sql.Connection con)
          Retrieve the underlying native JDBC Connection for the given Connection.
 java.sql.Connection getNativeConnectionFromStatement(java.sql.Statement stmt)
          Retrieve the underlying native JDBC Connection for the given Statement.
 java.sql.PreparedStatement getNativePreparedStatement(java.sql.PreparedStatement ps)
          Retrieve the underlying native JDBC PreparedStatement for the given statement.
 java.sql.ResultSet getNativeResultSet(java.sql.ResultSet rs)
          Retrieve the underlying native JDBC ResultSet for the given statement.
 java.sql.Statement getNativeStatement(java.sql.Statement stmt)
          Retrieve the underlying native JDBC Statement for the given Statement.
 boolean isNativeConnectionNecessaryForNativeCallableStatements()
          Return whether it is necessary to work on the native Connection to receive native CallableStatements.
 boolean isNativeConnectionNecessaryForNativePreparedStatements()
          Return whether it is necessary to work on the native Connection to receive native PreparedStatements.
 boolean isNativeConnectionNecessaryForNativeStatements()
          Return whether it is necessary to work on the native Connection to receive native Statements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommonsDbcpNativeJdbcExtractor

public CommonsDbcpNativeJdbcExtractor()
Method Detail

isNativeConnectionNecessaryForNativeStatements

public boolean isNativeConnectionNecessaryForNativeStatements()
Description copied from interface: NativeJdbcExtractor
Return whether it is necessary to work on the native Connection to receive native Statements.

This should be true if the connection pool does not allow to extract the native JDBC objects from its Statement wrapper but supports a way to retrieve the native JDBC Connection. This way, applications can still receive native Statements and ResultSet via working on the native JDBC Connection.

Specified by:
isNativeConnectionNecessaryForNativeStatements in interface NativeJdbcExtractor

isNativeConnectionNecessaryForNativePreparedStatements

public boolean isNativeConnectionNecessaryForNativePreparedStatements()
Description copied from interface: NativeJdbcExtractor
Return whether it is necessary to work on the native Connection to receive native PreparedStatements.

This should be true if the connection pool does not allow to extract the native JDBC objects from its PreparedStatement wrappers but supports a way to retrieve the native JDBC Connection. This way, applications can still receive native Statements and ResultSet via working on the native JDBC Connection.

Specified by:
isNativeConnectionNecessaryForNativePreparedStatements in interface NativeJdbcExtractor

isNativeConnectionNecessaryForNativeCallableStatements

public boolean isNativeConnectionNecessaryForNativeCallableStatements()
Description copied from interface: NativeJdbcExtractor
Return whether it is necessary to work on the native Connection to receive native CallableStatements.

This should be true if the connection pool does not allow to extract the native JDBC objects from its CallableStatement wrappers but supports a way to retrieve the native JDBC Connection. This way, applications can still receive native Statements and ResultSet via working on the native JDBC Connection.

Specified by:
isNativeConnectionNecessaryForNativeCallableStatements in interface NativeJdbcExtractor

getNativeConnection

public java.sql.Connection getNativeConnection(java.sql.Connection con)
Description copied from interface: NativeJdbcExtractor
Retrieve the underlying native JDBC Connection for the given Connection. Supposed to return the given Connection if not capable of unwrapping.

Specified by:
getNativeConnection in interface NativeJdbcExtractor
Parameters:
con - the Connection handle, potentially wrapped by a connection pool
Returns:
the underlying native JDBC Connection, if possible; else, the original Connection

getNativeConnectionFromStatement

public java.sql.Connection getNativeConnectionFromStatement(java.sql.Statement stmt)
                                                     throws java.sql.SQLException
Description copied from interface: NativeJdbcExtractor
Retrieve the underlying native JDBC Connection for the given Statement. Supposed to return the Statement.getConnection if not capable of unwrapping.

Having this extra method allows for more efficient unwrapping if data access code already has a Statement. Statement.getConnection() often returns the native JDBC Connection even if the Statement itself is wrapped by a pool.

Specified by:
getNativeConnectionFromStatement in interface NativeJdbcExtractor
Parameters:
stmt - the Statement handle, potentially wrapped by a connection pool
Returns:
the underlying native JDBC Connection, if possible; else, the original Connection
Throws:
java.sql.SQLException - if thrown by JDBC methods

getNativeStatement

public java.sql.Statement getNativeStatement(java.sql.Statement stmt)
Description copied from interface: NativeJdbcExtractor
Retrieve the underlying native JDBC Statement for the given Statement. Supposed to return the given Statement if not capable of unwrapping.

Specified by:
getNativeStatement in interface NativeJdbcExtractor
Parameters:
stmt - the Statement handle, potentially wrapped by a connection pool
Returns:
the underlying native JDBC Statement, if possible; else, the original Connection

getNativePreparedStatement

public java.sql.PreparedStatement getNativePreparedStatement(java.sql.PreparedStatement ps)
Description copied from interface: NativeJdbcExtractor
Retrieve the underlying native JDBC PreparedStatement for the given statement. Supposed to return the given PreparedStatement if not capable of unwrapping.

Specified by:
getNativePreparedStatement in interface NativeJdbcExtractor
Parameters:
ps - the PreparedStatement handle, potentially wrapped by a connection pool
Returns:
the underlying native JDBC PreparedStatement, if possible; else, the original Connection

getNativeCallableStatement

public java.sql.CallableStatement getNativeCallableStatement(java.sql.CallableStatement cs)
Description copied from interface: NativeJdbcExtractor
Retrieve the underlying native JDBC CallableStatement for the given statement. Supposed to return the given CallableStatement if not capable of unwrapping.

Specified by:
getNativeCallableStatement in interface NativeJdbcExtractor
Parameters:
cs - the CallableStatement handle, potentially wrapped by a connection pool
Returns:
the underlying native JDBC CallableStatement, if possible; else, the original Connection

getNativeResultSet

public java.sql.ResultSet getNativeResultSet(java.sql.ResultSet rs)
                                      throws java.sql.SQLException
Description copied from interface: NativeJdbcExtractor
Retrieve the underlying native JDBC ResultSet for the given statement. Supposed to return the given ResultSet if not capable of unwrapping.

Specified by:
getNativeResultSet in interface NativeJdbcExtractor
Parameters:
rs - the ResultSet handle, potentially wrapped by a connection pool
Returns:
the underlying native JDBC ResultSet, if possible; else, the original Connection
Throws:
java.sql.SQLException - if thrown by JDBC methods


Copyright (C) 2003-2004 The Spring Framework Project.