Announcement Announcement Module
Collapse
No announcement yet.
FlatFileItemWriter more than one lineAggregators Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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();
            }
        }
    }

    Comment


    • #3
      Thanks

      Hi DHGarrette thank you for your quick response.

      Comment

      Working...
      X