有没有一种方法可以在Spring JdbcTemplate中设置特定查询的获取大小?

时间:2018-09-19 05:22:34

标签: spring-jdbc jdbctemplate

我有返回数百万条记录的查询。使用默认的oracle fetch大小,执行大约需要45分钟以上。但是,如果我将fetchsize设置为1000,则它会在5分钟内执行。但是,当返回10行时将其设置为1000,则会减慢速度并消耗过多的内存。

int oldSize = jdbcTemplate.getFetchSize();
jdbcTemplate.setFetchSize(1000);
jdbcTemplate.query();
jdbcTemplate.setFetchSize(oldSize);

但是我认为上面的代码将fetchsize更改为全局,这意味着它对所有查询都更改了。理想情况下,它应特定于查询。如果我的理解错误,请纠正我。

我尝试使用以下代码进行重置。

/**
 * Sets the current notification interruption filter.
 * <p>
 * The interruption filter defines which notifications are allowed to
 * interrupt the user (e.g. via sound &amp; vibration) and is applied
 * globally.
 * <p>
 * Only available if policy access is granted to this package. See
 * {@link #isNotificationPolicyAccessGranted}.
 */
public final void setInterruptionFilter(@InterruptionFilter int interruptionFilter) {
    final INotificationManager service = getService();
    try {
        service.setInterruptionFilter(mContext.getOpPackageName(), interruptionFilter);
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
}

有更好的方法吗?

0 个答案:

没有答案
相关问题