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

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

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

JdbcTemplate.setMaxRows介绍

[英]Set the maximum number of rows for this JdbcTemplate. This is important for processing subsets of large result sets, avoiding to read and hold the entire result set in the database or in the JDBC driver if we're never interested in the entire result in the first place (for example, when performing searches that might return a large number of matches).

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

Note: As of 4.3, negative values other than -1 will get passed on to the driver, in sync with #setFetchSize's support for special MySQL values.
[中]设置此JdbcTemplate的最大行数。这对于处理大型结果集的子集非常重要,避免在数据库或JDBC驱动程序中读取和保存整个结果集,如果我们一开始对整个结果不感兴趣(例如,在执行可能返回大量匹配项的搜索时)。
默认值为-1,表示使用JDBC驱动程序的默认配置(即不将特定的最大行数设置传递给驱动程序)。
注意:从4.3开始,-1以外的负值将传递给驱动程序,与#setFetchSize对特殊MySQL值的支持同步。

代码示例

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

/**
 * Set the maximum number of rows for this RDBMS operation. This is important
 * for processing subsets of large result sets, avoiding to read and hold
 * the entire result set in the database or in the JDBC driver.
 * <p>Default is 0, indicating to use the driver's default.
 * @see org.springframework.jdbc.core.JdbcTemplate#setMaxRows
 */
public void setMaxRows(int maxRows) {
  this.jdbcTemplate.setMaxRows(maxRows);
}

代码示例来源:origin: alibaba/nacos

jt.setMaxRows(50000);
jt.setQueryTimeout(queryTimeout);

代码示例来源: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: alibaba/nacos

@PostConstruct
public void init() {
  BasicDataSource ds = new BasicDataSource();
  ds.setDriverClassName(JDBC_DRIVER_NAME);
  ds.setUrl("jdbc:derby:" + NACOS_HOME + File.separator + DERBY_BASE_DIR + ";create=true");
  ds.setUsername(USER_NAME);
  ds.setPassword(PASSWORD);
  ds.setInitialSize(20);
  ds.setMaxActive(30);
  ds.setMaxIdle(50);
  ds.setMaxWait(10000L);
  ds.setPoolPreparedStatements(true);
  ds.setTimeBetweenEvictionRunsMillis(TimeUnit.MINUTES
    .toMillis(10L));
  ds.setTestWhileIdle(true);
  jt = new JdbcTemplate();
  jt.setMaxRows(50000);
  jt.setQueryTimeout(5000);
  jt.setDataSource(ds);
  DataSourceTransactionManager tm = new DataSourceTransactionManager();
  tjt = new TransactionTemplate(tm);
  tm.setDataSource(ds);
  tjt.setTimeout(5000);
  if (STANDALONE_MODE && !propertyUtil.isStandaloneUseMysql()) {
    reload();
  }
}

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

template.setMaxRows(maxRows.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: jamesagnew/hapi-fhir

@Override
  public void execute() {
    if (isDryRun()) {
      return;
    }
    List<Map<String, Object>> rows;
    do {
      ourLog.info("Querying for up to {} rows", myBatchSize);
      rows = getTxTemplate().execute(t -> {
        JdbcTemplate jdbcTemplate = newJdbcTemnplate();
        jdbcTemplate.setMaxRows(myBatchSize);
        return jdbcTemplate.query(mySql, new ColumnMapRowMapper());
      });
      ourLog.info("Processing {} rows", rows.size());
      List<Map<String, Object>> finalRows = rows;
      getTxTemplate().execute(t -> {
        for (Map<String, Object> nextRow : finalRows) {
          myConsumer.accept(nextRow);
        }
        return null;
      });
    } while (rows.size() > 0);
  }
}

代码示例来源:origin: jamesagnew/hapi-fhir

getTxTemplate().execute(t -> {
  JdbcTemplate jdbcTemplate = newJdbcTemnplate();
  jdbcTemplate.setMaxRows(100000);
  String sql = "SELECT * FROM " + getTableName() + " WHERE " + getColumnName() + " IS NULL";
  ourLog.info("Finding up to {} rows in {} that requires hashes", myBatchSize, getTableName());

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

/**
 * Set the maximum number of rows for this RDBMS operation. This is important
 * for processing subsets of large result sets, avoiding to read and hold
 * the entire result set in the database or in the JDBC driver.
 * <p>Default is 0, indicating to use the driver's default.
 * @see org.springframework.jdbc.core.JdbcTemplate#setMaxRows
 */
public void setMaxRows(int maxRows) {
  this.jdbcTemplate.setMaxRows(maxRows);
}

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

/**
 * Set the maximum number of rows for this RDBMS operation. This is important
 * for processing subsets of large result sets, avoiding to read and hold
 * the entire result set in the database or in the JDBC driver.
 * <p>Default is 0, indicating to use the driver's default.
 * @see org.springframework.jdbc.core.JdbcTemplate#setMaxRows
 */
public void setMaxRows(int maxRows) {
  this.jdbcTemplate.setMaxRows(maxRows);
}

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

public void setMaxRows(int maxRows) {
 delegate.setMaxRows(maxRows);
}

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

public void setMaxRows(int maxRows) {
 delegate.setMaxRows(maxRows);
}

代码示例来源:origin: org.apache.camel/camel-sql

@Override
public void setMaxMessagesPerPoll(int maxMessagesPerPoll) {
  super.setMaxMessagesPerPoll(maxMessagesPerPoll);
  if (jdbcTemplate != null) {
    jdbcTemplate.setMaxRows(maxMessagesPerPoll);
  }
}

代码示例来源: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: apache/servicemix-bundles

/**
 * 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: fast-sql/FastSQL

/**
 * 创建一个SQL实例
 */
public SQL sql() {
  if (this.jdbcTemplate == null) {
    this.jdbcTemplate = new JdbcTemplate();
    this.jdbcTemplate.setIgnoreWarnings(ignoreWarnings);
    this.jdbcTemplate.setFetchSize(fetchSize);
    this.jdbcTemplate.setMaxRows(maxRows);
    this.jdbcTemplate.setQueryTimeout(queryTimeout);
    this.jdbcTemplate.setSkipResultsProcessing(skipResultsProcessing);
    this.jdbcTemplate.setSkipUndeclaredResults(skipUndeclaredResults);
    this.jdbcTemplate.setResultsMapCaseInsensitive(resultsMapCaseInsensitive);
    this.jdbcTemplate.setDataSource(this.dataSource);
  }
  return new SQL(this.jdbcTemplate, this.dataSourceType);
}

相关文章