title: Spring Batch: Multiple Item Readers in a single step
body: <p>I am a newbie in spring batch. The task I need to achieve in spring batch as follows:</p>
  
  <ol>
  <li>Need to read some metadata from database.</li>
  <li>Based on this metadata, I need to read some files.</li>
  <li>After some processing, need to write those values from file to database.</li>
  </ol>
  
  <p>My queries are the following:</p>
  
  <p>a. For the 1st requirement, I needed to map the whole resultset to a single object, where Person related data are in 1 table and Pets related data are in another table and joined by person id. </p>
  
  <pre><code>public class PersonPetDetails {
  
      private String personName;
      private String personAddr;
  
      private int personAge;
  
      private List&lt;Pet&gt; pets;
  </code></pre>
  
  <p>For this I have written a custom Item reader which extends JdbcCursorItemReader.</p>
  
  <pre><code>public class CustomJDBCCusrorItemReader&lt;T&gt; extends JdbcCursorItemReader&lt;T&gt; {
  
      private ResultSetExtractor&lt;T&gt; resultSetExtractor;
  
  
      public void setResultSetExtractor(ResultSetExtractor&lt;T&gt; resultSetExtractor) {
          this.resultSetExtractor = resultSetExtractor;
      }
  
      @Override
      public void afterPropertiesSet() throws Exception {
          setVerifyCursorPosition(false);
          Assert.notNull(getDataSource(), "DataSource must be provided");
          Assert.notNull(getSql(), "The SQL query must be provided");
          Assert.notNull(resultSetExtractor, "ResultSetExtractor must be provided");
      }
  
  
      @Override
      protected T readCursor(ResultSet rs, int currentRow) throws SQLException {      
          return resultSetExtractor.extractData(rs);
      }
  }
  </code></pre>
  
  <p>Is this the correct way to achieve my requirement? Or is there a much better way?</p>
  
  <p>b. AFAIK, in spring batch there cannot be a step with just a reader, without a writer. Hence, I cannot call another set of reader in a different step of the Job. Then, how can I call multiple readers in a single step?</p>
  
  <p>c. Also, based on some condition I may need to call a third set of Reader. How can I conditionally call a reader in a step?</p>
  
  <p>Thanks for going through my post. I know it is long. Any help is much appreciated. Also, i guess an example code snippet would help me better understand the point. :) </p>