Announcement Announcement Module
Collapse
No announcement yet.
ItemReader returning one list Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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...

      Comment


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

        Comment

        Working...
        X