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
This commit is contained in:
committed by
Mark Paluch
parent
d6b325746a
commit
dfaaa51a34
@@ -46,6 +46,7 @@ public class JdbcMappingContext extends RelationalMappingContext {
|
||||
*/
|
||||
public JdbcMappingContext() {
|
||||
super();
|
||||
setSimpleTypeHolder(JdbcSimpleTypes.HOLDER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,6 +56,7 @@ public class JdbcMappingContext extends RelationalMappingContext {
|
||||
*/
|
||||
public JdbcMappingContext(NamingStrategy namingStrategy) {
|
||||
super(namingStrategy);
|
||||
setSimpleTypeHolder(JdbcSimpleTypes.HOLDER);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -27,6 +28,8 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
import org.springframework.data.jdbc.core.JdbcAggregateTemplate;
|
||||
import org.springframework.data.jdbc.core.convert.DataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.convert.JdbcConverter;
|
||||
@@ -46,7 +49,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
public class AbstractJdbcConfigurationIntegrationTests {
|
||||
|
||||
@Test // DATAJDBC-395
|
||||
public void configuresInfrastructureComponents() {
|
||||
void configuresInfrastructureComponents() {
|
||||
|
||||
assertApplicationContext(context -> {
|
||||
|
||||
@@ -63,6 +66,18 @@ public class AbstractJdbcConfigurationIntegrationTests {
|
||||
}, AbstractJdbcConfigurationUnderTest.class, Infrastructure.class);
|
||||
}
|
||||
|
||||
@Test // #975
|
||||
void registersSimpleTypesFromCustomConversions() {
|
||||
|
||||
assertApplicationContext(context -> {
|
||||
JdbcMappingContext mappingContext = context.getBean(JdbcMappingContext.class);
|
||||
assertThat( //
|
||||
mappingContext.getPersistentEntity(AbstractJdbcConfigurationUnderTest.Blah.class) //
|
||||
).describedAs("Blah should not be an entity, since there is a WritingConversion configured for it") //
|
||||
.isNull();
|
||||
}, AbstractJdbcConfigurationUnderTest.class, Infrastructure.class);
|
||||
}
|
||||
|
||||
protected static void assertApplicationContext(Consumer<ConfigurableApplicationContext> verification,
|
||||
Class<?>... configurationClasses) {
|
||||
|
||||
@@ -93,6 +108,25 @@ public class AbstractJdbcConfigurationIntegrationTests {
|
||||
public Dialect jdbcDialect(NamedParameterJdbcOperations operations) {
|
||||
return HsqlDbDialect.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JdbcCustomConversions jdbcCustomConversions() {
|
||||
return new JdbcCustomConversions(Collections.singletonList(Blah2BlubbConverter.INSTANCE));
|
||||
}
|
||||
|
||||
@WritingConverter
|
||||
enum Blah2BlubbConverter implements Converter<Blah, Blubb> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public Blubb convert(Blah blah) {
|
||||
return new Blubb();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Blah {}
|
||||
|
||||
private static class Blubb {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ package org.springframework.data.jdbc.testing;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.mariadb.jdbc.MariaDbDataSource;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
@@ -33,10 +33,11 @@ import org.testcontainers.containers.MariaDBContainer;
|
||||
*
|
||||
* @author Christoph Preißner
|
||||
* @author Mark Paluch
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@Configuration
|
||||
@Profile("mariadb")
|
||||
class MariaDBDataSourceConfiguration extends DataSourceConfiguration {
|
||||
class MariaDBDataSourceConfiguration extends DataSourceConfiguration implements InitializingBean {
|
||||
|
||||
private static MariaDBContainer<?> MARIADB_CONTAINER;
|
||||
|
||||
@@ -49,9 +50,7 @@ class MariaDBDataSourceConfiguration extends DataSourceConfiguration {
|
||||
|
||||
if (MARIADB_CONTAINER == null) {
|
||||
|
||||
MariaDBContainer<?> container = new MariaDBContainer<>("mariadb:10.5")
|
||||
.withUsername("root")
|
||||
.withPassword("")
|
||||
MariaDBContainer<?> container = new MariaDBContainer<>("mariadb:10.5").withUsername("root").withPassword("")
|
||||
.withConfigurationOverride("");
|
||||
container.start();
|
||||
|
||||
@@ -70,13 +69,12 @@ class MariaDBDataSourceConfiguration extends DataSourceConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initDatabase() throws SQLException {
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
try (Connection connection = createDataSource().getConnection()) {
|
||||
ScriptUtils.executeSqlScript(connection,
|
||||
new ByteArrayResource("DROP DATABASE test;CREATE DATABASE test;".getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
package org.springframework.data.jdbc.testing;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.jdbc.datasource.init.ScriptUtils;
|
||||
import org.testcontainers.containers.MySQLContainer;
|
||||
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
|
||||
/**
|
||||
* {@link DataSource} setup for MySQL. Starts a docker container with a MySql database and sets up a database name
|
||||
* "test" in it.
|
||||
@@ -39,7 +39,7 @@ import org.testcontainers.containers.MySQLContainer;
|
||||
*/
|
||||
@Configuration
|
||||
@Profile("mysql")
|
||||
class MySqlDataSourceConfiguration extends DataSourceConfiguration {
|
||||
class MySqlDataSourceConfiguration extends DataSourceConfiguration implements InitializingBean {
|
||||
|
||||
private static MySQLContainer<?> MYSQL_CONTAINER;
|
||||
|
||||
@@ -52,9 +52,7 @@ class MySqlDataSourceConfiguration extends DataSourceConfiguration {
|
||||
|
||||
if (MYSQL_CONTAINER == null) {
|
||||
|
||||
MySQLContainer<?> container = new MySQLContainer<>("mysql:8.0.24")
|
||||
.withUsername("test")
|
||||
.withPassword("test")
|
||||
MySQLContainer<?> container = new MySQLContainer<>("mysql:8.0.24").withUsername("test").withPassword("test")
|
||||
.withConfigurationOverride("");
|
||||
|
||||
container.start();
|
||||
@@ -71,8 +69,8 @@ class MySqlDataSourceConfiguration extends DataSourceConfiguration {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initDatabase() throws SQLException {
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
try (Connection connection = createDataSource().getConnection()) {
|
||||
ScriptUtils.executeSqlScript(connection,
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.assertj.core.api.SoftAssertions;
|
||||
@@ -47,7 +46,6 @@ public class BasicRelationalPersistentPropertyUnitTests {
|
||||
RelationalMappingContext context = new RelationalMappingContext();
|
||||
RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(DummyEntity.class);
|
||||
|
||||
|
||||
@Test // DATAJDBC-106
|
||||
public void detectsAnnotatedColumnName() {
|
||||
|
||||
@@ -61,9 +59,12 @@ public class BasicRelationalPersistentPropertyUnitTests {
|
||||
|
||||
RelationalPersistentProperty listProperty = entity.getRequiredPersistentProperty("someList");
|
||||
|
||||
PersistentPropertyPath<RelationalPersistentProperty> path = context.findPersistentPropertyPaths(DummyEntity.class, p -> p.getName().equals("someList")).getFirst().orElseThrow(() -> new AssertionFailedError("Couldn't find path for 'someList'"));
|
||||
PersistentPropertyPath<RelationalPersistentProperty> path = context
|
||||
.findPersistentPropertyPaths(DummyEntity.class, p -> p.getName().equals("someList")).getFirst()
|
||||
.orElseThrow(() -> new AssertionFailedError("Couldn't find path for 'someList'"));
|
||||
|
||||
assertThat(listProperty.getReverseColumnName(new PersistentPropertyPathExtension(context, path))).isEqualTo(quoted("dummy_column_name"));
|
||||
assertThat(listProperty.getReverseColumnName(new PersistentPropertyPathExtension(context, path)))
|
||||
.isEqualTo(quoted("dummy_column_name"));
|
||||
assertThat(listProperty.getKeyColumn()).isEqualTo(quoted("dummy_key_column_name"));
|
||||
}
|
||||
|
||||
@@ -127,7 +128,6 @@ public class BasicRelationalPersistentPropertyUnitTests {
|
||||
softly.assertAll();
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
@SuppressWarnings("unused")
|
||||
private static class DummyEntity {
|
||||
@@ -136,7 +136,6 @@ public class BasicRelationalPersistentPropertyUnitTests {
|
||||
private final SomeEnum someEnum;
|
||||
private final LocalDateTime localDateTime;
|
||||
private final ZonedDateTime zonedDateTime;
|
||||
private final UUID uuid;
|
||||
|
||||
// DATAJDBC-259
|
||||
private final List<String> listOfString;
|
||||
|
||||
Reference in New Issue
Block a user