j-easy / easy-batch

The simple, stupid batch framework for Java
https://github.com/j-easy/easy-batch/wiki
MIT License
611 stars 199 forks source link

can we stop to create file when they are no values #384

Closed old741 closed 4 years ago

old741 commented 4 years ago

Hello , i use v5.3.0 I use JdbcRecordReader and writer. I want write in my file if only my query return at least one line. How can I do it please ?

old741 commented 4 years ago

On spring batch it s writer.setShouldDeleteIfEmpty(true); with FlatFileItemWriter How do it on EasyBatch wiith FileRecordWriter please?

fmbenhassine commented 4 years ago

You can't do it with the FileRecordWriter. It is not the responsibility of the writer to delete or move the file if no records have been written. You can do that using a JobListener#afterJob instead, something like:

public void afterJob(JobReport jobReport) {
    if (jobReport.getMetrics().getWriteCount() == 0) {
        delete(yourFile);
    }
}
old741 commented 4 years ago

Thank you !