Skip to content

Commit 0e09a2d

Browse files
committed
Polish "Add additional configuration properties for JdbcTemplate"
See gh-44470
1 parent baa89c5 commit 0e09a2d

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

Diff for: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcProperties.java

+19-24
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
*
2828
* @author Kazuki Shimizu
2929
* @author Stephane Nicoll
30-
* @author Yanming Zhou
3130
* @since 2.0.0
3231
*/
3332
@ConfigurationProperties("spring.jdbc")
@@ -44,6 +43,12 @@ public Template getTemplate() {
4443
*/
4544
public static class Template {
4645

46+
/**
47+
* Whether to ignore JDBC statement warnings (SQLWarning). When set to false,
48+
* throw a SQLWarningException instead.
49+
*/
50+
private boolean ignoreWarnings = true;
51+
4752
/**
4853
* Number of rows that should be fetched from the database when more rows are
4954
* needed. Use -1 to use the JDBC driver's default configuration.
@@ -63,32 +68,30 @@ public static class Template {
6368
private Duration queryTimeout;
6469

6570
/**
66-
* If this variable is {@code false}, we will throw exceptions on SQL warnings.
67-
*/
68-
private boolean ignoreWarnings = true;
69-
70-
/**
71-
* If this variable is set to true, then all results checking will be bypassed for
72-
* any callable statement processing. This can be used to avoid a bug in some
73-
* older Oracle JDBC drivers like 10.1.0.2.
71+
* Whether results processing should be skipped. Can be used to optimize callable
72+
* statement processing when we know that no results are being passed back.
7473
*/
7574
private boolean skipResultsProcessing;
7675

7776
/**
78-
* If this variable is set to true then all results from a stored procedure call
79-
* that don't have a corresponding SqlOutParameter declaration will be bypassed.
80-
* All other results processing will be take place unless the variable
81-
* {@code skipResultsProcessing} is set to {@code true}.
77+
* Whether undeclared results should be skipped.
8278
*/
8379
private boolean skipUndeclaredResults;
8480

8581
/**
86-
* If this variable is set to true then execution of a CallableStatement will
87-
* return the results in a Map that uses case-insensitive names for the
88-
* parameters.
82+
* Whether execution of a CallableStatement will return the results in a Map that
83+
* uses case-insensitive names for the parameters.
8984
*/
9085
private boolean resultsMapCaseInsensitive;
9186

87+
public boolean isIgnoreWarnings() {
88+
return this.ignoreWarnings;
89+
}
90+
91+
public void setIgnoreWarnings(boolean ignoreWarnings) {
92+
this.ignoreWarnings = ignoreWarnings;
93+
}
94+
9295
public int getFetchSize() {
9396
return this.fetchSize;
9497
}
@@ -113,14 +116,6 @@ public void setQueryTimeout(Duration queryTimeout) {
113116
this.queryTimeout = queryTimeout;
114117
}
115118

116-
public boolean isIgnoreWarnings() {
117-
return this.ignoreWarnings;
118-
}
119-
120-
public void setIgnoreWarnings(boolean ignoreWarnings) {
121-
this.ignoreWarnings = ignoreWarnings;
122-
}
123-
124119
public boolean isSkipResultsProcessing() {
125120
return this.skipResultsProcessing;
126121
}

Diff for: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ JdbcTemplate jdbcTemplate(DataSource dataSource, JdbcProperties properties,
4343
ObjectProvider<SQLExceptionTranslator> sqlExceptionTranslator) {
4444
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
4545
JdbcProperties.Template template = properties.getTemplate();
46+
jdbcTemplate.setIgnoreWarnings(template.isIgnoreWarnings());
4647
jdbcTemplate.setFetchSize(template.getFetchSize());
4748
jdbcTemplate.setMaxRows(template.getMaxRows());
4849
if (template.getQueryTimeout() != null) {
4950
jdbcTemplate.setQueryTimeout((int) template.getQueryTimeout().getSeconds());
5051
}
51-
jdbcTemplate.setIgnoreWarnings(template.isIgnoreWarnings());
5252
jdbcTemplate.setSkipResultsProcessing(template.isSkipResultsProcessing());
5353
jdbcTemplate.setSkipUndeclaredResults(template.isSkipUndeclaredResults());
5454
jdbcTemplate.setResultsMapCaseInsensitive(template.isResultsMapCaseInsensitive());

Diff for: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
* @author Stephane Nicoll
5353
* @author Kazuki Shimizu
5454
* @author Dan Zheng
55-
* @author Yanming Zhou
5655
*/
5756
class JdbcTemplateAutoConfigurationTests {
5857

@@ -67,10 +66,10 @@ void testJdbcTemplateExists() {
6766
assertThat(context).hasSingleBean(JdbcOperations.class);
6867
JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);
6968
assertThat(jdbcTemplate.getDataSource()).isEqualTo(context.getBean(DataSource.class));
69+
assertThat(jdbcTemplate.isIgnoreWarnings()).isEqualTo(true);
7070
assertThat(jdbcTemplate.getFetchSize()).isEqualTo(-1);
7171
assertThat(jdbcTemplate.getQueryTimeout()).isEqualTo(-1);
7272
assertThat(jdbcTemplate.getMaxRows()).isEqualTo(-1);
73-
assertThat(jdbcTemplate.isIgnoreWarnings()).isEqualTo(true);
7473
assertThat(jdbcTemplate.isSkipResultsProcessing()).isEqualTo(false);
7574
assertThat(jdbcTemplate.isSkipUndeclaredResults()).isEqualTo(false);
7675
assertThat(jdbcTemplate.isResultsMapCaseInsensitive()).isEqualTo(false);
@@ -80,19 +79,19 @@ void testJdbcTemplateExists() {
8079
@Test
8180
void testJdbcTemplateWithCustomProperties() {
8281
this.contextRunner
83-
.withPropertyValues("spring.jdbc.template.fetch-size:100", "spring.jdbc.template.query-timeout:60",
84-
"spring.jdbc.template.max-rows:1000", "spring.jdbc.template.ignore-warnings:false",
82+
.withPropertyValues("spring.jdbc.template.ignore-warnings:false", "spring.jdbc.template.fetch-size:100",
83+
"spring.jdbc.template.query-timeout:60", "spring.jdbc.template.max-rows:1000",
8584
"spring.jdbc.template.skip-results-processing:true",
8685
"spring.jdbc.template.skip-undeclared-results:true",
8786
"spring.jdbc.template.results-map-case-insensitive:true")
8887
.run((context) -> {
8988
assertThat(context).hasSingleBean(JdbcOperations.class);
9089
JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);
9190
assertThat(jdbcTemplate.getDataSource()).isNotNull();
91+
assertThat(jdbcTemplate.isIgnoreWarnings()).isEqualTo(false);
9292
assertThat(jdbcTemplate.getFetchSize()).isEqualTo(100);
9393
assertThat(jdbcTemplate.getQueryTimeout()).isEqualTo(60);
9494
assertThat(jdbcTemplate.getMaxRows()).isEqualTo(1000);
95-
assertThat(jdbcTemplate.isIgnoreWarnings()).isEqualTo(false);
9695
assertThat(jdbcTemplate.isSkipResultsProcessing()).isEqualTo(true);
9796
assertThat(jdbcTemplate.isSkipUndeclaredResults()).isEqualTo(true);
9897
assertThat(jdbcTemplate.isResultsMapCaseInsensitive()).isEqualTo(true);

0 commit comments

Comments
 (0)