You can create one view in database for different queries and call it as you call in a JdbcPagingItemReader .If thats not an option then there are different ways , but one way i have worked is as given below.Spring has other option as well, but as per developer stand point following is definitely an option.
Create two item reader ...first one is below
<!--use org.springframework.batch.item.database.JdbcCursorItemReader for simple queries-->
<bean id="itemReader1"
class="org.springframework.batch.item.database.JdbcPagingItemReader"
<property name="sql"
value=" FROM table1" />
.......
<property name="rowMapper">
<bean class="com.sjena.AccountApplicationMapper" />
</property>
</bean>
then another reader from table 2
<bean id="itemReader2"
class="org.springframework.batch.item.database.JdbcCursorItemReader"
<property name="sql"
value="FROM table2" />
.......
<property name="rowMapper">
<bean class="com.sjena.AccountApplicationMapper" />
</property>
</bean>
then delegate to your custom reader
<bean id="customItemReader" class="com.sjena.spring.reader.MyCustomReader"
scope="step">
<property name="itemReader1" ref="itemReader1" />
<property name="itemReader2" ref="itemReader2" />
<property name="pageSize" value="5" />
</bean>
And eventually use this custom reader
<job id="testJob" xmlns="http://www.springframework.org/schema/batch">
<step id="step1">
<tasklet>
<chunk reader="itemReader" writer="itemWriter"
commit-interval="1" />
</tasklet>
</step>
</job>
Then your class is as given below
public class MyCustomReader implements ItemReader<AccountApplicationSummary> {
int pagesize;// you may have diff pagesize for diff item readers
ItemReader<AccountApplication> itemReader1;
ItemReader<AccountApplication> itemReader2;
@Override
public AccountApplicationSummary read()
throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
// itemReader1.setPageSize(pageSize),Be sure, itemReader is JdbcPagingItemReader type and better to do these initiatlization in a init method (implement InitializingBean and use afterpropertyset to set them..)..
//Like pageSize, you can set anyproperty that you may need
AccountApplication application1 = itemReader1.read();
AccountApplication application2 = itemReader2.read();
//And you have results from both tables and now you can play with it
AccountApplicationSummary summary = new AccountApplicationSummary();
return summary;
}
}