Top Description Fields Constructors Methods
org.springframework.jdbc.core.support

public abstract Class AbstractLobCreatingPreparedStatementCallback

extends Object
implements PreparedStatementCallback<Integer>
Class Inheritance
All Implemented Interfaces
org.springframework.jdbc.core.PreparedStatementCallback
Imports
java.sql.PreparedStatement, .SQLException, org.springframework.dao.DataAccessException, org.springframework.jdbc.core.PreparedStatementCallback, org.springframework.jdbc.support.lob.LobCreator, .LobHandler, org.springframework.util.Assert

Abstract PreparedStatementCallback implementation that manages a LobCreator. Typically used as inner class, with access to surrounding method arguments.

Delegates to the setValues template method for setting values on the PreparedStatement, using a given LobCreator for BLOB/CLOB arguments.

A usage example with org.springframework.jdbc.core.JdbcTemplate:

JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);  // reusable object
LobHandler lobHandler = new DefaultLobHandler();  // reusable object

jdbcTemplate.execute(
    "INSERT INTO imagedb (image_name, content, description) VALUES (?, ?, ?)",
    new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
      protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException {
        ps.setString(1, name);
        lobCreator.setBlobAsBinaryStream(ps, 2, contentStream, contentLength);
        lobCreator.setClobAsString(ps, 3, description);
      }
    });
Author
Juergen Hoeller
Since
1.0.2
See Also
org.springframework.jdbc.support.lob.LobCreator

Field Summary

Modifier and TypeField and Description
private final LobHandler

Constructor Summary

AccessConstructor and Description
public
AbstractLobCreatingPreparedStatementCallback(LobHandler
the LobHandler to create LobCreators with
lobHandler
)

Create a new AbstractLobCreatingPreparedStatementCallback for the given LobHandler.

Method Summary

Modifier and TypeMethod and Description
public final Integer
doInPreparedStatement(PreparedStatement
active JDBC PreparedStatement
ps
)

Implements org.springframework.jdbc.core.PreparedStatementCallback.doInPreparedStatement.

Gets called by JdbcTemplate.execute with an active JDBC PreparedStatement.

protected abstract void
setValues(PreparedStatement
the PreparedStatement to use
ps
,
LobCreator
the LobCreator to use
lobCreator
)

Set values on the given PreparedStatement, using the given LobCreator for BLOB/CLOB arguments.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

lobHandlerback to summary
private final LobHandler lobHandler

Constructor Detail

AbstractLobCreatingPreparedStatementCallbackback to summary
public AbstractLobCreatingPreparedStatementCallback(LobHandler lobHandler)

Create a new AbstractLobCreatingPreparedStatementCallback for the given LobHandler.

Parameters
lobHandler:LobHandler

the LobHandler to create LobCreators with

Method Detail

doInPreparedStatementback to summary
public final Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException

Implements org.springframework.jdbc.core.PreparedStatementCallback.doInPreparedStatement.

Doc from org.springframework.jdbc.core.PreparedStatementCallback.doInPreparedStatement.

Gets called by JdbcTemplate.execute with an active JDBC PreparedStatement. Does not need to care about closing the Statement or the Connection, or about handling transactions: this will all be handled by Spring's JdbcTemplate.

Note

Any ResultSets opened should be closed in finally blocks within the callback implementation. Spring will close the Statement object after the callback returned, but this does not necessarily imply that the ResultSet resources will be closed: the Statement objects might get pooled by the connection pool, with close calls only returning the object to the pool but not physically closing the resources.

If called without a thread-bound JDBC transaction (initiated by DataSourceTransactionManager), the code will simply get executed on the JDBC connection with its transactional semantics. If JdbcTemplate is configured to use a JTA-aware DataSource, the JDBC connection and thus the callback code will be transactional if a JTA transaction is active.

Allows for returning a result object created within the callback, i.e. a domain object or a collection of domain objects. Note that there's special support for single step actions: see JdbcTemplate.queryForObject etc. A thrown RuntimeException is treated as application exception, it gets propagated to the caller of the template.

Parameters
ps:PreparedStatement

active JDBC PreparedStatement

Returns:Integer

a result object, or null if none

Annotations
@Override
Exceptions
SQLException:
if thrown by a JDBC method, to be auto-converted to a DataAccessException by an SQLExceptionTranslator
DataAccessException:
in case of custom exceptions
setValuesback to summary
protected abstract void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQLException, DataAccessException

Set values on the given PreparedStatement, using the given LobCreator for BLOB/CLOB arguments.

Parameters
ps:PreparedStatement

the PreparedStatement to use

lobCreator:LobCreator

the LobCreator to use

Exceptions
SQLException:
if thrown by JDBC methods
DataAccessException:
in case of custom exceptions