类 AbstractLobCreatingPreparedStatementCallback
- java.lang.Object
- org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback
- 所有已实现的接口:
PreparedStatementCallback<Integer>
public abstract class AbstractLobCreatingPreparedStatementCallback extends Object implements PreparedStatementCallback<Integer>
AbstractPreparedStatementCallback
implementation that manages aLobCreator
. 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
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); } } );
- 从以下版本开始:
- 1.0.2
- 作者:
- Juergen Hoeller
- 另请参阅:
LobCreator
构造器概要
构造器 构造器 说明 AbstractLobCreatingPreparedStatementCallback(LobHandler lobHandler)
Create a new AbstractLobCreatingPreparedStatementCallback for the given LobHandler.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 Integer
doInPreparedStatement(PreparedStatement ps)
Gets called byJdbcTemplate.execute
with an active JDBC PreparedStatement.protected abstract void
setValues(PreparedStatement ps, LobCreator lobCreator)
Set values on the given PreparedStatement, using the given LobCreator for BLOB/CLOB arguments.
构造器详细资料
AbstractLobCreatingPreparedStatementCallback
public AbstractLobCreatingPreparedStatementCallback(LobHandler lobHandler)
Create a new AbstractLobCreatingPreparedStatementCallback for the given LobHandler.- 参数:
lobHandler
- the LobHandler to create LobCreators with
方法详细资料
doInPreparedStatement
public final Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException
从接口复制的说明:PreparedStatementCallback
Gets called byJdbcTemplate.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.
- 指定者:
doInPreparedStatement
在接口中PreparedStatementCallback<Integer>
- 参数:
ps
- active JDBC PreparedStatement- 返回:
- a result object, or
null
if none - 抛出:
SQLException
- if thrown by a JDBC method, to be auto-converted to a DataAccessException by an SQLExceptionTranslatorDataAccessException
- in case of custom exceptions- 另请参阅:
JdbcTemplate.queryForObject(String, Object[], Class)
,JdbcTemplate.queryForList(String, Object[])
setValues
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.- 参数:
ps
- the PreparedStatement to uselobCreator
- the LobCreator to use- 抛出:
SQLException
- if thrown by JDBC methodsDataAccessException
- in case of custom exceptions