2014-12-23 84 views
0

我正在编写一个Java应用程序以从一个表读取数据并将其写入某个文件。我们的表格有百万条记录,我们需要每天读取 并写入文件。所以,我使用Spring批处理作为JdbcPagingItemReader,因为我想读取页面中的记录。 下面是我的豆认定中: -在由JdbcPagingItemReader生成的查询中添加“with ur”或任何其他前缀

<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> 

春内部生成的查询是这样的: -

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

不过,我使用的DB2数据库,具有全局设置的读取过程中采取锁。因此,避免这种情况,我们在每个查询中都使用“with ur”。 所以我想生成我的查询为: -

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

我无法找到无论如何做相同。请让我知道如何在使用JdbcPagingItemReader的同时在查询中附加一些额外的部分。

回答

2

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

+0

我会尝试相同的,如果适合我。将接受答案。如果你有一些伪代码,分享它。 – Panther

+0

抱歉没有代码,因为我从来没有使用它。如果你解决了这个问题,用其他人的解决方案编辑你的问题 –

+0

当然,我想这样做 – Panther

相关问题