Browse Source

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
pull/1403/head
Mikhail2048 3 years ago committed by Mark Paluch
parent
commit
b8e8c996b6
No known key found for this signature in database
GPG Key ID: 4406B84C1661DCD1
  1. 42
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java
  2. 8
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql
  3. 7
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-h2.sql
  4. 7
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-hsql.sql
  5. 7
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql
  6. 8
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mssql.sql
  7. 6
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mysql.sql
  8. 8
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-oracle.sql
  9. 8
      spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-postgres.sql

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

@ -69,7 +69,9 @@ import org.springframework.data.jdbc.testing.AssumeFeatureTestExecutionListener; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 {

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

@ -2,6 +2,7 @@ DROP TABLE dummy_entity; @@ -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 @@ -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)
);

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

@ -32,3 +32,10 @@ CREATE TABLE LEAF @@ -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)
);

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

@ -32,3 +32,10 @@ CREATE TABLE LEAF @@ -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)
);

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

@ -32,3 +32,10 @@ CREATE TABLE LEAF @@ -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)
);

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

@ -2,6 +2,7 @@ DROP TABLE IF EXISTS dummy_entity; @@ -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 @@ -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)
);

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

@ -36,3 +36,9 @@ CREATE TABLE LEAF @@ -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)
);

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

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

@ -2,6 +2,7 @@ DROP TABLE dummy_entity; @@ -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 @@ -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)
);
Loading…
Cancel
Save