I am trying to extend the JdbcCursorItemReader so that I can dynamically set the SQL select statement.
Starting with a working batch job that retrieves data from an Oracle db using JdbcCursorItemReader I wrote a class to extend JdbcCursorItemReader and implemented my own setSql to set the query I generate at runtime.
When I run the batch no data is retrieved from the db, nor are any errors reported anywhere. I have logged the generated SQL and it is correct, and when run from sqldeveloper returns data. It rather looks as if the read is no longer being called.
I am using batch version 2.1.6.Release and Spring 3.0.5.Release
Can anyone help?
This is the reader configuration:
As shown it runs fine but doesn't work, but using the commented class instead of my own it does work.Code:<bean id="reader" scope="step" class="com.me.batch.MyItemReader"> <property name="serviceProvider" value="#{jobParameters['sp.id']}"/> <property name="extractMonth" value="#{jobParameters['extract.month']}"/> <!-- class="org.springframework.batch.item.database.JdbcCursorItemReader"> --> <property name="dataSource" ref="dataSource"/> <property name="sql" value="select * from V_EXPORT"/> <property name="verifyCursorPosition" value="${batch.verify.cursor.position}"/> <property name="rowMapper"> <bean class="com.me.batch.RechargeReadingRowMapper"/> </property> </bean>
My class is defined like this (extract):
Code:public class MyItemReader extends JdbcCursorItemReader<RechargeReading> { public void setSql(String newsql) { // The passed query is ignored. The set serves only as a trigger to create a new query from previously set data. log.debug("Parameter newsql = " + newsql); query = "select * from V_EXPORT where START_TIME between to_date ('" + extractMonth + "01', 'yyyymmdd') AND to_date ('" + extractMonth + lastDay + "', 'yyyymmdd')"; super.setSql(query); log.info("Actual query sql = " + query); }


Reply With Quote