/** * Prepare the given JDBC Statement (or PreparedStatement or CallableStatement), * applying statement settings such as fetch size, max rows, and query timeout. * @param stmt the JDBC Statement to prepare * @throws SQLException if thrown by JDBC API * @see #setFetchSize * @see #setMaxRows * @see #setQueryTimeout * @see org.springframework.jdbc.datasource.DataSourceUtils#applyTransactionTimeout */ protected void applyStatementSettings(Statement stmt) throws SQLException { int fetchSize = getFetchSize(); if (fetchSize != -1) { stmt.setFetchSize(fetchSize); } int maxRows = getMaxRows(); if (maxRows != -1) { stmt.setMaxRows(maxRows); } DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout()); }
@Test public void parameterPropagation() { SqlOperation operation = new SqlOperation() {}; DataSource ds = new DriverManagerDataSource(); operation.setDataSource(ds); operation.setFetchSize(10); operation.setMaxRows(20); JdbcTemplate jt = operation.getJdbcTemplate(); assertEquals(ds, jt.getDataSource()); assertEquals(10, jt.getFetchSize()); assertEquals(20, jt.getMaxRows()); }
@Test public void testConfig() { assertNotNull(jdbcPagingItemReader); NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) ReflectionTestUtils.getField(jdbcPagingItemReader, "namedParameterJdbcTemplate"); JdbcTemplate jdbcTemplate = (JdbcTemplate) namedParameterJdbcTemplate.getJdbcOperations(); assertEquals(1000, jdbcTemplate.getMaxRows()); assertEquals(100, jdbcTemplate.getFetchSize()); }
/** * Check mandatory properties ({@link DataSource} and * {@link #setChannelMessageStoreQueryProvider(ChannelMessageStoreQueryProvider)}). If no {@link MessageRowMapper} * and {@link ChannelMessageStorePreparedStatementSetter} was explicitly set using * {@link #setMessageRowMapper(MessageRowMapper)} and * {@link #setPreparedStatementSetter(ChannelMessageStorePreparedStatementSetter)} respectively, the default * {@link MessageRowMapper} and {@link ChannelMessageStorePreparedStatementSetter} will be instantiate using the * specified {@link #deserializer} and {@link #lobHandler}. * Also, if the jdbcTemplate's fetchSize property ({@link JdbcTemplate#getFetchSize()}) * is not 1, a warning will be logged. When using the {@link JdbcChannelMessageStore} * with Oracle, the fetchSize value of 1 is needed to ensure FIFO characteristics * of polled messages. Please see the Oracle {@link ChannelMessageStoreQueryProvider} for more details. * @throws Exception Any Exception. */ @Override public void afterPropertiesSet() throws Exception { Assert.state(this.jdbcTemplate != null, "A DataSource or JdbcTemplate must be provided"); Assert.notNull(this.channelMessageStoreQueryProvider, "A channelMessageStoreQueryProvider must be provided."); if (this.messageRowMapper == null) { this.messageRowMapper = new MessageRowMapper(this.deserializer, this.lobHandler); } if (this.jdbcTemplate.getFetchSize() != 1 && logger.isWarnEnabled()) { logger.warn("The jdbcTemplate's fetch size is not 1. This may cause FIFO issues with Oracle databases."); } if (this.preparedStatementSetter == null) { this.preparedStatementSetter = new ChannelMessageStorePreparedStatementSetter(this.serializer, this.lobHandler); } this.jdbcTemplate.afterPropertiesSet(); }
public int getFetchSize() { return delegate.getFetchSize(); }
public int getFetchSize() { return delegate.getFetchSize(); }
/** * Check mandatory properties ({@link DataSource} and * {@link #setChannelMessageStoreQueryProvider(ChannelMessageStoreQueryProvider)}). If no {@link MessageRowMapper} * and {@link ChannelMessageStorePreparedStatementSetter} was explicitly set using * {@link #setMessageRowMapper(MessageRowMapper)} and * {@link #setPreparedStatementSetter(ChannelMessageStorePreparedStatementSetter)} respectively, the default * {@link MessageRowMapper} and {@link ChannelMessageStorePreparedStatementSetter} will be instantiate using the * specified {@link #deserializer} and {@link #lobHandler}. * Also, if the jdbcTemplate's fetchSize property ({@link JdbcTemplate#getFetchSize()}) * is not 1, a warning will be logged. When using the {@link JdbcChannelMessageStore} * with Oracle, the fetchSize value of 1 is needed to ensure FIFO characteristics * of polled messages. Please see the Oracle {@link ChannelMessageStoreQueryProvider} for more details. * @throws Exception Any Exception. */ @Override public void afterPropertiesSet() throws Exception { Assert.state(this.jdbcTemplate != null, "A DataSource or JdbcTemplate must be provided"); Assert.notNull(this.channelMessageStoreQueryProvider, "A channelMessageStoreQueryProvider must be provided."); if (this.messageRowMapper == null) { this.messageRowMapper = new MessageRowMapper(this.deserializer, this.lobHandler); } if (this.jdbcTemplate.getFetchSize() != 1 && logger.isWarnEnabled()) { logger.warn("The jdbcTemplate's fetch size is not 1. This may cause FIFO issues with Oracle databases."); } if (this.preparedStatementSetter == null) { this.preparedStatementSetter = new ChannelMessageStorePreparedStatementSetter(this.serializer, this.lobHandler); } this.jdbcTemplate.afterPropertiesSet(); }
/** * Prepare the given JDBC Statement (or PreparedStatement or CallableStatement), * applying statement settings such as fetch size, max rows, and query timeout. * @param stmt the JDBC Statement to prepare * @throws SQLException if thrown by JDBC API * @see #setFetchSize * @see #setMaxRows * @see #setQueryTimeout * @see org.springframework.jdbc.datasource.DataSourceUtils#applyTransactionTimeout */ protected void applyStatementSettings(Statement stmt) throws SQLException { int fetchSize = getFetchSize(); if (fetchSize > 0) { stmt.setFetchSize(fetchSize); } int maxRows = getMaxRows(); if (maxRows > 0) { stmt.setMaxRows(maxRows); } DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout()); }
/** * Prepare the given JDBC Statement (or PreparedStatement or CallableStatement), * applying statement settings such as fetch size, max rows, and query timeout. * @param stmt the JDBC Statement to prepare * @throws SQLException if thrown by JDBC API * @see #setFetchSize * @see #setMaxRows * @see #setQueryTimeout * @see org.springframework.jdbc.datasource.DataSourceUtils#applyTransactionTimeout */ protected void applyStatementSettings(Statement stmt) throws SQLException { int fetchSize = getFetchSize(); if (fetchSize != -1) { stmt.setFetchSize(fetchSize); } int maxRows = getMaxRows(); if (maxRows != -1) { stmt.setMaxRows(maxRows); } DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout()); }