Simply create an SqlSession with BATCH as ExecutorType.
@Transactional
public void insert(Collection<DatasetData> datas) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
try {
DatasetDataMapper datasetDataMapper = sqlSession.getMapper(DatasetDataMapper.class);
for (DatasetData data: datas) {
datasetDataMapper.insertBatch(data);
}
sqlSession.commit();
} finally {
sqlSession.close();
}
}
Christian
I have a { call myproc( {#param1, VARCHAR}, {#param2, VARCHAR} ... ) }
statement and mapper function.
I loop through the dataset and call the mapper method for each record.
If I run with SIMPLE I can see multiple prepared statements and executes.
If I run with BATCH I can see no statements, just a pause in the logging
where you would expect.
The time to call with 100 records ~8 seconds, 1000 records ~80 seconds.
The time makes no difference if I run with SIMPLE or BATCH ExecutorType.
I've stepped through MyBatic BatchExecutor code and confirmed the same
statement is reused, and that executeBatch() is called and is where all
the time is spent.
I've also tried with POOLED, apache BasicDataSource, apache
PooledDataSource, C3P0 ComboPooledDataSource, none make any difference.
I'm wondering if this is a limitation of calling stored procedure rather
than insert/update sql statement, though this would seem wrong to me.
But like I said, probably I'm missing something fundamental in my
understanding. Any ideas gratefully received.
thanks...Roy