public class SimpleNativeJdbcExtractor extends NativeJdbcExtractorAdapter
NativeJdbcExtractor
interface.
Assumes a pool that wraps Connection handles but not DatabaseMetaData:
In this case, the underlying native Connection can be retrieved by simply
calling conHandle.getMetaData().getConnection()
.
All other JDBC objects will be returned as passed in.
This extractor should work with any pool that does not wrap DatabaseMetaData,
and will also work with any plain JDBC driver. Note that a pool can still wrap
Statements, PreparedStatements, etc: The only requirement of this extractor is
that java.sql.DatabaseMetaData
does not get wrapped, returning the
native Connection of the JDBC driver on metaData.getConnection()
.
Customize this extractor by setting the "nativeConnectionNecessaryForXxx" flags accordingly: If Statements, PreparedStatements, and/or CallableStatements are wrapped by your pool, set the corresponding "nativeConnectionNecessaryForXxx" flags to "true". If none of the statement types is wrapped - or you solely need Connection unwrapping in the first place -, the defaults are fine.
SimpleNativeJdbcExtractor is a common choice for use with OracleLobHandler, which
just needs Connection unwrapping via the NativeJdbcExtractorAdapter.getNativeConnectionFromStatement(java.sql.Statement)
method. This usage will work with almost any connection pool.
For full usage with JdbcTemplate, i.e. to also provide Statement unwrapping:
setNativeConnectionNecessaryForNativeStatements(boolean)
,
setNativeConnectionNecessaryForNativePreparedStatements(boolean)
,
setNativeConnectionNecessaryForNativeCallableStatements(boolean)
,
Jdbc4NativeJdbcExtractor
,
JdbcTemplate.setNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor)
,
OracleLobHandler.setNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor)
Constructor and Description |
---|
SimpleNativeJdbcExtractor() |
Modifier and Type | Method and Description |
---|---|
boolean |
isNativeConnectionNecessaryForNativeCallableStatements()
Return
false by default. |
boolean |
isNativeConnectionNecessaryForNativePreparedStatements()
Return
false by default. |
boolean |
isNativeConnectionNecessaryForNativeStatements()
Return
false by default. |
void |
setNativeConnectionNecessaryForNativeCallableStatements(boolean nativeConnectionNecessary)
Set whether it is necessary to work on the native Connection to
receive native CallableStatements.
|
void |
setNativeConnectionNecessaryForNativePreparedStatements(boolean nativeConnectionNecessary)
Set whether it is necessary to work on the native Connection to
receive native PreparedStatements.
|
void |
setNativeConnectionNecessaryForNativeStatements(boolean nativeConnectionNecessaryForNativeStatements)
Set whether it is necessary to work on the native Connection to
receive native Statements.
|
doGetNativeConnection, getNativeCallableStatement, getNativeConnection, getNativeConnectionFromStatement, getNativePreparedStatement, getNativeResultSet, getNativeStatement
public void setNativeConnectionNecessaryForNativeStatements(boolean nativeConnectionNecessaryForNativeStatements)
This makes sense if you need to work with native Statements from a pool that does not allow to extract the native JDBC objects from its wrappers but returns the native Connection on DatabaseMetaData.getConnection.
The standard SimpleNativeJdbcExtractor is unable to unwrap statements, so set this to true if your connection pool wraps Statements.
public boolean isNativeConnectionNecessaryForNativeStatements()
NativeJdbcExtractorAdapter
false
by default.isNativeConnectionNecessaryForNativeStatements
in interface NativeJdbcExtractor
isNativeConnectionNecessaryForNativeStatements
in class NativeJdbcExtractorAdapter
public void setNativeConnectionNecessaryForNativePreparedStatements(boolean nativeConnectionNecessary)
This makes sense if you need to work with native PreparedStatements from a pool that does not allow to extract the native JDBC objects from its wrappers but returns the native Connection on Statement.getConnection.
The standard SimpleNativeJdbcExtractor is unable to unwrap statements, so set this to true if your connection pool wraps PreparedStatements.
public boolean isNativeConnectionNecessaryForNativePreparedStatements()
NativeJdbcExtractorAdapter
false
by default.isNativeConnectionNecessaryForNativePreparedStatements
in interface NativeJdbcExtractor
isNativeConnectionNecessaryForNativePreparedStatements
in class NativeJdbcExtractorAdapter
public void setNativeConnectionNecessaryForNativeCallableStatements(boolean nativeConnectionNecessary)
This makes sense if you need to work with native CallableStatements from a pool that does not allow to extract the native JDBC objects from its wrappers but returns the native Connection on Statement.getConnection.
The standard SimpleNativeJdbcExtractor is unable to unwrap statements, so set this to true if your connection pool wraps CallableStatements.
public boolean isNativeConnectionNecessaryForNativeCallableStatements()
NativeJdbcExtractorAdapter
false
by default.isNativeConnectionNecessaryForNativeCallableStatements
in interface NativeJdbcExtractor
isNativeConnectionNecessaryForNativeCallableStatements
in class NativeJdbcExtractorAdapter