Skip to content

Commit d94388f

Browse files
committed
Add some missing configuration properties for JdbcTemplate
- ignore-warnings - skip-results-processing - skip-undeclared-results - results-map-case-insensitive Fix spring-projectsGH-44419 Signed-off-by: Yanming Zhou <[email protected]>
1 parent 9364879 commit d94388f

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*
2828
* @author Kazuki Shimizu
2929
* @author Stephane Nicoll
30+
* @author Yanming Zhou
3031
* @since 2.0.0
3132
*/
3233
@ConfigurationProperties("spring.jdbc")
@@ -61,6 +62,33 @@ public static class Template {
6162
@DurationUnit(ChronoUnit.SECONDS)
6263
private Duration queryTimeout;
6364

65+
/**
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.
74+
*/
75+
private boolean skipResultsProcessing;
76+
77+
/**
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}.
82+
*/
83+
private boolean skipUndeclaredResults;
84+
85+
/**
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.
89+
*/
90+
private boolean resultsMapCaseInsensitive;
91+
6492
public int getFetchSize() {
6593
return this.fetchSize;
6694
}
@@ -85,6 +113,38 @@ public void setQueryTimeout(Duration queryTimeout) {
85113
this.queryTimeout = queryTimeout;
86114
}
87115

116+
public boolean isIgnoreWarnings() {
117+
return this.ignoreWarnings;
118+
}
119+
120+
public void setIgnoreWarnings(boolean ignoreWarnings) {
121+
this.ignoreWarnings = ignoreWarnings;
122+
}
123+
124+
public boolean isSkipResultsProcessing() {
125+
return this.skipResultsProcessing;
126+
}
127+
128+
public void setSkipResultsProcessing(boolean skipResultsProcessing) {
129+
this.skipResultsProcessing = skipResultsProcessing;
130+
}
131+
132+
public boolean isSkipUndeclaredResults() {
133+
return this.skipUndeclaredResults;
134+
}
135+
136+
public void setSkipUndeclaredResults(boolean skipUndeclaredResults) {
137+
this.skipUndeclaredResults = skipUndeclaredResults;
138+
}
139+
140+
public boolean isResultsMapCaseInsensitive() {
141+
return this.resultsMapCaseInsensitive;
142+
}
143+
144+
public void setResultsMapCaseInsensitive(boolean resultsMapCaseInsensitive) {
145+
this.resultsMapCaseInsensitive = resultsMapCaseInsensitive;
146+
}
147+
88148
}
89149

90150
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
* Configuration for {@link JdbcTemplateConfiguration}.
3232
*
3333
* @author Stephane Nicoll
34+
* @author Yanming Zhou
3435
*/
3536
@Configuration(proxyBeanMethods = false)
3637
@ConditionalOnMissingBean(JdbcOperations.class)
@@ -47,6 +48,10 @@ JdbcTemplate jdbcTemplate(DataSource dataSource, JdbcProperties properties,
4748
if (template.getQueryTimeout() != null) {
4849
jdbcTemplate.setQueryTimeout((int) template.getQueryTimeout().getSeconds());
4950
}
51+
jdbcTemplate.setIgnoreWarnings(template.isIgnoreWarnings());
52+
jdbcTemplate.setSkipResultsProcessing(template.isSkipResultsProcessing());
53+
jdbcTemplate.setSkipUndeclaredResults(template.isSkipUndeclaredResults());
54+
jdbcTemplate.setResultsMapCaseInsensitive(template.isResultsMapCaseInsensitive());
5055
sqlExceptionTranslator.ifUnique(jdbcTemplate::setExceptionTranslator);
5156
return jdbcTemplate;
5257
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
* @author Stephane Nicoll
4848
* @author Kazuki Shimizu
4949
* @author Dan Zheng
50+
* @author Yanming Zhou
5051
*/
5152
class JdbcTemplateAutoConfigurationTests {
5253

@@ -64,21 +65,32 @@ void testJdbcTemplateExists() {
6465
assertThat(jdbcTemplate.getFetchSize()).isEqualTo(-1);
6566
assertThat(jdbcTemplate.getQueryTimeout()).isEqualTo(-1);
6667
assertThat(jdbcTemplate.getMaxRows()).isEqualTo(-1);
68+
assertThat(jdbcTemplate.isIgnoreWarnings()).isEqualTo(true);
69+
assertThat(jdbcTemplate.isSkipResultsProcessing()).isEqualTo(false);
70+
assertThat(jdbcTemplate.isSkipUndeclaredResults()).isEqualTo(false);
71+
assertThat(jdbcTemplate.isResultsMapCaseInsensitive()).isEqualTo(false);
6772
});
6873
}
6974

7075
@Test
7176
void testJdbcTemplateWithCustomProperties() {
7277
this.contextRunner
7378
.withPropertyValues("spring.jdbc.template.fetch-size:100", "spring.jdbc.template.query-timeout:60",
74-
"spring.jdbc.template.max-rows:1000")
79+
"spring.jdbc.template.max-rows:1000", "spring.jdbc.template.ignore-warnings:false",
80+
"spring.jdbc.template.skip-results-processing:true",
81+
"spring.jdbc.template.skip-undeclared-results:true",
82+
"spring.jdbc.template.results-map-case-insensitive:true")
7583
.run((context) -> {
7684
assertThat(context).hasSingleBean(JdbcOperations.class);
7785
JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);
7886
assertThat(jdbcTemplate.getDataSource()).isNotNull();
7987
assertThat(jdbcTemplate.getFetchSize()).isEqualTo(100);
8088
assertThat(jdbcTemplate.getQueryTimeout()).isEqualTo(60);
8189
assertThat(jdbcTemplate.getMaxRows()).isEqualTo(1000);
90+
assertThat(jdbcTemplate.isIgnoreWarnings()).isEqualTo(false);
91+
assertThat(jdbcTemplate.isSkipResultsProcessing()).isEqualTo(true);
92+
assertThat(jdbcTemplate.isSkipUndeclaredResults()).isEqualTo(true);
93+
assertThat(jdbcTemplate.isResultsMapCaseInsensitive()).isEqualTo(true);
8294
});
8395
}
8496

0 commit comments

Comments
 (0)