Home » Java » In a read-write chunk oriented process where does Spring Batch commit?

In a read-write chunk oriented process where does Spring Batch commit?

Posted by: admin October 23, 2018 Leave a comment


On my java project, I am having a read (FlatFileItemReader) – write (JdbcBatchItemWriter) chunk oriented process using Spring boot. Using HikariCp datasources.

Looking into the Spring batch jdbc writer we can find that part :

               //some code
                public int[] doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
                    for (T item : items) {
                        itemPreparedStatementSetter.setValues(item, ps);
                    return ps.executeBatch();
              //some code

So basically here if my Hikari datasource has setAutocommit parameter to true it means that after ps.executeBatch() my database will be updated.

First question here, on PreparedStatement.executeBatch() how does it process exactly? Does it commit every sql statement or at the end of every sql statements?

In the case where setAutocommit parameter is on false, after ps.executeBatch() it should not be updated.

Since Spring batch should manage the transaction and so the commit. I tried to find where does it commit for a better understanding on an issue that I have. Looking to ChunkOrientedTasklet, SimpleChunkProcessor and TransactionTemplateI could not find where in the process it does the commit.

So my second question is, where does Spring batch exactly commit on a chunk oriented process?

EDIT : Using Spring batch 3.0.7

EDIT : It seems processed in AbstractPlatformTransactionManager.processCommit(DefaultTransactionStatus status) but still can not understand how.