Skip to content

Commit e2422c2

Browse files
mipo256mp911de
authored andcommitted
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
1 parent 0dd33f8 commit e2422c2

9 files changed

+97
-4
lines changed

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
import org.springframework.data.jdbc.testing.EnabledOnFeature;
7070
import org.springframework.data.jdbc.testing.TestConfiguration;
7171
import org.springframework.data.jdbc.testing.TestDatabaseFeatures;
72+
import org.springframework.data.relational.core.mapping.Column;
7273
import org.springframework.data.relational.core.mapping.MappedCollection;
74+
import org.springframework.data.relational.core.mapping.Table;
7375
import org.springframework.data.relational.core.mapping.event.AbstractRelationalEvent;
7476
import org.springframework.data.relational.core.mapping.event.AfterConvertEvent;
7577
import org.springframework.data.relational.core.sql.LockMode;
@@ -113,6 +115,8 @@ public class JdbcRepositoryIntegrationTests {
113115
@Autowired MyEventListener eventListener;
114116
@Autowired RootRepository rootRepository;
115117

118+
@Autowired WithDelimitedColumnRepository withDelimitedColumnRepository;
119+
116120
private static DummyEntity createDummyEntity() {
117121

118122
DummyEntity entity = new DummyEntity();
@@ -1238,6 +1242,22 @@ void fetchByExampleFluentOnlyInstantOneValueAsSimple() {
12381242
assertThat(match.get().getName()).contains(two.getName());
12391243
}
12401244

1245+
@Test
1246+
void withDelimitedColumnTest() {
1247+
WithDelimitedColumn withDelimitedColumn = new WithDelimitedColumn();
1248+
withDelimitedColumn.setType("TYPICAL");
1249+
withDelimitedColumn.setIdentifier("UR-123");
1250+
1251+
WithDelimitedColumn saved = withDelimitedColumnRepository.save(withDelimitedColumn);
1252+
1253+
assertThat(saved.getId()).isNotNull();
1254+
1255+
Optional<WithDelimitedColumn> inDatabase = withDelimitedColumnRepository.findById(saved.getId());
1256+
1257+
assertThat(inDatabase).isPresent();
1258+
assertThat(inDatabase.get().getIdentifier()).isEqualTo("UR-123");
1259+
}
1260+
12411261
private Root createRoot(String namePrefix) {
12421262

12431263
return new Root(null, namePrefix,
@@ -1361,10 +1381,17 @@ interface DummyEntityRepository extends CrudRepository<DummyEntity, Long>, Query
13611381
List<DummyEntity> findByEnumType(Direction direction);
13621382
}
13631383

1384+
interface RootRepository extends ListCrudRepository<Root, Long> {
1385+
List<Root> findAllByOrderByIdAsc();
1386+
}
1387+
1388+
interface WithDelimitedColumnRepository extends CrudRepository<WithDelimitedColumn, Long> { }
1389+
13641390
@Configuration
13651391
@Import(TestConfiguration.class)
13661392
static class Config {
13671393

1394+
13681395
@Autowired JdbcRepositoryFactory factory;
13691396

13701397
@Bean
@@ -1382,6 +1409,9 @@ RootRepository rootRepository() {
13821409
return factory.getRepository(RootRepository.class);
13831410
}
13841411

1412+
@Bean
1413+
WithDelimitedColumnRepository withDelimitedColumnRepository() { return factory.getRepository(WithDelimitedColumnRepository.class); }
1414+
13851415
@Bean
13861416
NamedQueries namedQueries() throws IOException {
13871417

@@ -1404,15 +1434,11 @@ public ExtensionAwareQueryMethodEvaluationContextProvider extensionAware(List<Ev
14041434

14051435
return extensionAwareQueryMethodEvaluationContextProvider;
14061436
}
1407-
14081437
@Bean
14091438
public EvaluationContextExtension evaluationContextExtension() {
14101439
return new MyIdContextProvider();
14111440
}
1412-
}
14131441

1414-
interface RootRepository extends ListCrudRepository<Root, Long> {
1415-
List<Root> findAllByOrderByIdAsc();
14161442
}
14171443

14181444
@Value
@@ -1424,6 +1450,14 @@ static class Root {
14241450
@MappedCollection(idColumn = "ROOT_ID", keyColumn = "ROOT_KEY") List<Intermediate> intermediates;
14251451
}
14261452

1453+
@Data
1454+
@Table("WITH_DELIMITED_COLUMN")
1455+
static class WithDelimitedColumn {
1456+
@Id Long id;
1457+
@Column("ORG.XTUNIT.IDENTIFIER") String identifier;
1458+
@Column ("STYPE") String type;
1459+
}
1460+
14271461
@Value
14281462
static class Intermediate {
14291463

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ DROP TABLE dummy_entity;
22
DROP TABLE ROOT;
33
DROP TABLE INTERMEDIATE;
44
DROP TABLE LEAF;
5+
DROP TABLE WITH_DELIMITED_COLUMN;
56

67
CREATE TABLE dummy_entity
78
(
@@ -37,3 +38,10 @@ CREATE TABLE LEAF
3738
INTERMEDIATE_ID BIGINT,
3839
INTERMEDIATE_KEY INTEGER
3940
);
41+
42+
CREATE TABLE WITH_DELIMITED_COLUMN
43+
(
44+
ID BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY,
45+
"ORG.XTUNIT.IDENTIFIER" VARCHAR(100),
46+
STYPE VARCHAR(100)
47+
);

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-h2.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ CREATE TABLE LEAF
3232
INTERMEDIATE_ID BIGINT,
3333
INTERMEDIATE_KEY INTEGER
3434
);
35+
36+
CREATE TABLE WITH_DELIMITED_COLUMN
37+
(
38+
ID BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY,
39+
"ORG.XTUNIT.IDENTIFIER" VARCHAR(100),
40+
STYPE VARCHAR(100)
41+
);

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-hsql.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ CREATE TABLE LEAF
3232
INTERMEDIATE_ID BIGINT,
3333
INTERMEDIATE_KEY INTEGER
3434
);
35+
36+
CREATE TABLE WITH_DELIMITED_COLUMN
37+
(
38+
ID BIGINT GENERATED BY DEFAULT AS IDENTITY ( START WITH 1 ) PRIMARY KEY,
39+
"ORG.XTUNIT.IDENTIFIER" VARCHAR(100),
40+
STYPE VARCHAR(100)
41+
);

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ CREATE TABLE LEAF
3232
INTERMEDIATE_ID BIGINT,
3333
INTERMEDIATE_KEY INTEGER
3434
);
35+
36+
CREATE TABLE WITH_DELIMITED_COLUMN
37+
(
38+
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
39+
`ORG.XTUNIT.IDENTIFIER` VARCHAR(100),
40+
STYPE VARCHAR(100)
41+
);

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mssql.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ DROP TABLE IF EXISTS dummy_entity;
22
DROP TABLE IF EXISTS ROOT;
33
DROP TABLE IF EXISTS INTERMEDIATE;
44
DROP TABLE IF EXISTS LEAF;
5+
DROP TABLE IF EXISTS WITH_DELIMITED_COLUMN;
56

67
CREATE TABLE dummy_entity
78
(
@@ -37,3 +38,10 @@ CREATE TABLE LEAF
3738
INTERMEDIATE_ID BIGINT,
3839
INTERMEDIATE_KEY INTEGER
3940
);
41+
42+
CREATE TABLE WITH_DELIMITED_COLUMN
43+
(
44+
ID BIGINT IDENTITY PRIMARY KEY,
45+
"ORG.XTUNIT.IDENTIFIER" VARCHAR(100),
46+
STYPE VARCHAR(100)
47+
);

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mysql.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ CREATE TABLE LEAF
3636
INTERMEDIATE_KEY INTEGER
3737
);
3838

39+
CREATE TABLE WITH_DELIMITED_COLUMN
40+
(
41+
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
42+
`ORG.XTUNIT.IDENTIFIER` VARCHAR(100),
43+
STYPE VARCHAR(100)
44+
);

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-oracle.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ DROP TABLE DUMMY_ENTITY CASCADE CONSTRAINTS PURGE;
22
DROP TABLE ROOT CASCADE CONSTRAINTS PURGE;
33
DROP TABLE INTERMEDIATE CASCADE CONSTRAINTS PURGE;
44
DROP TABLE LEAF CASCADE CONSTRAINTS PURGE;
5+
DROP TABLE WITH_DELIMITED_COLUMN CASCADE CONSTRAINTS PURGE;
56

67
CREATE TABLE DUMMY_ENTITY
78
(
@@ -37,3 +38,10 @@ CREATE TABLE LEAF
3738
INTERMEDIATE_ID NUMBER,
3839
INTERMEDIATE_KEY NUMBER
3940
);
41+
42+
CREATE TABLE WITH_DELIMITED_COLUMN
43+
(
44+
ID NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY,
45+
"ORG.XTUNIT.IDENTIFIER" VARCHAR(100),
46+
STYPE VARCHAR(100)
47+
)

spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-postgres.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ DROP TABLE dummy_entity;
22
DROP TABLE ROOT;
33
DROP TABLE INTERMEDIATE;
44
DROP TABLE LEAF;
5+
DROP TABLE WITH_DELIMITED_COLUMN;
56

67
CREATE TABLE dummy_entity
78
(
@@ -37,3 +38,10 @@ CREATE TABLE LEAF
3738
"INTERMEDIATE_ID" BIGINT,
3839
"INTERMEDIATE_KEY" INTEGER
3940
);
41+
42+
CREATE TABLE "WITH_DELIMITED_COLUMN"
43+
(
44+
ID BIGINT IDENTITY PRIMARY KEY,
45+
"ORG.XTUNIT.IDENTIFIER" VARCHAR(100),
46+
STYPE VARCHAR(100)
47+
);

0 commit comments

Comments
 (0)