Browse Source

Ensure configuration methods in SimpleJdbcInsert support method chaining

Prior to this commit, the withoutTableColumnMetaDataAccess() and
includeSynonymsForTableColumnMetaData() methods in SimpleJdbcInsert
incorrectly declared a SimpleJdbcInsertOperations return type, which
prevented method chaining when the instance was declared to be of type
SimpleJdbcInsert.

This commit changes the return types of those methods to
SimpleJdbcInsert to benefit from covariant return types like the rest
of the configuration methods in SimpleJdbcInsert.

Closes gh-31177
pull/31186/head
Sam Brannen 2 years ago
parent
commit
734d113b11
  1. 4
      spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsert.java
  2. 22
      spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java

4
spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsert.java

@ -109,13 +109,13 @@ public class SimpleJdbcInsert extends AbstractJdbcInsert implements SimpleJdbcIn @@ -109,13 +109,13 @@ public class SimpleJdbcInsert extends AbstractJdbcInsert implements SimpleJdbcIn
}
@Override
public SimpleJdbcInsertOperations withoutTableColumnMetaDataAccess() {
public SimpleJdbcInsert withoutTableColumnMetaDataAccess() {
setAccessTableColumnMetaData(false);
return this;
}
@Override
public SimpleJdbcInsertOperations includeSynonymsForTableColumnMetaData() {
public SimpleJdbcInsert includeSynonymsForTableColumnMetaData() {
setOverrideIncludeSynonymsDefault(true);
return this;
}

22
spring-jdbc/src/test/java/org/springframework/jdbc/core/simple/SimpleJdbcInsertTests.java

@ -64,6 +64,28 @@ class SimpleJdbcInsertTests { @@ -64,6 +64,28 @@ class SimpleJdbcInsertTests {
}
/**
* This method does not test any functionality but rather only that
* configuration methods can be chained without compiler errors.
*/
@Test // gh-31177
void methodChaining() throws Exception {
SimpleJdbcInsert insert = new SimpleJdbcInsert(dataSource)
.withCatalogName("my_catalog")
.withSchemaName("my_schema")
.withTableName("my_table")
.usingColumns("col1", "col2")
.usingGeneratedKeyColumns("id")
.usingQuotedIdentifiers()
.withoutTableColumnMetaDataAccess()
.includeSynonymsForTableColumnMetaData();
assertThat(insert).isNotNull();
// Satisfy the @AfterEach mock verification.
connection.close();
}
@Test
void noSuchTable() throws Exception {
ResultSet resultSet = mock();

Loading…
Cancel
Save