All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.redis.spring.batch.writer.ProcessingItemWriter Maven / Gradle / Ivy

There is a newer version: 4.0.7
Show newest version
package com.redis.spring.batch.writer;

import java.util.Collection;
import java.util.List;

import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.AbstractItemStreamItemWriter;

public class ProcessingItemWriter extends AbstractItemStreamItemWriter {

    private final ItemProcessor, List> processor;

    private final ItemWriter writer;

    public ProcessingItemWriter(ItemProcessor, List> reader, ItemWriter writer) {
        this.processor = reader;
        this.writer = writer;
    }

    @Override
    public void open(ExecutionContext executionContext) {
        if (processor instanceof ItemStream) {
            ((ItemStream) processor).open(executionContext);
        }
        super.open(executionContext);
    }

    @Override
    public void update(ExecutionContext executionContext) {
        if (processor instanceof ItemStream) {
            ((ItemStream) processor).update(executionContext);
        }
        super.update(executionContext);
    }

    @Override
    public void close() {
        super.close();
        if (processor instanceof ItemStream) {
            ((ItemStream) processor).close();
        }
    }

    @Override
    public void write(List items) throws Exception {
        List targets = processor.process(items);
        if (targets != null) {
            writer.write(targets);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy