Announcement Announcement Module
No announcement yet.
Calling ItemWriter from Item Processor Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling ItemWriter from Item Processor


    I know the way chunk based processing works is that it reads a specified amount in the ItemReader, passes this to ItemProcessor who then works on this list one by one and then passes the list to ItemWriter. I was just wondering if there was a way to call ItemWriter from Item Processor before the chunk is completed or irrespective of chunk size.

    Basically in the code below I want to call the ReportBuilder bean (ItemWriter) when I see a new Customer (notice how I am ordering by this field in the Reader). So when Processor sees a new value for this field it should write out the data it has built so far. This way each separate Customer will be a separate report.

    <job id="settlementReportJob" xmlns="">
    		<step id="createFilesStep">
    			<tasklet transaction-manager="jpaTransactionManager">
    				<chunk reader="ReportDataLoader" processor="ReportDataProcessor"
    					writer="ReportBuilder" commit-interval="-1" />
    	<bean id="ReportDataLoader"
    		<property name="entityManagerFactory" ref="AS400entityManagerFactory"/>
    		<property name="queryString" value="select a from Sdjphy01 a order by customer"/>
    Thanks in advance for any help.

  • #2
    Not sure if I understand your request, but a commit-interval=1 will send every customer to the writer after processor handles it.


    • #3
      Commit-interval property must be a positive value. Of course, you can use the delegate pattern for the Writers.

      First, define the writer bean in your context file (bean id="writerBean".... /> and then, use this bean in your ItemProcessor by creating a FlatFileItemProcessor<T> writerName (with @Autowired), but you need to define the ItemWriter as non-transactional (there is a property in the FlatFileItemWriter) and open and close the file manually.

      Hope to help you.


      • #4
        I'm wondering if you have the wrong thing defined as the "Item" you are passing through the chunk. What is returned by the ItemReader (or ItemProcessor if it is different)? I would expect that to be a customer object. That way you could set the commit count to 1 and have each one written separately via normal chunk processing.

        You don't want to call the writer directly.