Announcement Announcement Module
No announcement yet.
shouldDeleteIfEmpty not working in 2.1.2.RELEASE Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • shouldDeleteIfEmpty not working in 2.1.2.RELEASE

    just upgraded spring batch from 2.0.3.RELEASE to 2.1.2.RELEASE.

    FlatFileItemWriter.shouldDeleteIfEmpty seems to be not working in 2.1.1.RELEASE and 2.1.2.RELEASE
    but it works fine in 2.0.3.RELEASE.

    Any ideas?

  • #2
    I don't see anything that changed in the implementation. Can you provide a test case or a bit more detail about what the scenario is when it doesn't work?


    • #3
      Testcase is
      1)Fetch the data from mysql database
      2)format the data
      3)write it into flat files.
      the output file should be correspond to a database row.
      i.e. one file per record

      <!-- database reader-->
      <bean id="mysqlItemReader" class="org.springframework.batch.item.database.Jdb cPagingItemReader" scope="step">
      <property name="dataSource" ref="mysqlDataSource"/>
      <property name="queryProvider">
      <bean class="org.springframework.batch.item.database.sup port.MySqlPagingQueryProvider">
      <property name="pageSize" value="1000"/>
      <property name="rowMapper" ref="someMapper"/>
      <property name="maxItemCount" value="500000"/>

      <!-- impl of org.springframework.batch.item.ItemProcessor-->
      <bean id="itemProcessor" class="com.batch.DataProcessor">

      <!-- file writer-->
      <bean id="itemWriter" class="org.springframework.batch.item.file.MultiRe sourceItemWriter">
      <property name="itemCountLimitPerResource" value="1"/>
      <property name="resourceSuffixCreator" ref="xmlFileSuffixCreator"/>
      <property name="resource">
      <bean class=" rce">
      <constructor-arg index="0">
      <property name="delegate" ref="resourceAwareItemWriterItemStream"/>

      <bean id="resourceAwareItemWriterItemStream" class="org.springframework.batch.item.file.FlatFil eItemWriter">
      <property name="lineAggregator" ref="lineAggregator"/>
      <property name="shouldDeleteIfEmpty" value="true"/>
      <property name="encoding" value="UTF-8"/>

      <job id="fullExport" restartable="false" xmlns="">
      <step id="exportFileStep">
      <chunk reader="mysqlItemReader" writer="itemWriter" commit-interval="1" processor="itemProcessor" skip-limit="1">
      <skippable-exception-classes><include class="org.xml.sax.SAXParseException"/></skippable-exception-classes>
      <end on="COMPLETED"/>

      The reason i set commit-interval to 1 it writes one file for one record
      otherwise it write 'n' records on one file ('n' - commit-interval value)


      • #4
        Is the problem related to skips (do you get empty files if there are no exceptions and no skips)? I can imagine, without having looked in detail, that the item writer for a file that was supposed to contain a failed item was opened but not closed, so the check to delete on empty was never made.


        • #5
          It generates a empty file when there is no item to read as well as if there is a item to read.

          if there is no items to read it generates 1 empty file
          if there is 10 items to read it generates 10 files with data + 1 empty file

          there is no exception/skips.


          • #6
            Raise a JIRA if you think it's a bug?