LobHandler interface.
Invokes the direct accessor methods that java.sql.ResultSet
and java.sql.PreparedStatement offer.
By default, incoming streams are going to be passed to the appropriate
setBinary/Ascii/CharacterStream method on the JDBC driver's
PreparedStatement. If the specified content length is negative,
this handler will use the JDBC 4.0 variants of the set-stream methods
without a length parameter; otherwise, it will pass the specified length
on to the driver.
This LobHandler should work for any JDBC driver that is JDBC compliant
in terms of the spec's suggestions regarding simple BLOB and CLOB handling.
This does not apply to Oracle 9i's drivers at all; as of Oracle 10g,
it does work but may still come with LOB size limitations. Consider using
recent Oracle drivers even when working against an older database server.
See the LobHandler javadoc for the full set of recommendations.
Some JDBC drivers require values with a BLOB/CLOB target column to be
explicitly set through the JDBC setBlob / setClob API:
for example, PostgreSQL's driver. Switch the "wrapAsLob"
property to "true" when operating against such a driver.
On JDBC 4.0, this LobHandler also supports streaming the BLOB/CLOB content
via the setBlob / setClob variants that take a stream
argument directly. Consider switching the "streamAsLob"
property to "true" when operating against a fully compliant JDBC 4.0 driver.
Finally, this LobHandler also supports the creation of temporary BLOB/CLOB
objects. Consider switching the "createTemporaryLob"
property to "true" when "streamAsLob" happens to run into LOB size limitations.
See the LobHandler interface javadoc for a summary of recommendations.
java.sql.ResultSet#getBytes , java.sql.ResultSet#getBinaryStream , java.sql.ResultSet#getString , java.sql.ResultSet#getAsciiStream , java.sql.ResultSet#getCharacterStream , java.sql.PreparedStatement#setBytes , java.sql.PreparedStatement#setBinaryStream , java.sql.PreparedStatement#setString , java.sql.PreparedStatement#setAsciiStream , java.sql.PreparedStatement#setCharacterStream
| Modifier and Type | Class and Description |
|---|---|
| protected class | DefaultLobHandler.DefaultLobCreator
Default LobCreator implementation as an inner class. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| protected final Log | |
| private boolean | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public InputStream | getBlobAsBinaryStream(ResultSet
the ResultSet to retrieve the content from rs, int the column index to use columnIndex)Implements org. |
| public byte[] | getBlobAsBytes(ResultSet
the ResultSet to retrieve the content from rs, int the column index to use columnIndex)Implements org. |
| public InputStream | getClobAsAsciiStream(ResultSet
the ResultSet to retrieve the content from rs, int the column index to use columnIndex)Implements org. |
| public Reader | getClobAsCharacterStream(ResultSet
the ResultSet to retrieve the content from rs, int the column index to use columnIndex)Implements org. |
| public String | getClobAsString(ResultSet
the ResultSet to retrieve the content from rs, int the column index to use columnIndex)Implements org. |
| public LobCreator | getLobCreator()
Implements org. LobCreator instance, i.e. a session for creating BLOBs
and CLOBs.
|
| public void | setCreateTemporaryLob(boolean createTemporaryLob)
Specify whether to copy a byte array / String into a temporary JDBC
Blob / Clob object created through the JDBC 4.0 |
| public void | setStreamAsLob(boolean streamAsLob)
Specify whether to submit a binary stream / character stream to the JDBC
driver as explicit LOB content, using the JDBC 4.0 |
| public void | setWrapAsLob(boolean wrapAsLob)
Specify whether to submit a byte array / String to the JDBC driver
wrapped in a JDBC Blob / Clob object, using the JDBC |
| createTemporaryLob | back to summary |
|---|---|
| private boolean createTemporaryLob | |
| logger | back to summary |
|---|---|
| protected final Log logger | |
| streamAsLob | back to summary |
|---|---|
| private boolean streamAsLob | |
| wrapAsLob | back to summary |
|---|---|
| private boolean wrapAsLob | |
| DefaultLobHandler | back to summary |
|---|---|
| public DefaultLobHandler() | |
| getBlobAsBinaryStream | back to summary |
|---|---|
| public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException Implements org. Doc from org. Retrieve the given column as binary stream from the given ResultSet.
Might simply invoke
| |
| getBlobAsBytes | back to summary |
|---|---|
| public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException Implements org. Doc from org. Retrieve the given column as bytes from the given ResultSet.
Might simply invoke
| |
| getClobAsAsciiStream | back to summary |
|---|---|
| public InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException Implements org. Doc from org. Retrieve the given column as ASCII stream from the given ResultSet.
Might simply invoke
| |
| getClobAsCharacterStream | back to summary |
|---|---|
| public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException Implements org. Doc from org. Retrieve the given column as character stream from the given ResultSet.
Might simply invoke
| |
| getClobAsString | back to summary |
|---|---|
| public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException Implements org. Doc from org. Retrieve the given column as String from the given ResultSet.
Might simply invoke
| |
| getLobCreator | back to summary |
|---|---|
| public LobCreator getLobCreator() Implements org. Doc from org. Create a new
| |
| setCreateTemporaryLob | back to summary |
|---|---|
| public void setCreateTemporaryLob(boolean createTemporaryLob) Specify whether to copy a byte array / String into a temporary JDBC
Blob / Clob object created through the JDBC 4.0 Default is "false", using the common JDBC 2.0 This setting affects stream arguments as well as byte array / String
arguments, requiring JDBC 4.0 support. For supporting LOB content against
JDBC 3.0, check out the | |
| setStreamAsLob | back to summary |
|---|---|
| public void setStreamAsLob(boolean streamAsLob) Specify whether to submit a binary stream / character stream to the JDBC
driver as explicit LOB content, using the JDBC 4.0 Default is "false", using the common JDBC 2.0 This setting affects stream arguments as well as byte array / String
arguments, requiring JDBC 4.0 support. For supporting LOB content against
JDBC 3.0, check out the | |
| setWrapAsLob | back to summary |
|---|---|
| public void setWrapAsLob(boolean wrapAsLob) Specify whether to submit a byte array / String to the JDBC driver
wrapped in a JDBC Blob / Clob object, using the JDBC Default is "false", using the common JDBC 2.0 This setting affects byte array / String arguments as well as stream
arguments, unless | |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements org. |
| public void | setBlobAsBinaryStream(PreparedStatement
the PreparedStatement to the set the content on ps, int the parameter index to use paramIndex, InputStream the content as binary stream, or binaryStream, int contentLength)null for SQL NULLImplements org. |
| public void | setBlobAsBytes(PreparedStatement
the PreparedStatement to the set the content on ps, int the parameter index to use paramIndex, byte[] the content as byte array, or content)null for SQL NULLImplements org. |
| public void | setClobAsAsciiStream(PreparedStatement
the PreparedStatement to the set the content on ps, int the parameter index to use paramIndex, InputStream the content as ASCII stream, or asciiStream, int contentLength)null for SQL NULLImplements org. |
| public void | setClobAsCharacterStream(PreparedStatement
the PreparedStatement to the set the content on ps, int the parameter index to use paramIndex, Reader the content as character stream, or characterStream, int contentLength)null for SQL NULLImplements org. |
| public void | setClobAsString(PreparedStatement
the PreparedStatement to the set the content on ps, int the parameter index to use paramIndex, String the content as String, or content)null for SQL NULLImplements org. |
| DefaultLobCreator | back to summary |
|---|---|
| protected DefaultLobCreator() | |
| close | back to summary |
|---|---|
| public void close() Implements org. Doc from org. Close this LobCreator session and free its temporarily created BLOBs and CLOBs. Will not need to do anything if using PreparedStatement's standard methods, but might be necessary to free database resources if using proprietary means. Note Needs to be invoked after the involved PreparedStatements have been executed or the affected O/R mapping sessions have been flushed. Otherwise, the database resources for the temporary BLOBs might stay allocated.
| |
| setBlobAsBinaryStream | back to summary |
|---|---|
| public void setBlobAsBinaryStream(PreparedStatement ps, int paramIndex, InputStream binaryStream, int contentLength) throws SQLException Implements org. Doc from org. Set the given content as binary stream on the given statement, using the given
parameter index. Might simply invoke
| |
| setBlobAsBytes | back to summary |
|---|---|
| public void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte[] content) throws SQLException Implements org. Doc from org. Set the given content as bytes on the given statement, using the given
parameter index. Might simply invoke
| |
| setClobAsAsciiStream | back to summary |
|---|---|
| public void setClobAsAsciiStream(PreparedStatement ps, int paramIndex, InputStream asciiStream, int contentLength) throws SQLException Implements org. Doc from org. Set the given content as ASCII stream on the given statement, using the given
parameter index. Might simply invoke
| |
| setClobAsCharacterStream | back to summary |
|---|---|
| public void setClobAsCharacterStream(PreparedStatement ps, int paramIndex, Reader characterStream, int contentLength) throws SQLException Implements org. Doc from org. Set the given content as character stream on the given statement, using the given
parameter index. Might simply invoke
| |
| setClobAsString | back to summary |
|---|---|
| public void setClobAsString(PreparedStatement ps, int paramIndex, String content) throws SQLException Implements org. Doc from org. Set the given content as String on the given statement, using the given
parameter index. Might simply invoke
| |