类 JdbcBatchItemWriter<T>
- java.lang.Object
- org.springframework.batch.item.database.JdbcBatchItemWriter<T>
- 所有已实现的接口:
ItemWriter<T>
,org.springframework.beans.factory.InitializingBean
public class JdbcBatchItemWriter<T> extends java.lang.Object implements ItemWriter<T>, org.springframework.beans.factory.InitializingBean
The user must provide an SQL query and a special callback for either ofItemWriter
that uses the batching features fromNamedParameterJdbcTemplate
to execute a batch of statements for all items provided.ItemPreparedStatementSetter
orItemSqlParameterSourceProvider
. You can use either named parameters or the traditional '?' placeholders. If you use the named parameter support then you should provide aItemSqlParameterSourceProvider
, otherwise you should provide aItemPreparedStatementSetter
. This callback would be responsible for mapping the item to the parameters needed to execute the SQL statement.
It is expected thatwrite(List)
is called inside a transaction.
The writer is thread-safe after its properties are set (normal singleton behavior), so it can be used to write in multiple concurrent transactions.- 从以下版本开始:
- 2.0
- 作者:
- Dave Syer, Thomas Risberg, Michael Minella
字段概要
字段 修饰符和类型 字段 说明 protected static org.apache.commons.logging.Log
logger
构造器概要
构造器 构造器 说明 JdbcBatchItemWriter()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Check mandatory properties - there must be a SimpleJdbcTemplate and an SQL statement plus a parameter source.void
setAssertUpdates(boolean assertUpdates)
Public setter for the flag that determines whether an assertion is made that all items cause at least one row to be updated.void
setDataSource(javax.sql.DataSource dataSource)
Public setter for the data source for injection purposes.void
setItemPreparedStatementSetter(ItemPreparedStatementSetter<T> preparedStatementSetter)
Public setter for theItemPreparedStatementSetter
.void
setItemSqlParameterSourceProvider(ItemSqlParameterSourceProvider<T> itemSqlParameterSourceProvider)
Public setter for theItemSqlParameterSourceProvider
.void
setJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations namedParameterJdbcTemplate)
Public setter for theNamedParameterJdbcOperations
.void
setSql(java.lang.String sql)
Public setter for the query string to execute on write.void
write(java.util.List<? extends T> items)
Process the supplied data element.
字段详细资料
logger
protected static final org.apache.commons.logging.Log logger
构造器详细资料
JdbcBatchItemWriter
public JdbcBatchItemWriter()
方法详细资料
setAssertUpdates
public void setAssertUpdates(boolean assertUpdates)
Public setter for the flag that determines whether an assertion is made that all items cause at least one row to be updated.- 参数:
assertUpdates
- the flag to set. Defaults to true;
setSql
public void setSql(java.lang.String sql)
Public setter for the query string to execute on write. The parameters should correspond to those known to theItemPreparedStatementSetter
.- 参数:
sql
- the query to set
setItemPreparedStatementSetter
public void setItemPreparedStatementSetter(ItemPreparedStatementSetter<T> preparedStatementSetter)
Public setter for theItemPreparedStatementSetter
.- 参数:
preparedStatementSetter
- theItemPreparedStatementSetter
to set. This is required when using traditional '?' placeholders for the SQL statement.
setItemSqlParameterSourceProvider
public void setItemSqlParameterSourceProvider(ItemSqlParameterSourceProvider<T> itemSqlParameterSourceProvider)
Public setter for theItemSqlParameterSourceProvider
.- 参数:
itemSqlParameterSourceProvider
- theItemSqlParameterSourceProvider
to set. This is required when using named parameters for the SQL statement and the type to be written does not implementMap
.
setDataSource
public void setDataSource(javax.sql.DataSource dataSource)
Public setter for the data source for injection purposes.- 参数:
dataSource
-DataSource
to use for querying against
setJdbcTemplate
public void setJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations namedParameterJdbcTemplate)
Public setter for theNamedParameterJdbcOperations
.- 参数:
namedParameterJdbcTemplate
- theNamedParameterJdbcOperations
to set
afterPropertiesSet
public void afterPropertiesSet()
Check mandatory properties - there must be a SimpleJdbcTemplate and an SQL statement plus a parameter source.- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
write
public void write(java.util.List<? extends T> items) throws java.lang.Exception
从接口复制的说明:ItemWriter
Process the supplied data element. Will not be called with any null items in normal operation.- 指定者:
write
在接口中ItemWriter<T>
- 参数:
items
- items to be written- 抛出:
java.lang.Exception
- if there are errors. The framework will catch the exception and convert or rethrow it as appropriate.