From b8e8c996b648458a52d1ff9f8d8a31959bbbee2b Mon Sep 17 00:00:00 2001 From: Mikhail2048 Date: Mon, 9 Jan 2023 11:34:25 +0300 Subject: [PATCH] Integration test added to demonstrate behavior when column names contain characters illegal for bind parameters. See #1405 Related pull request #1406 Original pull request #1415 --- .../JdbcRepositoryIntegrationTests.java | 42 +++++++++++++++++-- .../JdbcRepositoryIntegrationTests-db2.sql | 8 ++++ .../JdbcRepositoryIntegrationTests-h2.sql | 7 ++++ .../JdbcRepositoryIntegrationTests-hsql.sql | 7 ++++ ...JdbcRepositoryIntegrationTests-mariadb.sql | 7 ++++ .../JdbcRepositoryIntegrationTests-mssql.sql | 8 ++++ .../JdbcRepositoryIntegrationTests-mysql.sql | 6 +++ .../JdbcRepositoryIntegrationTests-oracle.sql | 8 ++++ ...dbcRepositoryIntegrationTests-postgres.sql | 8 ++++ 9 files changed, 97 insertions(+), 4 deletions(-) diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java index b632a6ba7..9c9c8646f 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java @@ -69,7 +69,9 @@ import org.springframework.data.jdbc.testing.AssumeFeatureTestExecutionListener; import org.springframework.data.jdbc.testing.EnabledOnFeature; import org.springframework.data.jdbc.testing.TestConfiguration; import org.springframework.data.jdbc.testing.TestDatabaseFeatures; +import org.springframework.data.relational.core.mapping.Column; import org.springframework.data.relational.core.mapping.MappedCollection; +import org.springframework.data.relational.core.mapping.Table; import org.springframework.data.relational.core.mapping.event.AbstractRelationalEvent; import org.springframework.data.relational.core.mapping.event.AfterConvertEvent; import org.springframework.data.relational.core.sql.LockMode; @@ -113,6 +115,8 @@ public class JdbcRepositoryIntegrationTests { @Autowired MyEventListener eventListener; @Autowired RootRepository rootRepository; + @Autowired WithDelimitedColumnRepository withDelimitedColumnRepository; + private static DummyEntity createDummyEntity() { DummyEntity entity = new DummyEntity(); @@ -1238,6 +1242,22 @@ public class JdbcRepositoryIntegrationTests { assertThat(match.get().getName()).contains(two.getName()); } + @Test + void withDelimitedColumnTest() { + WithDelimitedColumn withDelimitedColumn = new WithDelimitedColumn(); + withDelimitedColumn.setType("TYPICAL"); + withDelimitedColumn.setIdentifier("UR-123"); + + WithDelimitedColumn saved = withDelimitedColumnRepository.save(withDelimitedColumn); + + assertThat(saved.getId()).isNotNull(); + + Optional inDatabase = withDelimitedColumnRepository.findById(saved.getId()); + + assertThat(inDatabase).isPresent(); + assertThat(inDatabase.get().getIdentifier()).isEqualTo("UR-123"); + } + private Root createRoot(String namePrefix) { return new Root(null, namePrefix, @@ -1361,10 +1381,17 @@ public class JdbcRepositoryIntegrationTests { List findByEnumType(Direction direction); } + interface RootRepository extends ListCrudRepository { + List findAllByOrderByIdAsc(); + } + + interface WithDelimitedColumnRepository extends CrudRepository { } + @Configuration @Import(TestConfiguration.class) static class Config { + @Autowired JdbcRepositoryFactory factory; @Bean @@ -1382,6 +1409,9 @@ public class JdbcRepositoryIntegrationTests { return factory.getRepository(RootRepository.class); } + @Bean + WithDelimitedColumnRepository withDelimitedColumnRepository() { return factory.getRepository(WithDelimitedColumnRepository.class); } + @Bean NamedQueries namedQueries() throws IOException { @@ -1404,15 +1434,11 @@ public class JdbcRepositoryIntegrationTests { return extensionAwareQueryMethodEvaluationContextProvider; } - @Bean public EvaluationContextExtension evaluationContextExtension() { return new MyIdContextProvider(); } - } - interface RootRepository extends ListCrudRepository { - List findAllByOrderByIdAsc(); } @Value @@ -1424,6 +1450,14 @@ public class JdbcRepositoryIntegrationTests { @MappedCollection(idColumn = "ROOT_ID", keyColumn = "ROOT_KEY") List intermediates; } + @Data + @Table("WITH_DELIMITED_COLUMN") + static class WithDelimitedColumn { + @Id Long id; + @Column("ORG.XTUNIT.IDENTIFIER") String identifier; + @Column ("STYPE") String type; + } + @Value static class Intermediate { diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql index 4916d64b0..e75d0a61b 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql @@ -2,6 +2,7 @@ DROP TABLE dummy_entity; DROP TABLE ROOT; DROP TABLE INTERMEDIATE; DROP TABLE LEAF; +DROP TABLE WITH_DELIMITED_COLUMN; CREATE TABLE dummy_entity ( @@ -37,3 +38,10 @@ CREATE TABLE LEAF INTERMEDIATE_ID BIGINT, INTERMEDIATE_KEY INTEGER ); + +CREATE TABLE WITH_DELIMITED_COLUMN +( + ID BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, + "ORG.XTUNIT.IDENTIFIER" VARCHAR(100), + STYPE VARCHAR(100) +); \ No newline at end of file diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-h2.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-h2.sql index c9eedd6b5..724cd2ba0 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-h2.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-h2.sql @@ -32,3 +32,10 @@ CREATE TABLE LEAF INTERMEDIATE_ID BIGINT, INTERMEDIATE_KEY INTEGER ); + +CREATE TABLE WITH_DELIMITED_COLUMN +( + ID BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, + "ORG.XTUNIT.IDENTIFIER" VARCHAR(100), + STYPE VARCHAR(100) +); \ No newline at end of file diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-hsql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-hsql.sql index c9eedd6b5..724cd2ba0 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-hsql.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-hsql.sql @@ -32,3 +32,10 @@ CREATE TABLE LEAF INTERMEDIATE_ID BIGINT, INTERMEDIATE_KEY INTEGER ); + +CREATE TABLE WITH_DELIMITED_COLUMN +( + ID BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY, + "ORG.XTUNIT.IDENTIFIER" VARCHAR(100), + STYPE VARCHAR(100) +); \ No newline at end of file diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql index 5a4a83d6e..7617b01bf 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql @@ -32,3 +32,10 @@ CREATE TABLE LEAF INTERMEDIATE_ID BIGINT, INTERMEDIATE_KEY INTEGER ); + +CREATE TABLE WITH_DELIMITED_COLUMN +( + ID BIGINT AUTO_INCREMENT PRIMARY KEY, + `ORG.XTUNIT.IDENTIFIER` VARCHAR(100), + STYPE VARCHAR(100) +); \ No newline at end of file diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mssql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mssql.sql index 458bbd0b5..cabaa038b 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mssql.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mssql.sql @@ -2,6 +2,7 @@ DROP TABLE IF EXISTS dummy_entity; DROP TABLE IF EXISTS ROOT; DROP TABLE IF EXISTS INTERMEDIATE; DROP TABLE IF EXISTS LEAF; +DROP TABLE IF EXISTS WITH_DELIMITED_COLUMN; CREATE TABLE dummy_entity ( @@ -37,3 +38,10 @@ CREATE TABLE LEAF INTERMEDIATE_ID BIGINT, INTERMEDIATE_KEY INTEGER ); + +CREATE TABLE WITH_DELIMITED_COLUMN +( + ID BIGINT IDENTITY PRIMARY KEY, + "ORG.XTUNIT.IDENTIFIER" VARCHAR(100), + STYPE VARCHAR(100) +); \ No newline at end of file diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mysql.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mysql.sql index 099958645..00175585d 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mysql.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mysql.sql @@ -36,3 +36,9 @@ CREATE TABLE LEAF INTERMEDIATE_KEY INTEGER ); +CREATE TABLE WITH_DELIMITED_COLUMN +( + ID BIGINT AUTO_INCREMENT PRIMARY KEY, + `ORG.XTUNIT.IDENTIFIER` VARCHAR(100), + STYPE VARCHAR(100) +); \ No newline at end of file diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-oracle.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-oracle.sql index 518e667c1..6383e3c62 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-oracle.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-oracle.sql @@ -2,6 +2,7 @@ DROP TABLE DUMMY_ENTITY CASCADE CONSTRAINTS PURGE; DROP TABLE ROOT CASCADE CONSTRAINTS PURGE; DROP TABLE INTERMEDIATE CASCADE CONSTRAINTS PURGE; DROP TABLE LEAF CASCADE CONSTRAINTS PURGE; +DROP TABLE WITH_DELIMITED_COLUMN CASCADE CONSTRAINTS PURGE; CREATE TABLE DUMMY_ENTITY ( @@ -37,3 +38,10 @@ CREATE TABLE LEAF INTERMEDIATE_ID NUMBER, INTERMEDIATE_KEY NUMBER ); + +CREATE TABLE WITH_DELIMITED_COLUMN +( + ID NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY, + "ORG.XTUNIT.IDENTIFIER" VARCHAR(100), + STYPE VARCHAR(100) +) diff --git a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-postgres.sql b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-postgres.sql index 8bcd1735e..a757002ca 100644 --- a/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-postgres.sql +++ b/spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-postgres.sql @@ -2,6 +2,7 @@ DROP TABLE dummy_entity; DROP TABLE ROOT; DROP TABLE INTERMEDIATE; DROP TABLE LEAF; +DROP TABLE WITH_DELIMITED_COLUMN; CREATE TABLE dummy_entity ( @@ -37,3 +38,10 @@ CREATE TABLE LEAF "INTERMEDIATE_ID" BIGINT, "INTERMEDIATE_KEY" INTEGER ); + +CREATE TABLE "WITH_DELIMITED_COLUMN" +( + ID BIGINT IDENTITY PRIMARY KEY, + "ORG.XTUNIT.IDENTIFIER" VARCHAR(100), + STYPE VARCHAR(100) +); \ No newline at end of file