DefaultLobHandler
for the Oracle 10g driver and
higher. Consider using the 10g/11g driver even against an Oracle 9i database!
DefaultLobHandler.setCreateTemporaryLob(boolean)
is the direct equivalent of this
OracleLobHandler's implementation strategy, just using standard JDBC 4.0 API.
That said, in most cases, regular DefaultLobHandler setup will work fine as well.@Deprecated public class OracleLobHandler extends AbstractLobHandler
LobHandler
implementation for Oracle databases. Uses proprietary API
to create oracle.sql.BLOB
and oracle.sql.CLOB
instances, as necessary when working with Oracle's JDBC driver.
Note that this LobHandler requires Oracle JDBC driver 9i or higher!
While most databases are able to work with DefaultLobHandler
,
Oracle 9i (or more specifically, the Oracle 9i JDBC driver) just accepts
Blob/Clob instances created via its own proprietary BLOB/CLOB API,
and additionally doesn't accept large streams for PreparedStatement's
corresponding setter methods. Therefore, you need to use a strategy like
this LobHandler implementation, or upgrade to the Oracle 10g/11g driver
(which still supports access to Oracle 9i databases).
NOTE: As of Oracle 10.2, DefaultLobHandler
should work equally
well out of the box. On Oracle 11g, JDBC 4.0 based options such as
DefaultLobHandler.setStreamAsLob(boolean)
and DefaultLobHandler.setCreateTemporaryLob(boolean)
are available as well, rendering this proprietary OracleLobHandler obsolete.
Also, consider upgrading to a new driver even when accessing an older database.
See the LobHandler
interface javadoc for a summary of recommendations.
Needs to work on a native JDBC Connection, to be able to cast it to
oracle.jdbc.OracleConnection
. If you pass in Connections from a
connection pool (the usual case in a Java EE environment), you need to set an
appropriate NativeJdbcExtractor
to allow for automatic retrieval of the underlying native JDBC Connection.
LobHandler and NativeJdbcExtractor are separate concerns, therefore they
are represented by separate strategy interfaces.
Coded via reflection to avoid dependencies on Oracle classes. Even reads in Oracle constants via reflection because of different Oracle drivers (classes12, ojdbc14, ojdbc5, ojdbc6) having different constant values! As this LobHandler initializes Oracle classes on instantiation, do not define this as eager-initializing singleton if you do not want to depend on the Oracle JAR being in the class path: use "lazy-init=true" to avoid this issue.
DefaultLobHandler
,
setNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor)
Modifier and Type | Class and Description |
---|---|
protected static interface |
OracleLobHandler.LobCallback
Deprecated.
Internal callback interface for use with createLob.
|
protected class |
OracleLobHandler.OracleLobCreator
Deprecated.
LobCreator implementation for Oracle databases.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
BLOB_CLASS_NAME
Deprecated.
|
private java.lang.Class |
blobClass
Deprecated.
|
private java.lang.Boolean |
cache
Deprecated.
|
private static java.lang.String |
CLOB_CLASS_NAME
Deprecated.
|
private java.lang.Class |
clobClass
Deprecated.
|
private static java.lang.String |
DURATION_SESSION_FIELD_NAME
Deprecated.
|
private java.util.Map<java.lang.Class,java.lang.Integer> |
durationSessionConstants
Deprecated.
|
protected Log |
logger
Deprecated.
|
private static java.lang.String |
MODE_READONLY_FIELD_NAME
Deprecated.
|
private static java.lang.String |
MODE_READWRITE_FIELD_NAME
Deprecated.
|
private java.util.Map<java.lang.Class,java.lang.Integer> |
modeReadOnlyConstants
Deprecated.
|
private java.util.Map<java.lang.Class,java.lang.Integer> |
modeReadWriteConstants
Deprecated.
|
private NativeJdbcExtractor |
nativeJdbcExtractor
Deprecated.
|
private java.lang.Boolean |
releaseResourcesAfterRead
Deprecated.
|
Constructor and Description |
---|
OracleLobHandler()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
java.io.InputStream |
getBlobAsBinaryStream(java.sql.ResultSet rs,
int columnIndex)
Deprecated.
Retrieve the given column as binary stream from the given ResultSet.
|
byte[] |
getBlobAsBytes(java.sql.ResultSet rs,
int columnIndex)
Deprecated.
Retrieve the given column as bytes from the given ResultSet.
|
java.io.InputStream |
getClobAsAsciiStream(java.sql.ResultSet rs,
int columnIndex)
Deprecated.
Retrieve the given column as ASCII stream from the given ResultSet.
|
java.io.Reader |
getClobAsCharacterStream(java.sql.ResultSet rs,
int columnIndex)
Deprecated.
Retrieve the given column as character stream from the given ResultSet.
|
java.lang.String |
getClobAsString(java.sql.ResultSet rs,
int columnIndex)
Deprecated.
Retrieve the given column as String from the given ResultSet.
|
LobCreator |
getLobCreator()
Deprecated.
Create a new
LobCreator instance, i.e. |
protected void |
initializeResourcesBeforeRead(java.sql.Connection con,
java.lang.Object lob)
Deprecated.
Initialize any LOB resources before a read is done.
|
protected void |
initOracleDriverClasses(java.sql.Connection con)
Deprecated.
Retrieve the
oracle.sql.BLOB and oracle.sql.CLOB
classes via reflection, and initialize the values for the
DURATION_SESSION, MODE_READWRITE and MODE_READONLY constants defined there. |
protected void |
releaseResourcesAfterRead(java.sql.Connection con,
java.lang.Object lob)
Deprecated.
Release any LOB resources after read is complete.
|
void |
setCache(boolean cache)
Deprecated.
Set whether to cache the temporary LOB in the buffer cache.
|
void |
setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor)
Deprecated.
Set an appropriate NativeJdbcExtractor to be able to retrieve the underlying
native
oracle.jdbc.OracleConnection . |
void |
setReleaseResourcesAfterRead(boolean releaseResources)
Deprecated.
Set whether to aggressively release any resources used by the LOB.
|
getBlobAsBinaryStream, getBlobAsBytes, getClobAsAsciiStream, getClobAsCharacterStream, getClobAsString
private static final java.lang.String BLOB_CLASS_NAME
private static final java.lang.String CLOB_CLASS_NAME
private static final java.lang.String DURATION_SESSION_FIELD_NAME
private static final java.lang.String MODE_READWRITE_FIELD_NAME
private static final java.lang.String MODE_READONLY_FIELD_NAME
protected final Log logger
private NativeJdbcExtractor nativeJdbcExtractor
private java.lang.Boolean cache
private java.lang.Boolean releaseResourcesAfterRead
private java.lang.Class blobClass
private java.lang.Class clobClass
private final java.util.Map<java.lang.Class,java.lang.Integer> durationSessionConstants
private final java.util.Map<java.lang.Class,java.lang.Integer> modeReadWriteConstants
private final java.util.Map<java.lang.Class,java.lang.Integer> modeReadOnlyConstants
public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor)
oracle.jdbc.OracleConnection
. This is necessary for
DataSource-based connection pools, as those need to return wrapped JDBC
Connection handles that cannot be cast to a native Connection implementation.
Effectively, this LobHandler just invokes a single NativeJdbcExtractor
method, namely getNativeConnectionFromStatement
with a
PreparedStatement argument (falling back to a
PreparedStatement.getConnection()
call if no extractor is set).
A common choice is SimpleNativeJdbcExtractor
, whose Connection unwrapping
(which is what OracleLobHandler needs) will work with many connection pools.
See SimpleNativeJdbcExtractor
and
oracle.jdbc.OracleConnection javadoc for details.
public void setCache(boolean cache)
Default is true
.
See Also:
public void setReleaseResourcesAfterRead(boolean releaseResources)
true
then you can only read the LOB values once. Any subsequent reads will fail since the resources
have been closed.
Setting this property to true
can be useful when your queries generates large
temporary LOBs that occupy space in the TEMPORARY tablespace or when you want to free up any
memory allocated by the driver for the LOB reading.
Default is false
.
See Also:
protected void initOracleDriverClasses(java.sql.Connection con)
oracle.sql.BLOB
and oracle.sql.CLOB
classes via reflection, and initialize the values for the
DURATION_SESSION, MODE_READWRITE and MODE_READONLY constants defined there.
See Also:
con
- the Oracle Connection, for using the exact same class loader
that the Oracle driver was loaded withpublic byte[] getBlobAsBytes(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
LobHandler
ResultSet.getBytes
or work with
ResultSet.getBlob
, depending on the database and driver.rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to usenull
in case of SQL NULLjava.sql.SQLException
- if thrown by JDBC methodsResultSet.getBytes(int)
public java.io.InputStream getBlobAsBinaryStream(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
LobHandler
ResultSet.getBinaryStream
or work with
ResultSet.getBlob
, depending on the database and driver.rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to usenull
in case of SQL NULLjava.sql.SQLException
- if thrown by JDBC methodsResultSet.getBinaryStream(int)
public java.lang.String getClobAsString(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
LobHandler
ResultSet.getString
or work with
ResultSet.getClob
, depending on the database and driver.rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to usenull
in case of SQL NULLjava.sql.SQLException
- if thrown by JDBC methodsResultSet.getString(int)
public java.io.InputStream getClobAsAsciiStream(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
LobHandler
ResultSet.getAsciiStream
or work with
ResultSet.getClob
, depending on the database and driver.rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to usenull
in case of SQL NULLjava.sql.SQLException
- if thrown by JDBC methodsResultSet.getAsciiStream(int)
public java.io.Reader getClobAsCharacterStream(java.sql.ResultSet rs, int columnIndex) throws java.sql.SQLException
LobHandler
ResultSet.getCharacterStream
or work with
ResultSet.getClob
, depending on the database and driver.rs
- the ResultSet to retrieve the content fromcolumnIndex
- the column index to usejava.sql.SQLException
- if thrown by JDBC methodsResultSet.getCharacterStream(int)
public LobCreator getLobCreator()
LobHandler
LobCreator
instance, i.e. a session for creating BLOBs
and CLOBs. Needs to be closed after the created LOBs are not needed anymore -
typically after statement execution or transaction completion.LobCreator.close()
protected void initializeResourcesBeforeRead(java.sql.Connection con, java.lang.Object lob)
This implementation calls BLOB.open(BLOB.MODE_READONLY)
or
CLOB.open(CLOB.MODE_READONLY)
on any non-temporary LOBs if
releaseResourcesAfterRead
property is set to true
.
This method can be overridden by sublcasses if different behavior is desired.
con
- the connection to be usde for initilizationlob
- the LOB to initializeprotected void releaseResourcesAfterRead(java.sql.Connection con, java.lang.Object lob)
If releaseResourcesAfterRead
property is set to true
then this implementation calls
BLOB.close()
or CLOB.close()
on any non-temporary LOBs that are open or
BLOB.freeTemporary()
or CLOB.freeTemporary()
on any temporary LOBs.
This method can be overridden by sublcasses if different behavior is desired.
con
- the connection to be usde for initilizationlob
- the LOB to initialize