Class NativeJdbcExtractorAdapter
- java.lang.Object
- org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter
- All Implemented Interfaces:
NativeJdbcExtractor
- Direct Known Subclasses:
C3P0NativeJdbcExtractor,CommonsDbcpNativeJdbcExtractor,JBossNativeJdbcExtractor,Jdbc4NativeJdbcExtractor,SimpleNativeJdbcExtractor,WebLogicNativeJdbcExtractor,WebSphereNativeJdbcExtractor
public abstract class NativeJdbcExtractorAdapter extends Object implements NativeJdbcExtractor
Abstract adapter class for theNativeJdbcExtractorinterface, for simplified implementation of basic extractors. Basically returns the passed-in JDBC objects on all methods.getNativeConnectionchecks for a ConnectionProxy chain, for example from a TransactionAwareDataSourceProxy, before delegating todoGetNativeConnectionfor actual unwrapping. You can override either of the two for a specific connection pool, but the latter is recommended to participate in ConnectionProxy unwrapping.getNativeConnectionalso applies a fallback if the first native extraction process failed, that is, returned the same Connection as passed in. It assumes that some additional proxying is going in this case: Hence, it retrieves the underlying native Connection from the DatabaseMetaData viaconHandle.getMetaData().getConnection()and retries the native extraction process based on that Connection handle. This works, for example, for the Connection proxies exposed by Hibernate 3.1'sSession.connection().The
getNativeConnectionFromStatementmethod is implemented to simply delegate togetNativeConnectionwith the Statement's Connection. This is what most extractor implementations will stick to, unless there's a more efficient version for a specific pool.- Since:
- 1.1
- Author:
- Juergen Hoeller
- See Also:
getNativeConnection(java.sql.Connection),getNativeConnectionFromStatement(java.sql.Statement),ConnectionProxy
Constructor Summary
Constructors Constructor Description NativeJdbcExtractorAdapter()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ConnectiondoGetNativeConnection(Connection con)Not able to unwrap: return passed-in Connection.CallableStatementgetNativeCallableStatement(CallableStatement cs)Not able to unwrap: return passed-in CallableStatement.ConnectiongetNativeConnection(Connection con)Check for a ConnectionProxy chain, then delegate to doGetNativeConnection.ConnectiongetNativeConnectionFromStatement(Statement stmt)Retrieve the Connection via the Statement's Connection.PreparedStatementgetNativePreparedStatement(PreparedStatement ps)Not able to unwrap: return passed-in PreparedStatement.ResultSetgetNativeResultSet(ResultSet rs)Not able to unwrap: return passed-in ResultSet.StatementgetNativeStatement(Statement stmt)Not able to unwrap: return passed-in Statement.booleanisNativeConnectionNecessaryForNativeCallableStatements()Returnfalseby default.booleanisNativeConnectionNecessaryForNativePreparedStatements()Returnfalseby default.booleanisNativeConnectionNecessaryForNativeStatements()Returnfalseby default.
Constructor Detail
NativeJdbcExtractorAdapter
public NativeJdbcExtractorAdapter()
Method Detail
isNativeConnectionNecessaryForNativeStatements
public boolean isNativeConnectionNecessaryForNativeStatements()
Returnfalseby default.- Specified by:
isNativeConnectionNecessaryForNativeStatementsin interfaceNativeJdbcExtractor
isNativeConnectionNecessaryForNativePreparedStatements
public boolean isNativeConnectionNecessaryForNativePreparedStatements()
Returnfalseby default.- Specified by:
isNativeConnectionNecessaryForNativePreparedStatementsin interfaceNativeJdbcExtractor
isNativeConnectionNecessaryForNativeCallableStatements
public boolean isNativeConnectionNecessaryForNativeCallableStatements()
Returnfalseby default.- Specified by:
isNativeConnectionNecessaryForNativeCallableStatementsin interfaceNativeJdbcExtractor
getNativeConnection
public Connection getNativeConnection(Connection con) throws SQLException
Check for a ConnectionProxy chain, then delegate to doGetNativeConnection.ConnectionProxy is used by Spring's TransactionAwareDataSourceProxy and LazyConnectionDataSourceProxy. The target connection behind it is typically one from a local connection pool, to be unwrapped by the doGetNativeConnection implementation of a concrete subclass.
- Specified by:
getNativeConnectionin interfaceNativeJdbcExtractor- Parameters:
con- the Connection handle, potentially wrapped by a connection pool- Returns:
- the underlying native JDBC Connection, if possible; else, the original Connection
- Throws:
SQLException- if thrown by JDBC methods- See Also:
doGetNativeConnection(java.sql.Connection),ConnectionProxy,DataSourceUtils.getTargetConnection(java.sql.Connection),TransactionAwareDataSourceProxy,LazyConnectionDataSourceProxy
doGetNativeConnection
protected Connection doGetNativeConnection(Connection con) throws SQLException
Not able to unwrap: return passed-in Connection.- Throws:
SQLException
getNativeConnectionFromStatement
public Connection getNativeConnectionFromStatement(Statement stmt) throws SQLException
Retrieve the Connection via the Statement's Connection.- Specified by:
getNativeConnectionFromStatementin interfaceNativeJdbcExtractor- Parameters:
stmt- the Statement handle, potentially wrapped by a connection pool- Returns:
- the underlying native JDBC Connection, if possible; else, the original Connection
- Throws:
SQLException- if thrown by JDBC methods- See Also:
getNativeConnection(java.sql.Connection),Statement.getConnection()
getNativeStatement
public Statement getNativeStatement(Statement stmt) throws SQLException
Not able to unwrap: return passed-in Statement.- Specified by:
getNativeStatementin interfaceNativeJdbcExtractor- Parameters:
stmt- the Statement handle, potentially wrapped by a connection pool- Returns:
- the underlying native JDBC Statement, if possible; else, the original Statement
- Throws:
SQLException- if thrown by JDBC methods
getNativePreparedStatement
public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException
Not able to unwrap: return passed-in PreparedStatement.- Specified by:
getNativePreparedStatementin interfaceNativeJdbcExtractor- Parameters:
ps- the PreparedStatement handle, potentially wrapped by a connection pool- Returns:
- the underlying native JDBC PreparedStatement, if possible; else, the original PreparedStatement
- Throws:
SQLException- if thrown by JDBC methods
getNativeCallableStatement
public CallableStatement getNativeCallableStatement(CallableStatement cs) throws SQLException
Not able to unwrap: return passed-in CallableStatement.- Specified by:
getNativeCallableStatementin interfaceNativeJdbcExtractor- Parameters:
cs- the CallableStatement handle, potentially wrapped by a connection pool- Returns:
- the underlying native JDBC CallableStatement, if possible; else, the original CallableStatement
- Throws:
SQLException- if thrown by JDBC methods
getNativeResultSet
public ResultSet getNativeResultSet(ResultSet rs) throws SQLException
Not able to unwrap: return passed-in ResultSet.- Specified by:
getNativeResultSetin interfaceNativeJdbcExtractor- Parameters:
rs- the ResultSet handle, potentially wrapped by a connection pool- Returns:
- the underlying native JDBC ResultSet, if possible; else, the original ResultSet
- Throws:
SQLException- if thrown by JDBC methods