Skip to content

Commit 83750cc

Browse files
schaudermp911de
authored andcommitted
Fixes build failures with JDK16.
`JdbcMappingContext` sets the SimpleTypeHolder to `JdbcSimpleTypeHolder.HOLDER` by default. Fixing test failures where properties of type `UUID` were considered an entity by the `MappingContext`. This in turn triggered failures when it tried to make fields of `UUID` accessible. Removed the `UUID` field from a test entity in SD Relational, since `UUID` is not a simple type for Relational, nor a proper entity. Replaced `@PostConstruct` with `InitializingBean` in test data source conifgurations in order avoid the requirement of importing javax.annotation-api. Closes #975
1 parent a9912a4 commit 83750cc

File tree

5 files changed

+53
-23
lines changed

5 files changed

+53
-23
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/JdbcMappingContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class JdbcMappingContext extends RelationalMappingContext {
4646
*/
4747
public JdbcMappingContext() {
4848
super();
49+
setSimpleTypeHolder(JdbcSimpleTypes.HOLDER);
4950
}
5051

5152
/**
@@ -55,6 +56,7 @@ public JdbcMappingContext() {
5556
*/
5657
public JdbcMappingContext(NamingStrategy namingStrategy) {
5758
super(namingStrategy);
59+
setSimpleTypeHolder(JdbcSimpleTypes.HOLDER);
5860
}
5961

6062
/*

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.mockito.Mockito.*;
2020

2121
import java.util.Arrays;
22+
import java.util.Collections;
2223
import java.util.List;
2324
import java.util.function.Consumer;
2425

@@ -27,6 +28,8 @@
2728
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2829
import org.springframework.context.annotation.Bean;
2930
import org.springframework.context.annotation.Configuration;
31+
import org.springframework.core.convert.converter.Converter;
32+
import org.springframework.data.convert.WritingConverter;
3033
import org.springframework.data.jdbc.core.JdbcAggregateTemplate;
3134
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
3235
import org.springframework.data.jdbc.core.convert.JdbcConverter;
@@ -46,7 +49,7 @@
4649
public class AbstractJdbcConfigurationIntegrationTests {
4750

4851
@Test // DATAJDBC-395
49-
public void configuresInfrastructureComponents() {
52+
void configuresInfrastructureComponents() {
5053

5154
assertApplicationContext(context -> {
5255

@@ -63,6 +66,18 @@ public void configuresInfrastructureComponents() {
6366
}, AbstractJdbcConfigurationUnderTest.class, Infrastructure.class);
6467
}
6568

69+
@Test // #975
70+
void registersSimpleTypesFromCustomConversions() {
71+
72+
assertApplicationContext(context -> {
73+
JdbcMappingContext mappingContext = context.getBean(JdbcMappingContext.class);
74+
assertThat( //
75+
mappingContext.getPersistentEntity(AbstractJdbcConfigurationUnderTest.Blah.class) //
76+
).describedAs("Blah should not be an entity, since there is a WritingConversion configured for it") //
77+
.isNull();
78+
}, AbstractJdbcConfigurationUnderTest.class, Infrastructure.class);
79+
}
80+
6681
protected static void assertApplicationContext(Consumer<ConfigurableApplicationContext> verification,
6782
Class<?>... configurationClasses) {
6883

@@ -93,6 +108,25 @@ static class AbstractJdbcConfigurationUnderTest extends AbstractJdbcConfiguratio
93108
public Dialect jdbcDialect(NamedParameterJdbcOperations operations) {
94109
return HsqlDbDialect.INSTANCE;
95110
}
111+
112+
@Override
113+
public JdbcCustomConversions jdbcCustomConversions() {
114+
return new JdbcCustomConversions(Collections.singletonList(Blah2BlubbConverter.INSTANCE));
115+
}
116+
117+
@WritingConverter
118+
enum Blah2BlubbConverter implements Converter<Blah, Blubb> {
119+
INSTANCE;
120+
121+
@Override
122+
public Blubb convert(Blah blah) {
123+
return new Blubb();
124+
}
125+
}
126+
127+
private static class Blah {}
128+
129+
private static class Blubb {}
96130
}
97131

98132
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MariaDBDataSourceConfiguration.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import java.sql.Connection;
1919
import java.sql.SQLException;
2020

21-
import javax.annotation.PostConstruct;
2221
import javax.sql.DataSource;
2322

2423
import org.mariadb.jdbc.MariaDbDataSource;
24+
import org.springframework.beans.factory.InitializingBean;
2525
import org.springframework.context.annotation.Configuration;
2626
import org.springframework.context.annotation.Profile;
2727
import org.springframework.core.io.ByteArrayResource;
@@ -33,10 +33,11 @@
3333
*
3434
* @author Christoph Preißner
3535
* @author Mark Paluch
36+
* @author Jens Schauder
3637
*/
3738
@Configuration
3839
@Profile("mariadb")
39-
class MariaDBDataSourceConfiguration extends DataSourceConfiguration {
40+
class MariaDBDataSourceConfiguration extends DataSourceConfiguration implements InitializingBean {
4041

4142
private static MariaDBContainer<?> MARIADB_CONTAINER;
4243

@@ -49,9 +50,7 @@ protected DataSource createDataSource() {
4950

5051
if (MARIADB_CONTAINER == null) {
5152

52-
MariaDBContainer<?> container = new MariaDBContainer<>("mariadb:10.5")
53-
.withUsername("root")
54-
.withPassword("")
53+
MariaDBContainer<?> container = new MariaDBContainer<>("mariadb:10.5").withUsername("root").withPassword("")
5554
.withConfigurationOverride("");
5655
container.start();
5756

@@ -70,13 +69,12 @@ protected DataSource createDataSource() {
7069
}
7170
}
7271

73-
@PostConstruct
74-
public void initDatabase() throws SQLException {
72+
@Override
73+
public void afterPropertiesSet() throws Exception {
7574

7675
try (Connection connection = createDataSource().getConnection()) {
7776
ScriptUtils.executeSqlScript(connection,
7877
new ByteArrayResource("DROP DATABASE test;CREATE DATABASE test;".getBytes()));
7978
}
8079
}
81-
8280
}

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/testing/MySqlDataSourceConfiguration.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
package org.springframework.data.jdbc.testing;
1717

1818
import java.sql.Connection;
19-
import java.sql.SQLException;
2019

21-
import javax.annotation.PostConstruct;
2220
import javax.sql.DataSource;
2321

22+
import org.springframework.beans.factory.InitializingBean;
2423
import org.springframework.context.annotation.Configuration;
2524
import org.springframework.context.annotation.Profile;
2625
import org.springframework.core.io.ByteArrayResource;
@@ -40,7 +39,7 @@
4039
*/
4140
@Configuration
4241
@Profile("mysql")
43-
class MySqlDataSourceConfiguration extends DataSourceConfiguration {
42+
class MySqlDataSourceConfiguration extends DataSourceConfiguration implements InitializingBean {
4443

4544
private static MySQLContainer<?> MYSQL_CONTAINER;
4645

@@ -53,9 +52,7 @@ protected DataSource createDataSource() {
5352

5453
if (MYSQL_CONTAINER == null) {
5554

56-
MySQLContainer<?> container = new MySQLContainer<>()
57-
.withUsername("root")
58-
.withPassword("")
55+
MySQLContainer<?> container = new MySQLContainer<>().withUsername("root").withPassword("")
5956
.withConfigurationOverride("");
6057

6158
container.start();
@@ -72,8 +69,8 @@ protected DataSource createDataSource() {
7269
return dataSource;
7370
}
7471

75-
@PostConstruct
76-
public void initDatabase() throws SQLException {
72+
@Override
73+
public void afterPropertiesSet() throws Exception {
7774

7875
try (Connection connection = createDataSource().getConnection()) {
7976
ScriptUtils.executeSqlScript(connection,

spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/BasicRelationalPersistentPropertyUnitTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.time.ZonedDateTime;
2626
import java.util.Date;
2727
import java.util.List;
28-
import java.util.UUID;
2928
import java.util.function.BiConsumer;
3029

3130
import org.assertj.core.api.SoftAssertions;
@@ -47,7 +46,6 @@ public class BasicRelationalPersistentPropertyUnitTests {
4746
RelationalMappingContext context = new RelationalMappingContext();
4847
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
4948

50-
5149
@Test // DATAJDBC-106
5250
public void detectsAnnotatedColumnName() {
5351

@@ -61,9 +59,12 @@ public void detectsAnnotatedColumnAndKeyName() {
6159

6260
RelationalPersistentProperty listProperty = entity.getRequiredPersistentProperty("someList");
6361

64-
PersistentPropertyPath<RelationalPersistentProperty> path = context.findPersistentPropertyPaths(DummyEntity.class, p -> p.getName().equals("someList")).getFirst().orElseThrow(() -> new AssertionFailedError("Couldn't find path for 'someList'"));
62+
PersistentPropertyPath<RelationalPersistentProperty> path = context
63+
.findPersistentPropertyPaths(DummyEntity.class, p -> p.getName().equals("someList")).getFirst()
64+
.orElseThrow(() -> new AssertionFailedError("Couldn't find path for 'someList'"));
6565

66-
assertThat(listProperty.getReverseColumnName(new PersistentPropertyPathExtension(context, path))).isEqualTo(quoted("dummy_column_name"));
66+
assertThat(listProperty.getReverseColumnName(new PersistentPropertyPathExtension(context, path)))
67+
.isEqualTo(quoted("dummy_column_name"));
6768
assertThat(listProperty.getKeyColumn()).isEqualTo(quoted("dummy_key_column_name"));
6869
}
6970

@@ -127,7 +128,6 @@ public void classificationOfCollectionLikeProperties() {
127128
softly.assertAll();
128129
}
129130

130-
131131
@Data
132132
@SuppressWarnings("unused")
133133
private static class DummyEntity {
@@ -136,7 +136,6 @@ private static class DummyEntity {
136136
private final SomeEnum someEnum;
137137
private final LocalDateTime localDateTime;
138138
private final ZonedDateTime zonedDateTime;
139-
private final UUID uuid;
140139

141140
// DATAJDBC-259
142141
private final List<String> listOfString;

0 commit comments

Comments
 (0)