org.springframework.jdbc.core.JdbcTemplate.setFetchSize()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(369)

本文整理了Java中org.springframework.jdbc.core.JdbcTemplate.setFetchSize()方法的一些代码示例,展示了JdbcTemplate.setFetchSize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JdbcTemplate.setFetchSize()方法的具体详情如下:
包路径:org.springframework.jdbc.core.JdbcTemplate
类名称:JdbcTemplate
方法名:setFetchSize

JdbcTemplate.setFetchSize介绍

[英]Set the fetch size for this JdbcTemplate. This is important for processing large result sets: Setting this higher than the default value will increase processing speed at the cost of memory consumption; setting this lower can avoid transferring row data that will never be read by the application.

Default is -1, indicating to use the JDBC driver's default configuration (i.e. to not pass a specific fetch size setting on to the driver).

Note: As of 4.3, negative values other than -1 will get passed on to the driver, since e.g. MySQL supports special behavior for Integer.MIN_VALUE.
[中]设置此JdbcTemplate的获取大小。这对于处理大型结果集很重要:将其设置为高于默认值将以内存消耗为代价提高处理速度;将此值设置为较低可以避免传输应用程序永远无法读取的行数据。
默认值为-1,表示使用JDBC驱动程序的默认配置(即不将特定的提取大小设置传递给驱动程序)。
注意:从4.3开始,除了-1之外的负值将传递给驱动程序,因为例如MySQL支持Integer的特殊行为。最小值。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Set the fetch size for this RDBMS operation. This is important for processing
 * large result sets: Setting this higher than the default value will increase
 * processing speed at the cost of memory consumption; setting this lower can
 * avoid transferring row data that will never be read by the application.
 * <p>Default is 0, indicating to use the driver's default.
 * @see org.springframework.jdbc.core.JdbcTemplate#setFetchSize
 */
public void setFetchSize(int fetchSize) {
  this.jdbcTemplate.setFetchSize(fetchSize);
}

代码示例来源:origin: spring-projects/spring-batch

/**
 * Check mandatory properties.
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 */
@Override
public void afterPropertiesSet() throws Exception {
  super.afterPropertiesSet();
  Assert.notNull(dataSource, "DataSource may not be null");
  JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
  if (fetchSize != VALUE_NOT_SET) {
    jdbcTemplate.setFetchSize(fetchSize);
  }
  jdbcTemplate.setMaxRows(getPageSize());
  namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
  Assert.notNull(queryProvider, "QueryProvider may not be null");
  queryProvider.init(dataSource);
  this.firstPageSql = queryProvider.generateFirstPageQuery(getPageSize());
  this.remainingPagesSql = queryProvider.generateRemainingPagesQuery(getPageSize());
}

代码示例来源:origin: spring-projects/spring-framework

