Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I skip/delete an item in the ItemProcessor?

Tags:

spring-batch

I want to be able to delete an item while processing it if it fits a specific logic. For example, if the item doesn't contain a value I'm looking for, I don't want to that item to be written out to the file.

I'm currently using a class which implements ItemProcessor<T,T>.

Do I just return null?

like image 553
samwell Avatar asked Jun 26 '14 15:06

samwell


People also ask

How do you skip a line in Spring Batch?

We can handle it via a custom Dummy Object. And just use the below when required to skip the record in the reader : return MyClass. getDummyyClassObject();

What is ItemProcessor?

An ItemProcessor is simple. Given one object, transform it and return another. The provided object may or may not be of the same type. The point is that business logic may be applied within the process, and it is completely up to the developer to create that logic. An ItemProcessor can be wired directly into a step.

Can we have multiple processor in Spring Batch?

Yes, that could be done, indeed.

What is Chunk oriented processing?

Chunk oriented processing refers to reading the data one at a time and creating 'chunks' that are written out within a transaction boundary. Once the number of items read equals the commit interval, the entire chunk is written out by the ItemWriter , and then the transaction is committed.


1 Answers

Return null from the processor like below.

public class ExceptionRecordValidator implements 
        ItemProcessor<yourDTO, yourDTO>{
@Override
public yourDTO process(
        yourDTOitem) throws Exception {
     if(your requested value found){
         return yourDTO ;
     }else{
         return null;
     }
  }
}
like image 194
Srinivas Kasarla Avatar answered Nov 03 '22 22:11

Srinivas Kasarla