Results 1 to 3 of 3

Thread: FlatFileItemWriter more than one lineAggregators

  1. #1
    Join Date
    Feb 2009
    Posts
    16

    Question FlatFileItemWriter more than one lineAggregators

    Hi I have some question about Spring Batch 2.0

    in FlatFileItemWriter can I have more than one lineAggregators?
    coz in my case is :
    if found items = header then use HeaderAggregator
    if found items = data then use DataAggregator
    if found items = trailer then user TrailerAggregator

    Any suggestion? thx

  2. #2
    Join Date
    Feb 2008
    Posts
    488

    Default

    Use the composite pattern to create composite line aggregator. This example comes from the samples:

    Code:
    public class DelegatingTradeLineAggregator implements LineAggregator<Object> {
        private LineAggregator<Trade> tradeLineAggregator;
        private LineAggregator<CustomerCredit> customerLineAggregator;
    
        public String aggregate(Object item) {
            if (item instanceof Trade) {
                return this.tradeLineAggregator.aggregate((Trade) item);
            }
            else if (item instanceof CustomerCredit) {
                return this.customerLineAggregator.aggregate((CustomerCredit) item);
            }
            else {
                throw new RuntimeException();
            }
        }
    }

  3. #3
    Join Date
    Feb 2009
    Posts
    16

    Default Thanks

    Hi DHGarrette thank you for your quick response.

Posting Permissions

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