org.springframework.jdbc.support.lob
Class OracleLobHandler


public class OracleLobHandler
implements LobHandler

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. Developed and tested on Oracle 9i.

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 it initializes the 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.

Author:
Juergen Hoeller
Since: 04.12.2003
See Also: setNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor), oracle.sql.BLOB, oracle.sql.CLOB

Constructor Summary
OracleLobHandler()
          This constructor retrieves the oracle.sql.BLOB and oracle.sql.CLOB classes via reflection, and initializes the values for the DURATION_SESSION and MODE_READWRITE constants defined there.

Method Summary
 InputStreamgetBlobAsBinaryStream(ResultSet rs, int columnIndex)
           
 byte[]getBlobAsBytes(ResultSet rs, int columnIndex)
           
 InputStreamgetClobAsAsciiStream(ResultSet rs, int columnIndex)
           
 ReadergetClobAsCharacterStream(ResultSet rs, int columnIndex)
           
 StringgetClobAsString(ResultSet rs, int columnIndex)
           
 LobCreatorgetLobCreator()
           
 voidsetCache(boolean cache)
          Set whether to cache the temporary LOB in the buffer cache.
 voidsetNativeJdbcExtractor(NativeJdbcExtractor extractor)
          Set an appropriate NativeJdbcExtractor to be able to retrieve the underlying native oracle.jdbc.OracleConnection.

Constructor Detail

OracleLobHandler

public OracleLobHandler()
throws java.lang.ClassNotFoundException,
java.lang.NoSuchFieldException,
java.lang.IllegalAccessException
This constructor retrieves the oracle.sql.BLOB and oracle.sql.CLOB classes via reflection, and initializes the values for the DURATION_SESSION and MODE_READWRITE constants defined there.
See Also:
oracle.sql.BLOB#DURATION_SESSION, oracle.sql.BLOB#MODE_READWRITE, oracle.sql.CLOB#DURATION_SESSION, oracle.sql.CLOB#MODE_READWRITE
Method Detail

getBlobAsBinaryStream

public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex)
throws java.sql.SQLException

getBlobAsBytes

public byte[] getBlobAsBytes(ResultSet rs, int columnIndex)
throws java.sql.SQLException

getClobAsAsciiStream

public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex)
throws java.sql.SQLException

getClobAsCharacterStream

public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex)
throws java.sql.SQLException

getClobAsString

public String getClobAsString(ResultSet rs, int columnIndex)
throws java.sql.SQLException

getLobCreator

public LobCreator getLobCreator()

setCache

public void setCache(boolean cache)
Set whether to cache the temporary LOB in the buffer cache. This value will be passed into BLOB/CLOB.createTemporary.
See Also:
oracle.sql.BLOB#createTemporary, oracle.sql.CLOB#createTemporary

setNativeJdbcExtractor

public void setNativeJdbcExtractor(NativeJdbcExtractor extractor)
Set an appropriate NativeJdbcExtractor to be able to retrieve the underlying native oracle.jdbc.OracleConnection. This is necessary for any DataSource-based connection pool, as such a pool needs to return wrapped Connection handles.
See Also:
oracle.jdbc.OracleConnection

Association Links

to Class java.lang.String

to Class java.lang.String

to Class java.lang.String

to Class java.lang.String

to Class java.lang.Class

to Class java.lang.Class

to Class java.util.Map

to Class java.util.Map

to Class org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor