Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some missing configuration properties for JdbcTemplate #44470

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*
* @author Kazuki Shimizu
* @author Stephane Nicoll
* @author Yanming Zhou
* @since 2.0.0
*/
@ConfigurationProperties("spring.jdbc")
Expand Down Expand Up @@ -61,6 +62,33 @@ public static class Template {
@DurationUnit(ChronoUnit.SECONDS)
private Duration queryTimeout;

/**
* If this variable is {@code false}, we will throw exceptions on SQL warnings.
*/
private boolean ignoreWarnings = true;

/**
* If this variable is set to true, then all results checking will be bypassed for
* any callable statement processing. This can be used to avoid a bug in some
* older Oracle JDBC drivers like 10.1.0.2.
*/
private boolean skipResultsProcessing;

/**
* If this variable is set to true then all results from a stored procedure call
* that don't have a corresponding SqlOutParameter declaration will be bypassed.
* All other results processing will be take place unless the variable
* {@code skipResultsProcessing} is set to {@code true}.
*/
private boolean skipUndeclaredResults;

/**
* If this variable is set to true then execution of a CallableStatement will
* return the results in a Map that uses case-insensitive names for the
* parameters.
*/
private boolean resultsMapCaseInsensitive;

public int getFetchSize() {
return this.fetchSize;
}
Expand All @@ -85,6 +113,38 @@ public void setQueryTimeout(Duration queryTimeout) {
this.queryTimeout = queryTimeout;
}

public boolean isIgnoreWarnings() {
return this.ignoreWarnings;
}

public void setIgnoreWarnings(boolean ignoreWarnings) {
this.ignoreWarnings = ignoreWarnings;
}

public boolean isSkipResultsProcessing() {
return this.skipResultsProcessing;
}

public void setSkipResultsProcessing(boolean skipResultsProcessing) {
this.skipResultsProcessing = skipResultsProcessing;
}

public boolean isSkipUndeclaredResults() {
return this.skipUndeclaredResults;
}

public void setSkipUndeclaredResults(boolean skipUndeclaredResults) {
this.skipUndeclaredResults = skipUndeclaredResults;
}

public boolean isResultsMapCaseInsensitive() {
return this.resultsMapCaseInsensitive;
}

public void setResultsMapCaseInsensitive(boolean resultsMapCaseInsensitive) {
this.resultsMapCaseInsensitive = resultsMapCaseInsensitive;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* Configuration for {@link JdbcTemplateConfiguration}.
*
* @author Stephane Nicoll
* @author Yanming Zhou
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnMissingBean(JdbcOperations.class)
Expand All @@ -47,6 +48,10 @@ JdbcTemplate jdbcTemplate(DataSource dataSource, JdbcProperties properties,
if (template.getQueryTimeout() != null) {
jdbcTemplate.setQueryTimeout((int) template.getQueryTimeout().getSeconds());
}
jdbcTemplate.setIgnoreWarnings(template.isIgnoreWarnings());
jdbcTemplate.setSkipResultsProcessing(template.isSkipResultsProcessing());
jdbcTemplate.setSkipUndeclaredResults(template.isSkipUndeclaredResults());
jdbcTemplate.setResultsMapCaseInsensitive(template.isResultsMapCaseInsensitive());
sqlExceptionTranslator.ifUnique(jdbcTemplate::setExceptionTranslator);
return jdbcTemplate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* @author Stephane Nicoll
* @author Kazuki Shimizu
* @author Dan Zheng
* @author Yanming Zhou
*/
class JdbcTemplateAutoConfigurationTests {

Expand All @@ -64,21 +65,32 @@ void testJdbcTemplateExists() {
assertThat(jdbcTemplate.getFetchSize()).isEqualTo(-1);
assertThat(jdbcTemplate.getQueryTimeout()).isEqualTo(-1);
assertThat(jdbcTemplate.getMaxRows()).isEqualTo(-1);
assertThat(jdbcTemplate.isIgnoreWarnings()).isEqualTo(true);
assertThat(jdbcTemplate.isSkipResultsProcessing()).isEqualTo(false);
assertThat(jdbcTemplate.isSkipUndeclaredResults()).isEqualTo(false);
assertThat(jdbcTemplate.isResultsMapCaseInsensitive()).isEqualTo(false);
});
}

@Test
void testJdbcTemplateWithCustomProperties() {
this.contextRunner
.withPropertyValues("spring.jdbc.template.fetch-size:100", "spring.jdbc.template.query-timeout:60",
"spring.jdbc.template.max-rows:1000")
"spring.jdbc.template.max-rows:1000", "spring.jdbc.template.ignore-warnings:false",
"spring.jdbc.template.skip-results-processing:true",
"spring.jdbc.template.skip-undeclared-results:true",
"spring.jdbc.template.results-map-case-insensitive:true")
.run((context) -> {
assertThat(context).hasSingleBean(JdbcOperations.class);
JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);
assertThat(jdbcTemplate.getDataSource()).isNotNull();
assertThat(jdbcTemplate.getFetchSize()).isEqualTo(100);
assertThat(jdbcTemplate.getQueryTimeout()).isEqualTo(60);
assertThat(jdbcTemplate.getMaxRows()).isEqualTo(1000);
assertThat(jdbcTemplate.isIgnoreWarnings()).isEqualTo(false);
assertThat(jdbcTemplate.isSkipResultsProcessing()).isEqualTo(true);
assertThat(jdbcTemplate.isSkipUndeclaredResults()).isEqualTo(true);
assertThat(jdbcTemplate.isResultsMapCaseInsensitive()).isEqualTo(true);
});
}

Expand Down