Package org.mybatis.spring.batch
Class MyBatisBatchItemWriter<T>
java.lang.Object
org.mybatis.spring.batch.MyBatisBatchItemWriter<T>
- All Implemented Interfaces:
org.springframework.batch.item.ItemWriter<T>
,org.springframework.beans.factory.InitializingBean
public class MyBatisBatchItemWriter<T>
extends Object
implements org.springframework.batch.item.ItemWriter<T>, org.springframework.beans.factory.InitializingBean
ItemWriter
that uses the batching features from SqlSessionTemplate
to execute a batch of statements
for all items provided.
Provided to facilitate the migration from Spring-Batch iBATIS 2 writers to MyBatis 3.
The user must provide a MyBatis statement id that points to the SQL statement defined in the MyBatis.
It is expected that
is called inside a transaction. If it is not each statement call will be
autocommitted and flushStatements will return no results.
invalid @link
#write(List)
The writer is thread safe after its properties are set (normal singleton behavior), so it can be used to write in multiple concurrent transactions.
- Since:
- 1.1.0
- Author:
- Eduardo Macarron
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Check mandatory properties - there must be an SqlSession and a statementId.void
setAssertUpdates
(boolean assertUpdates) Public setter for the flag that determines whether an assertion is made that number of BatchResult objects returned is one and all items cause at least one row to be updated.void
setItemToParameterConverter
(org.springframework.core.convert.converter.Converter<T, ?> itemToParameterConverter) Public setter for a converter that converting item to parameter object.void
setSqlSessionFactory
(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory) Public setter forSqlSessionFactory
for injection purposes.void
setSqlSessionTemplate
(SqlSessionTemplate sqlSessionTemplate) Public setter for theSqlSessionTemplate
.void
setStatementId
(String statementId) Public setter for the statement id identifying the statement in the SqlMap configuration file.void
-
Constructor Details
-
MyBatisBatchItemWriter
public MyBatisBatchItemWriter()
-
-
Method Details
-
setAssertUpdates
public void setAssertUpdates(boolean assertUpdates) Public setter for the flag that determines whether an assertion is made that number of BatchResult objects returned is one and all items cause at least one row to be updated.- Parameters:
assertUpdates
- the flag to set. Defaults to true;
-
setSqlSessionFactory
public void setSqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory sqlSessionFactory) Public setter forSqlSessionFactory
for injection purposes.- Parameters:
sqlSessionFactory
- a factory object for theSqlSession
.
-
setSqlSessionTemplate
Public setter for theSqlSessionTemplate
.- Parameters:
sqlSessionTemplate
- a template object for use theSqlSession
on the Spring managed transaction
-
setStatementId
Public setter for the statement id identifying the statement in the SqlMap configuration file.- Parameters:
statementId
- the id for the statement
-
setItemToParameterConverter
public void setItemToParameterConverter(org.springframework.core.convert.converter.Converter<T, ?> itemToParameterConverter) Public setter for a converter that converting item to parameter object.By default implementation, an item does not convert.
- Parameters:
itemToParameterConverter
- a converter that converting item to parameter object- Since:
- 2.0.0
-
afterPropertiesSet
public void afterPropertiesSet()Check mandatory properties - there must be an SqlSession and a statementId.- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
write
- Specified by:
write
in interfaceorg.springframework.batch.item.ItemWriter<T>
-