|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.support.lob.AbstractLobHandler org.springframework.jdbc.support.lob.OracleLobHandler
public class OracleLobHandler
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 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.
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 J2EE environment), you need to set
an appropriate NativeJdbcExtractor to allow for automatical 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) 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.
setNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor)
,
oracle.sql.BLOB
,
oracle.sql.CLOB
Nested Class Summary | |
---|---|
protected static interface |
OracleLobHandler.LobCallback
Internal callback interface for use with createLob. |
protected class |
OracleLobHandler.OracleLobCreator
LobCreator implementation for Oracle databases. |
Field Summary | |
---|---|
protected org.apache.commons.logging.Log |
logger
|
Constructor Summary | |
---|---|
OracleLobHandler()
|
Method Summary | |
---|---|
InputStream |
getBlobAsBinaryStream(ResultSet rs,
int columnIndex)
Retrieve the given column as binary stream from the given ResultSet. |
byte[] |
getBlobAsBytes(ResultSet rs,
int columnIndex)
Retrieve the given column as bytes from the given ResultSet. |
InputStream |
getClobAsAsciiStream(ResultSet rs,
int columnIndex)
Retrieve the given column as ASCII stream from the given ResultSet. |
Reader |
getClobAsCharacterStream(ResultSet rs,
int columnIndex)
Retrieve the given column as character stream from the given ResultSet. |
String |
getClobAsString(ResultSet rs,
int columnIndex)
Retrieve the given column as String from the given ResultSet. |
LobCreator |
getLobCreator()
Create a new LobCreator instance, i.e. a session for creating BLOBs and CLOBs. |
protected void |
initOracleDriverClasses(Connection con)
Retrieve the oracle.sql.BLOB and oracle.sql.CLOB
classes via reflection, and initialize the values for the
DURATION_SESSION and MODE_READWRITE constants defined there. |
void |
setCache(boolean cache)
Set whether to cache the temporary LOB in the buffer cache. |
void |
setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor)
Set an appropriate NativeJdbcExtractor to be able to retrieve the underlying native oracle.jdbc.OracleConnection . |
Methods inherited from class org.springframework.jdbc.support.lob.AbstractLobHandler |
---|
getBlobAsBinaryStream, getBlobAsBytes, getClobAsAsciiStream, getClobAsCharacterStream, getClobAsString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final org.apache.commons.logging.Log logger
Constructor Detail |
---|
public OracleLobHandler()
Method Detail |
---|
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's javadoc for details.
NativeJdbcExtractor.getNativeConnectionFromStatement(java.sql.Statement)
,
SimpleNativeJdbcExtractor
,
oracle.jdbc.OracleConnection
public void setCache(boolean cache)
oracle.sql.BLOB#createTemporary
,
oracle.sql.CLOB#createTemporary
protected void initOracleDriverClasses(Connection con)
oracle.sql.BLOB
and oracle.sql.CLOB
classes via reflection, and initialize the values for the
DURATION_SESSION and MODE_READWRITE constants defined there.
con
- the Oracle Connection, for using the exact same class loader
that the Oracle driver was loaded withoracle.sql.BLOB#DURATION_SESSION
,
oracle.sql.BLOB#MODE_READWRITE
,
oracle.sql.CLOB#DURATION_SESSION
,
oracle.sql.CLOB#MODE_READWRITE
public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws 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 use
null
in case of SQL NULL
SQLException
- if thrown by JDBC methodsResultSet.getBytes(int)
public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws 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 use
null
in case of SQL NULL
SQLException
- if thrown by JDBC methodsResultSet.getBinaryStream(int)
public String getClobAsString(ResultSet rs, int columnIndex) throws 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 use
null
in case of SQL NULL
SQLException
- if thrown by JDBC methodsResultSet.getString(int)
public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws 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 use
null
in case of SQL NULL
SQLException
- if thrown by JDBC methodsResultSet.getAsciiStream(int)
public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws 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 use
SQLException
- if thrown by JDBC methodsResultSet.getCharacterStream(int)
public LobCreator getLobCreator()
LobHandler
LobCreator.close()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |