diff --git a/src/main/java/org/springframework/data/r2dbc/dialect/PostgresDialect.java b/src/main/java/org/springframework/data/r2dbc/dialect/PostgresDialect.java index 7af45270..322e2a19 100644 --- a/src/main/java/org/springframework/data/r2dbc/dialect/PostgresDialect.java +++ b/src/main/java/org/springframework/data/r2dbc/dialect/PostgresDialect.java @@ -35,6 +35,7 @@ import org.springframework.util.ClassUtils; * An SQL dialect for Postgres. * * @author Mark Paluch + * @author Jose Luis Leon */ public class PostgresDialect extends org.springframework.data.relational.core.dialect.PostgresDialect implements R2dbcDialect { @@ -49,7 +50,8 @@ public class PostgresDialect extends org.springframework.data.relational.core.di static { - Set> simpleTypes = new HashSet<>(Arrays.asList(UUID.class, URL.class, URI.class, InetAddress.class, Map.class)); + Set> simpleTypes = new HashSet<>( + Arrays.asList(UUID.class, URL.class, URI.class, InetAddress.class, Map.class)); // conditional Postgres Geo support. Stream.of("io.r2dbc.postgresql.codec.Box", // diff --git a/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java index 6df7331c..00f06421 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java @@ -17,8 +17,6 @@ package org.springframework.data.r2dbc.repository; import static org.assertj.core.api.Assertions.*; -import java.util.Map; - import io.r2dbc.postgresql.codec.Json; import io.r2dbc.spi.ConnectionFactory; import lombok.AllArgsConstructor; @@ -26,6 +24,9 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; +import java.util.Collections; +import java.util.Map; + import javax.sql.DataSource; import org.junit.jupiter.api.Test; @@ -55,6 +56,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; * Integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory} against Postgres. * * @author Mark Paluch + * @author Jose Luis Leon */ @ExtendWith(SpringExtension.class) @ContextConfiguration @@ -62,14 +64,15 @@ public class PostgresR2dbcRepositoryIntegrationTests extends AbstractR2dbcReposi @RegisterExtension public static final ExternalDatabase database = PostgresTestSupport.database(); - @Autowired JsonPersonRepository jsonPersonRepository; + @Autowired WithJsonRepository withJsonRepository; - @Autowired HStorePersonRepository hstorePersonRepository; + @Autowired WithHStoreRepository hstoreRepositoryWith; @Configuration @EnableR2dbcRepositories(considerNestedRepositories = true, - includeFilters = @Filter(classes = { PostgresLegoSetRepository.class, JsonPersonRepository.class, - HStorePersonRepository.class }, type = FilterType.ASSIGNABLE_TYPE)) + includeFilters = @Filter( + classes = { PostgresLegoSetRepository.class, WithJsonRepository.class, WithHStoreRepository.class }, + type = FilterType.ASSIGNABLE_TYPE)) static class IntegrationTestConfiguration extends AbstractR2dbcConfiguration { @Bean @@ -136,66 +139,64 @@ public class PostgresR2dbcRepositoryIntegrationTests extends AbstractR2dbcReposi JdbcTemplate template = new JdbcTemplate(createDataSource()); - template.execute("DROP TABLE IF EXISTS json_person"); - template.execute("CREATE TABLE json_person (\n" // + template.execute("DROP TABLE IF EXISTS with_json"); + template.execute("CREATE TABLE with_json (\n" // + " id SERIAL PRIMARY KEY,\n" // + " json_value JSONB NOT NULL" // + ");"); - JsonPerson person = new JsonPerson(null, Json.of("{\"hello\": \"world\"}")); - jsonPersonRepository.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete(); + WithJson person = new WithJson(null, Json.of("{\"hello\": \"world\"}")); + withJsonRepository.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete(); - jsonPersonRepository.findAll().as(StepVerifier::create).consumeNextWith(actual -> { + withJsonRepository.findAll().as(StepVerifier::create).consumeNextWith(actual -> { assertThat(actual.jsonValue).isNotNull(); assertThat(actual.jsonValue.asString()).isEqualTo("{\"hello\": \"world\"}"); }).verifyComplete(); } - @Test + @Test // gh-492 void shouldSaveAndLoadHStore() { JdbcTemplate template = new JdbcTemplate(createDataSource()); - template.execute("DROP TABLE IF EXISTS hstore_person"); + template.execute("DROP TABLE IF EXISTS with_hstore"); template.execute("CREATE EXTENSION IF NOT EXISTS hstore;"); - template.execute("CREATE TABLE hstore_person (\n" // - + " id SERIAL PRIMARY KEY,\n" // - + " hstore_value HSTORE NOT NULL" // - + ");"); + template.execute("CREATE TABLE with_hstore (" // + + " id SERIAL PRIMARY KEY," // + + " hstore_value HSTORE NOT NULL);"); - HStorePerson person = new HStorePerson(null, Map.of("hello", "world")); - hstorePersonRepository.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete(); + WithHStore person = new WithHStore(null, Collections.singletonMap("hello", "world")); + hstoreRepositoryWith.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete(); - hstorePersonRepository.findAll().as(StepVerifier::create).consumeNextWith(actual -> { + hstoreRepositoryWith.findAll().as(StepVerifier::create).consumeNextWith(actual -> { - assertThat(actual.hstoreValue).isNotNull(); - assertThat(actual.hstoreValue).containsEntry("hello", "world"); + assertThat(actual.hstoreValue).isNotNull().containsEntry("hello", "world"); }).verifyComplete(); } @AllArgsConstructor - static class JsonPerson { + static class WithJson { @Id Long id; Json jsonValue; } - interface JsonPersonRepository extends ReactiveCrudRepository { + interface WithJsonRepository extends ReactiveCrudRepository { } @AllArgsConstructor - @Table("hstore_person") - static class HStorePerson { + @Table("with_hstore") + static class WithHStore { @Id Long id; Map hstoreValue; } - interface HStorePersonRepository extends ReactiveCrudRepository { + interface WithHStoreRepository extends ReactiveCrudRepository { } }