Results 1 to 6 of 6

Thread: shouldDeleteIfEmpty not working in 2.1.2.RELEASE

  1. #1
    Join Date
    Feb 2008
    Location
    Bedford, England
    Posts
    5

    Default shouldDeleteIfEmpty not working in 2.1.2.RELEASE

    Hi,
    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. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    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. #3
    Join Date
    Feb 2008
    Location
    Bedford, England
    Posts
    5

    Default

    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">
    </bean>
    </property>
    <property name="pageSize" value="1000"/>
    <property name="rowMapper" ref="someMapper"/>
    <property name="maxItemCount" value="500000"/>
    </bean>

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

    <!-- 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="org.springframework.core.io.FileSystemResou rce">
    <constructor-arg index="0">
    <value>prefix_</value>
    </constructor-arg>
    </bean>
    </property>
    <property name="delegate" ref="resourceAwareItemWriterItemStream"/>
    </bean>

    <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"/>
    </bean>


    <job id="fullExport" restartable="false" xmlns="http://www.springframework.org/schema/batch">
    <step id="exportFileStep">
    <tasklet>
    <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>
    </chunk>
    </tasklet>
    <end on="COMPLETED"/>
    </step>
    </job>

    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. #4
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    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. #5
    Join Date
    Feb 2008
    Location
    Bedford, England
    Posts
    5

    Default

    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. #6
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    Raise a JIRA if you think it's a bug?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •