Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.jdbc.support.lob
Class DefaultLobHandler

    java.lang.Object
      org.springframework.jdbc.support.lob.AbstractLobHandler
          org.springframework.jdbc.support.lob.DefaultLobHandler

All Implemented Interfaces:
  LobHandler

    public class DefaultLobHandler

extends AbstractLobHandler

Default implementation of the `LobHandler` interface. Invokes the direct accessor methods that `java.sql.ResultSet` and `java.sql.PreparedStatement` offer.

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, and only to a limited degree to Oracle 10g! As a consequence, use `OracleLobHandler` for accessing Oracle BLOBs/CLOBs.

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.

See the `LobHandler` javadoc for a summary of recommendations.

Since:
  04.12.2003
Author:
  Juergen Hoeller
See Also:
  `setStreamAsLob(boolean)`, `ResultSet.getBytes(int)`, `ResultSet.getBinaryStream(int)`, `ResultSet.getString(int)`, `ResultSet.getAsciiStream(int)`, `ResultSet.getCharacterStream(int)`, `PreparedStatement.setBytes(int, byte[])`, `PreparedStatement.setBinaryStream(int, java.io.InputStream, int)`, `PreparedStatement.setString(int, java.lang.String)`, `PreparedStatement.setAsciiStream(int, java.io.InputStream, int)`, `PreparedStatement.setCharacterStream(int, java.io.Reader, int)`

Nested Class Summary
`protected class` | `DefaultLobHandler.DefaultLobCreator` Default LobCreator implementation as inner class.

Field Summary
`protected org.apache.commons.logging.Log` | `logger`

Constructor Summary
`DefaultLobHandler()`

Method Summary
`java.io.InputStream` | `getBlobAsBinaryStream(java.sql.ResultSet rs, int columnIndex)` Retrieve the given column as binary stream from the given ResultSet.
`byte[]` | `getBlobAsBytes(java.sql.ResultSet rs, int columnIndex)` Retrieve the given column as bytes from the given ResultSet.
`java.io.InputStream` | `getClobAsAsciiStream(java.sql.ResultSet rs, int columnIndex)` Retrieve the given column as ASCII stream from the given ResultSet.
`java.io.Reader` | `getClobAsCharacterStream(java.sql.ResultSet rs, int columnIndex)` Retrieve the given column as character stream from the given ResultSet.
`java.lang.String` | `getClobAsString(java.sql.ResultSet rs, int columnIndex)` Retrieve the given column as String from the given ResultSet.
`LobCreator` | `getLobCreator()` Create a new `LobCreator` instance, i.e.
`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 `setBlob` / `setClob` method with a stream argument.
`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 `setBlob` / `setClob` method with a Blob / Clob argument.

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

### logger

    protected final org.apache.commons.logging.Log logger

Constructor Detail

### DefaultLobHandler

    public DefaultLobHandler()

Method Detail

### setWrapAsLob

    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 `setBlob` / `setClob` method with a Blob / Clob argument.

  Default is "false", using the common JDBC 2.0 `setBinaryStream` / `setCharacterStream` method for setting the content. Switch this to "true" for explicit Blob / Clob wrapping against JDBC drivers that are known to require such wrapping (e.g. PostgreSQL's).

  This setting affects byte array / String arguments as well as stream arguments, unless `"streamAsLob"` overrides this handling to use JDBC 4.0's new explicit streaming support (if available).

  See Also:
    `PreparedStatement.setBlob(int, java.sql.Blob)`, `PreparedStatement.setClob(int, java.sql.Clob)`

### setStreamAsLob

    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 `setBlob` / `setClob` method with a stream argument.

  Default is "false", using the common JDBC 2.0 `setBinaryStream` / `setCharacterStream` method for setting the content. Switch this to "true" for explicit JDBC 4.0 usage, provided that your JDBC driver actually supports those JDBC 4.0 operations (e.g. Derby's).

  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 `"wrapAsLob"` setting.

  See Also:
    `PreparedStatement.setBlob(int, java.io.InputStream, long)`, `PreparedStatement.setClob(int, java.io.Reader, long)`

### getBlobAsBytes

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

  Description copied from interface: `LobHandler`
  Retrieve the given column as bytes from the given ResultSet. Might simply invoke `ResultSet.getBytes` or work with `ResultSet.getBlob`, depending on the database and driver.

  Parameters:
    `rs` - the ResultSet to retrieve the content from
    `columnIndex` - the column index to use
  Returns:
    the content as byte array, or `null` in case of SQL NULL
  Throws:
    `java.sql.SQLException` - if thrown by JDBC methods
  See Also:
    `ResultSet.getBytes(int)`

### getBlobAsBinaryStream

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

  Description copied from interface: `LobHandler`
  Retrieve the given column as binary stream from the given ResultSet. Might simply invoke `ResultSet.getBinaryStream` or work with `ResultSet.getBlob`, depending on the database and driver.

  Parameters:
    `rs` - the ResultSet to retrieve the content from
    `columnIndex` - the column index to use
  Returns:
    the content as binary stream, or `null` in case of SQL NULL
  Throws:
    `java.sql.SQLException` - if thrown by JDBC methods
  See Also:
    `ResultSet.getBinaryStream(int)`

### getClobAsString

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

  Description copied from interface: `LobHandler`
  Retrieve the given column as String from the given ResultSet. Might simply invoke `ResultSet.getString` or work with `ResultSet.getClob`, depending on the database and driver.

  Parameters:
    `rs` - the ResultSet to retrieve the content from
    `columnIndex` - the column index to use
  Returns:
    the content as String, or `null` in case of SQL NULL
  Throws:
    `java.sql.SQLException` - if thrown by JDBC methods
  See Also:
    `ResultSet.getString(int)`

### getClobAsAsciiStream

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

  Description copied from interface: `LobHandler`
  Retrieve the given column as ASCII stream from the given ResultSet. Might simply invoke `ResultSet.getAsciiStream` or work with `ResultSet.getClob`, depending on the database and driver.

  Parameters:
    `rs` - the ResultSet to retrieve the content from
    `columnIndex` - the column index to use
  Returns:
    the content as ASCII stream, or `null` in case of SQL NULL
  Throws:
    `java.sql.SQLException` - if thrown by JDBC methods
  See Also:
    `ResultSet.getAsciiStream(int)`

### getClobAsCharacterStream

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

  Description copied from interface: `LobHandler`
  Retrieve the given column as character stream from the given ResultSet. Might simply invoke `ResultSet.getCharacterStream` or work with `ResultSet.getClob`, depending on the database and driver.

  Parameters:
    `rs` - the ResultSet to retrieve the content from
    `columnIndex` - the column index to use
  Returns:
    the content as character stream
  Throws:
    `java.sql.SQLException` - if thrown by JDBC methods
  See Also:
    `ResultSet.getCharacterStream(int)`

### getLobCreator

    public LobCreator getLobCreator()

  Description copied from interface: `LobHandler`
  Create a new `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.

  Returns:
    the new LobCreator instance
  See Also:
    `LobCreator.close()`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD