I am using spring batch to process multiple files using MultiResourcePartitioner and all the itemreader and writers are in step scope.Each step runs individual files and commits to database at interval of 1000. when there is any error during current processing, all the previous commits needs to be roll backed and the step will fail . Thus the file contents are not added to the database.
Which is the best way among these:
Using Transaction Propogation as NESTED.
Setting commit interval in chunk with Integer.MAXVALUE , this will not work as the file have large items and fail with heap space.
any other way to have transaction at the step level.
I have the sample xml file shown below:
<bean id="filepartitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner">
<property name="resources" value="classpath:${filepath}" />
</bean>
<bean id="fileItemReader" scope="step" autowire-candidate="false" parent="itemReaderParent">
<property name="resource" value="#{stepExecutionContext[fileName]}" />
</bean>
<step id="step1" xmlns="http://www.springframework.org/schema/batch">
<tasklet transaction-manager="ratransactionManager" >
<chunk writer="jdbcItenWriter" reader="fileItemReader" processor="itemProcessor" commit-interval="800" retry-limit="3">
<retryable-exception-classes>
<include class="org.springframework.dao.DeadlockLoserDataAccessException"/>
</retryable-exception-classes>
</chunk>
<listeners>
<listener ref="customStepExecutionListener">
</listener>
</listeners>
</tasklet>
<fail on="FAILED"/>
</step>
UPDATES:
It seems that the main table (where direct insert happens) is referred by other tables and materialized views . if i delete the data in this table to remove stale records using processed column indicator , the data spooled using MV will show old data. i think staging table is needed for my requirement.
To implement staging data table for this requirement
Create another parallel step to poll database and write the data whose processed column value is Y.
Transfer data at the end of each successful file completion using step listener (afterStep method).
or any other suggestions.