Hi,
I managed to prove my suspicion that the JdbcCursorItemReader uses the same query every time.
I created a subclass of JdbcCursorItemReader and overrode the setSql method. Printed the sql and then called super.setSql(); The parameter used stayed the same as the first time so it appeared as if that nothing happened.
I decided that I am going to change the implementation to get around this. So I added a @BeforeStep method to my new JdbcCursorItemReader subclass. In here I initialised and set the PreparedStatementSetter for the JdbcCursorItemReader. I also changed the query to be a parameterized query.
This works fine. I am still not sure why my first approach did not work. Why isn't the query string built up every time by re-evaluating the paramter?
Can you suggest a better way to achieve this?
Config now looks like this:
Code:
<beans:bean id="updatePriceReader" class="batch.jobs.prices.UpdatePriceReader" scope="step">
<beans:property name="dataSource" ref="dataSource"/>
<beans:property name="sql" value="select ID, INSTRUCTIONID, PROCESSED, REFID FROM PRICEINSTRUCTION WHERE PROCESSED = 0 AND REFID= ?"/>
<beans:property name="rowMapper">
<beans:bean class="batch.jobs.prices.PriceInstructionMapper"/>
</beans:property>
</beans:bean>
JdbcCursorItemReader
Code:
public class UpdatePriceReader extends JdbcCursorItemReader {
@BeforeStep
public void setStepExecution(StepExecution stepExecution) {
UpdatePriceParameterSetter paramsSetter = new UpdatePriceParameterSetter();
paramsSetter.setParams(stepExecution.getJobParameters());
super.setPreparedStatementSetter(paramsSetter);
}
}
PreparedStatementSetter
Code:
public class UpdatePriceParameterSetter implements PreparedStatementSetter {
private JobParameters params;
public JobParameters getParams() {
return params;
}
public void setParams(JobParameters params) {
this.params = params;
}
public void setValues(PreparedStatement stmnt) throws SQLException {
stmnt.setString(1, params.getString("refId"));
}
}