Adding “with ur” or any other prefix in query being generated by JdbcPagingItemReader

扶醉桌前 提交于 2019-12-08 12:42:14

问题


I am writing a java application to read data from one table and writing it in some file. Our table have million of records, which we need to read daily and write in file. So, I am using Spring batch with reader as JdbcPagingItemReader, as I want to read records in pages. Below is my bean defination :-

<bean id="pagingItemReader" class="org.springframework.batch.item.database.JdbcPagingItemReader"
      scope="step">
    <property name="dataSource" ref="dataSource" />
    <property name="queryProvider">
      <bean
        class="org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="selectClause" value="select user_id, user_name , address" />
        <property name="fromClause" value="from mySchema.test" />
        <property name="whereClause" value="where address <> ''" />
        <property name="sortKey" value="user_id" />
      </bean>
    </property>
    <property name="pageSize" value="1000" />
    <property name="rowMapper">
        <bean class="com.myCompany.myClient.batch.reader.userVO" />
    </property>
</bean>

Spring generates the query internally like this :-

SELECT user_id, user_name , address  FROM mySchema.test ORDER BY user_id ASC FETCH FIRST 1000 ROWS ONLY

However, I am using DB2 database ,with global setting to take lock during the read. So avoid this, we use "with ur" in every query,we write. So I want my query to be generated as :-

   SELECT user_id, user_name , address  FROM mySchema.test ORDER BY user_id ASC FETCH FIRST 1000 ROWS ONLY with ur

I am not able to find anyway to do same. Kindly let me know how to append some extra part in query while using JdbcPagingItemReader.


回答1:


JdbcPagingItemReader allow you to set a PagingQueryProvider; maybe using a custom one - instead of using the one generated by SqlPagingQueryProviderFactoryBean - can solve your problem



来源:https://stackoverflow.com/questions/27617273/adding-with-ur-or-any-other-prefix-in-query-being-generated-by-jdbcpagingitemr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!