Results 1 to 4 of 4

Thread: ItemReader returning one list

  1. #1
    Join Date
    May 2009
    Posts
    7

    Default ItemReader returning one list

    I'm stucked with a probably little problem, I'd be glad if someone got an idea how to solve it:

    One step of my batch job is supposed to do
    - read a table from a SAP-connection
    - do some business stuff with the rows
    - create some FooItems based on the business an write it out

    So far I thought I could you a custom ItemReader which is called only once and returns a List of FooItems. But then I don't know how to handle this list. The AggregateItemReader doesn't seem to fit. May be a custom mapper can handle the list? Are there any examples out there how to deal with this problem?

  2. #2
    Join Date
    Feb 2008
    Posts
    488

    Default

    I'm not exactly sure what the interface with SAP looks like, but you'll probably want to follow the pattern of something like the JdbcCursorItemReader if you are going to be writing your own ItemReader.

    As it says in the JavaDoc for the ItemReader, the read() method will return items one at a time; the step is over when null is returned. The ListItemReader provides a very basic implementation that you can take a look at to get the idea.

  3. #3
    Join Date
    May 2009
    Posts
    7

    Default

    Unfortunatly the call to the SAP-system returns a whole table (list of items) with ONE call. So the regular ItemReader such JdbcCursorItemReader is not appropriate.

    I tried it with a custom reader where the read()-method gets actually called once and returns a list of FooItems. When its being called for the second time it returns null. But then I'll need a custom mapper to map the List of FooItems...

  4. #4
    Join Date
    Feb 2008
    Posts
    488

    Default

    You should make use of the ListItemReader:

    Code:
    public class SapItemReader<T> extends ItemStreamSupport implements ItemReader<T> {
        private ListItemReader<T> delegate;
    
        @Override
        public void open(ExecutionContext executionContext) throws ItemStreamException {
            List<T> listFromSapQuery = ...;
            this.delegate = new ListItemReader<T>(listFromSapQuery);
        }
    
        public T read() throws ... {
            return this.delegate.read();
        }
    }

Posting Permissions

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