添加“with ur"或由 JdbcPagingItemReader 生成的查询中的任何其他前缀 [英] Adding "with ur" or any other prefix in query being generated by JdbcPagingItemReader

查看:26
本文介绍了添加“with ur"或由 JdbcPagingItemReader 生成的查询中的任何其他前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 java 应用程序来从一个表中读取数据并将其写入某个文件中.我们的表有数百万条记录,我们需要每天阅读并写入文件.所以,我使用 Spring 批处理和阅读器作为 JdbcPagingItemReader,因为我想读取页面中的记录.以下是我的 bean 定义:-

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 像这样在内部生成查询:-

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

但是,我正在使用 DB2 数据库,并在读取期间使用全局设置锁定.所以避免这种情况,我们在每个查询中使用with ur",我们写.所以我希望我的查询生成为:-

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

我无论如何也找不到做同样的事情.请让我知道如何在使用 JdbcPagingItemReader 时在查询中附加一些额外的部分.

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.

推荐答案

JdbcPagingItemReader允许你设置一个PagingQueryProvider;也许使用自定义的 - 而不是使用由 SqlPagingQueryProviderFactoryBean 生成的 - 可以解决您的问题

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

这篇关于添加“with ur"或由 JdbcPagingItemReader 生成的查询中的任何其他前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