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
This commit is contained in:
Mikhail2048
2023-01-09 11:34:25 +03:00
committed by Mark Paluch
parent eed7c9dcf7
commit b8e8c996b6
9 changed files with 97 additions and 4 deletions

View File

@@ -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<WithDelimitedColumn> 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<DummyEntity> findByEnumType(Direction direction);
}
interface RootRepository extends ListCrudRepository<Root, Long> {
List<Root> findAllByOrderByIdAsc();
}
interface WithDelimitedColumnRepository extends CrudRepository<WithDelimitedColumn, Long> { }
@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<Root, Long> {
List<Root> findAllByOrderByIdAsc();
}
@Value
@@ -1424,6 +1450,14 @@ public class JdbcRepositoryIntegrationTests {
@MappedCollection(idColumn = "ROOT_ID", keyColumn = "ROOT_KEY") List<Intermediate> 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 {

View File

@@ -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)
);

View File

@@ -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)
);

View File

@@ -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)
);

View File

@@ -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)
);

View File

@@ -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)
);

View File

@@ -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)
);

View File

@@ -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)
)

View File

@@ -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)
);