org.springframework.jdbc.support.nativejdbc
Interface NativeJdbcExtractor

All Known Implementing Classes:
CommonsDbcpNativeJdbcExtractor, JBossNativeJdbcExtractor, SimpleNativeJdbcExtractor, XAPoolNativeJdbcExtractor

public interface NativeJdbcExtractor

Interface for extracting native JDBC objects from wrapped objects coming from connection pools. This is necessary to be able to case to native implementations like OracleConnection or OracleResultSet in application code, for example to create Blobs or access other vendor-specific features.

Note: Setting a custom NativeJdbcExtractor is just necessary if you want to cast to database-specific implementations, like OracleConnection/OracleResultSet. Else, any wrapped JDBC object will be fine too.

Note: To be able to support any pool's strategy of native ResultSet wrapping, it is advisable to get both the native Statement and the native ResultSet via this extractor. Some pools just allow to unwrap the Statement, some just to unwrap the ResultSet - the above strategy will cover both. It is typically not necessary to unwrap the Connection to retrieve the native ResultSet.

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

Method Summary
 CallableStatementgetNativeCallableStatement(CallableStatement cs)
          Retrieve the underlying native JDBC CallableStatement for the given statement.
 ConnectiongetNativeConnection(Connection con)
          Retrieve the underlying native JDBC Connection for the given Connection.
 ConnectiongetNativeConnectionFromStatement(Statement stmt)
          Retrieve the underlying native JDBC Connection for the given Statement.
 PreparedStatementgetNativePreparedStatement(PreparedStatement ps)
          Retrieve the underlying native JDBC PreparedStatement for the given statement.
 ResultSetgetNativeResultSet(ResultSet rs)
          Retrieve the underlying native JDBC ResultSet for the given statement.
 StatementgetNativeStatement(Statement stmt)
          Retrieve the underlying native JDBC Statement for the given Statement.
 booleanisNativeConnectionNecessaryForNativeCallableStatements()
          Return whether it is necessary to work on the native Connection to receive native CallableStatements.
 booleanisNativeConnectionNecessaryForNativePreparedStatements()
          Return whether it is necessary to work on the native Connection to receive native PreparedStatements.
 booleanisNativeConnectionNecessaryForNativeStatements()
          Return whether it is necessary to work on the native Connection to receive native Statements.

Method Detail

getNativeCallableStatement

public CallableStatement getNativeCallableStatement(CallableStatement cs)
throws java.sql.SQLException
Retrieve the underlying native JDBC CallableStatement for the given statement. Supposed to return the given CallableStatement if not capable of unwrapping.
Parameters:
cs - the CallableStatement handle, potentially wrapped by a connection pool
Returns: the underlying native JDBC CallableStatement, if possible
Throws:
SQLException - if thrown by JDBC methods

getNativeConnection

public Connection getNativeConnection(Connection con)
throws java.sql.SQLException
Retrieve the underlying native JDBC Connection for the given Connection. Supposed to return the given Connection if not capable of unwrapping.
Parameters:
con - the Connection handle, potentially wrapped by a connection pool
Returns: the underlying native JDBC Connection, if possible
Throws:
SQLException - if thrown by JDBC methods

getNativeConnectionFromStatement

public Connection getNativeConnectionFromStatement(Statement stmt)
throws java.sql.SQLException
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.

Parameters:
stmt - the Statement handle, potentially wrapped by a connection pool
Returns: the underlying native JDBC Connection, if possible
Throws:
SQLException - if thrown by JDBC methods

getNativePreparedStatement

public PreparedStatement getNativePreparedStatement(PreparedStatement ps)
throws java.sql.SQLException
Retrieve the underlying native JDBC PreparedStatement for the given statement. Supposed to return the given PreparedStatement if not capable of unwrapping.
Parameters:
ps - the PreparedStatement handle, potentially wrapped by a connection pool
Returns: the underlying native JDBC PreparedStatement, if possible
Throws:
SQLException - if thrown by JDBC methods

getNativeResultSet

public ResultSet getNativeResultSet(ResultSet rs)
throws java.sql.SQLException
Retrieve the underlying native JDBC ResultSet for the given statement. Supposed to return the given ResultSet if not capable of unwrapping.
Parameters:
rs - the ResultSet handle, potentially wrapped by a connection pool
Returns: the underlying native JDBC ResultSet, if possible
Throws:
SQLException - if thrown by JDBC methods

getNativeStatement

public Statement getNativeStatement(Statement stmt)
throws java.sql.SQLException
Retrieve the underlying native JDBC Statement for the given Statement. Supposed to return the given Statement if not capable of unwrapping.
Parameters:
stmt - the Statement handle, potentially wrapped by a connection pool
Returns: the underlying native JDBC Statement, if possible
Throws:
SQLException - if thrown by JDBC methods

isNativeConnectionNecessaryForNativeCallableStatements

public boolean isNativeConnectionNecessaryForNativeCallableStatements()
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.


isNativeConnectionNecessaryForNativePreparedStatements

public boolean isNativeConnectionNecessaryForNativePreparedStatements()
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.


isNativeConnectionNecessaryForNativeStatements

public boolean isNativeConnectionNecessaryForNativeStatements()
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.