template.setDataSource(this.dataSource);
if (fetchSize != null) {
  template.setFetchSize(fetchSize.intValue());

代码示例来源:origin: spring-projects/spring-integration

/**
 * The JDBC {@link DataSource} to use when interacting with the database.
 * The passed-in {@link DataSource} is used to instantiate a {@link JdbcTemplate}
 * with {@link JdbcTemplate#setFetchSize(int)} set to <code>1</code>
 * and with {@link JdbcTemplate#setMaxRows(int)} set to <code>1</code>.
 * @param dataSource a {@link DataSource}
 */
public void setDataSource(DataSource dataSource) {
  this.jdbcTemplate = new JdbcTemplate(dataSource);
  this.jdbcTemplate.setFetchSize(1);
  this.jdbcTemplate.setMaxRows(1);
}

代码示例来源:origin: spring-projects/spring-integration

/**
 * Create a {@link org.springframework.integration.store.MessageStore}
 * with all mandatory properties. The passed-in
 * {@link DataSource} is used to instantiate a {@link JdbcTemplate}
 * with {@link JdbcTemplate#setFetchSize(int)} set to <code>1</code>
 * and with {@link JdbcTemplate#setMaxRows(int)} set to <code>1</code>.
 * @param dataSource a {@link DataSource}
 */
public JdbcChannelMessageStore(DataSource dataSource) {
  this();
  this.jdbcTemplate = new JdbcTemplate(dataSource);
  this.jdbcTemplate.setFetchSize(1);
  this.jdbcTemplate.setMaxRows(1);
}

代码示例来源:origin: komoot/photon

/**
 * @param host     database host
 * @param port     database port
 * @param database database name
 * @param username db username
 * @param password db username's password
 */
public NominatimConnector(String host, int port, String database, String username, String password) {
  BasicDataSource dataSource = new BasicDataSource();
  dataSource.setUrl(String.format("jdbc:postgres_jts://%s:%d/%s", host, port, database));
  dataSource.setUsername(username);
  dataSource.setPassword(password);
  dataSource.setDriverClassName(JtsWrapper.class.getCanonicalName());
  dataSource.setDefaultAutoCommit(false);
  template = new JdbcTemplate(dataSource);
  template.setFetchSize(100000);
}

代码示例来源:origin: org.springframework/org.springframework.jdbc

/**
 * Set the fetch size for this RDBMS operation. This is important for processing
 * large result sets: Setting this higher than the default value will increase
 * processing speed at the cost of memory consumption; setting this lower can
 * avoid transferring row data that will never be read by the application.
 * <p>Default is 0, indicating to use the driver's default.
 * @see org.springframework.jdbc.core.JdbcTemplate#setFetchSize
 */
public void setFetchSize(int fetchSize) {
  this.jdbcTemplate.setFetchSize(fetchSize);
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Set the fetch size for this RDBMS operation. This is important for processing
 * large result sets: Setting this higher than the default value will increase
 * processing speed at the cost of memory consumption; setting this lower can
 * avoid transferring row data that will never be read by the application.
 * <p>Default is 0, indicating to use the driver's default.
 * @see org.springframework.jdbc.core.JdbcTemplate#setFetchSize
 */
public void setFetchSize(int fetchSize) {
  this.jdbcTemplate.setFetchSize(fetchSize);
}

代码示例来源:origin: openstreetmap/osmosis

private void setStatementFetchSizeForStreaming() {
  jdbcTemplate.setFetchSize(10000);
}

代码示例来源:origin: io.bufferslayer/bufferslayer-spring-jdbc

public void setFetchSize(int fetchSize) {
 delegate.setFetchSize(fetchSize);
}

代码示例来源:origin: io.bufferslayer/buffer-spring-jdbc

public void setFetchSize(int fetchSize) {
 delegate.setFetchSize(fetchSize);
}

代码示例来源:origin: stackoverflow.com

// jdbc
statement.setFetchSize(500);

// spring     
JdbcTemplate jdbc = new JdbcTemplate(datasource);
jdbc.setFetchSize(500);

代码示例来源:origin: openstreetmap/osmosis

private void setStatementFetchSizeForStreaming() {
  switch (dbType) {
  case POSTGRESQL:
    jdbcTemplate.setFetchSize(10000);
    break;
  case MYSQL:
    jdbcTemplate.setFetchSize(Integer.MIN_VALUE);
    break;
  default:
    throw createUnknownDbTypeException();
  }
}

代码示例来源:origin: pl.edu.icm.yadda/recorddb-editor

@Override
protected void queryMetasPage(int limit, String query, Object[] params, ResultSetExtractor rse) throws DataAccessException {
  // NOTE: Postgres with fetch size limit = 0 caches all the data in memory
  if (jdbcops instanceof JdbcTemplate) {
    ((JdbcTemplate)jdbcops).setFetchSize(limit);
  }
  jdbcops.query(query, params, rse);
  if (jdbcops instanceof JdbcTemplate) {
    ((JdbcTemplate)jdbcops).setFetchSize(0);
  }        
}

代码示例来源:origin: org.openstreetmap.osmosis/osmosis-apidb

private void setStatementFetchSizeForStreaming() {
  switch (dbType) {
  case POSTGRESQL:
    jdbcTemplate.setFetchSize(10000);
    break;
  case MYSQL:
    jdbcTemplate.setFetchSize(Integer.MIN_VALUE);
    break;
  default:
    throw createUnknownDbTypeException();
  }
}

代码示例来源:origin: org.springframework.integration/spring-integration-jdbc

/**
 * The JDBC {@link DataSource} to use when interacting with the database.
 * The passed-in {@link DataSource} is used to instantiate a {@link JdbcTemplate}
 * with {@link JdbcTemplate#setFetchSize(int)} set to <code>1</code>
 * and with {@link JdbcTemplate#setMaxRows(int)} set to <code>1</code>.
 * @param dataSource a {@link DataSource}
 */
public void setDataSource(DataSource dataSource) {
  this.jdbcTemplate = new JdbcTemplate(dataSource);
  this.jdbcTemplate.setFetchSize(1);
  this.jdbcTemplate.setMaxRows(1);
}

代码示例来源:origin: org.springframework.integration/spring-integration-jdbc

/**
 * Create a {@link org.springframework.integration.store.MessageStore}
 * with all mandatory properties. The passed-in
 * {@link DataSource} is used to instantiate a {@link JdbcTemplate}
 * with {@link JdbcTemplate#setFetchSize(int)} set to <code>1</code>
 * and with {@link JdbcTemplate#setMaxRows(int)} set to <code>1</code>.
 * @param dataSource a {@link DataSource}
 */
public JdbcChannelMessageStore(DataSource dataSource) {
  this();
  this.jdbcTemplate = new JdbcTemplate(dataSource);
  this.jdbcTemplate.setFetchSize(1);
  this.jdbcTemplate.setMaxRows(1);
}

代码示例来源:origin: io.openscore/score-queue-impl

private <T> List<T> doSelect(String sql, int maxRows, RowMapper<T> rowMapper, Object... params) {
  JdbcTemplate template = jdbcTemplateMap.get(maxRows);
  if (template == null) try {
    lock.lock();
    template = new JdbcTemplate(dataSource);
    template.setFetchSize(maxRows);
    template.setMaxRows(maxRows);
    jdbcTemplateMap.put(maxRows, template);
  } finally{
    lock.unlock();
  }
  return doSelect0(template, sql, rowMapper, params);
}

代码示例来源:origin: io.openscore/score-queue-impl

public Integer countMessagesWithoutAckForWorker(int maxSize, long minVersionAllowed, String workerUuid) {
  jdbcTemplate.setMaxRows(maxSize);
  jdbcTemplate.setFetchSize(maxSize);
  Object[] values = {
      workerUuid,
      ExecStatus.SENT.getNumber(),
      minVersionAllowed,
  };
  long time = System.currentTimeMillis();
  Integer result = jdbcTemplate.queryForObject(QUERY_COUNT_MESSAGES_WITHOUT_ACK_FOR_WORKER_SQL, values,Integer.class);
  if (logger.isTraceEnabled())
    logger.trace("Query [" + QUERY_COUNT_MESSAGES_WITHOUT_ACK_FOR_WORKER_SQL + "] took " + (System.currentTimeMillis() - time) + " ms");
  if (logger.isDebugEnabled()) {
    logger.debug("Got msg without ack :" + result + ",for version:" + minVersionAllowed + ",for worker:" + workerUuid);
  }
  return result.intValue();
}

代码示例来源:origin: com.googlecode.metridoc/metridoc-camel-core

@Override
public SqlRowSet queryForRowSet(String query, int fetchSize) {
  JdbcTemplate jdbcTemplate = new StreamingJdbcTemplate();
  jdbcTemplate.setDataSource(dataSource);
  jdbcTemplate.setFetchSize(fetchSize);
  if(!query.startsWith("select")){
    query = "select * from " + query;
  }
  return jdbcTemplate.queryForRowSet(query);
}

相关文章