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 6fc78d42..7af45270 100644 --- a/src/main/java/org/springframework/data/r2dbc/dialect/PostgresDialect.java +++ b/src/main/java/org/springframework/data/r2dbc/dialect/PostgresDialect.java @@ -11,6 +11,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.function.Consumer; @@ -48,7 +49,7 @@ 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)); + 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", // @@ -307,5 +308,4 @@ public class PostgresDialect extends org.springframework.data.relational.core.di return source.asArray(); } } - } 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 dcb52de9..6df7331c 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java @@ -17,6 +17,8 @@ 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; @@ -42,6 +44,7 @@ import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory; import org.springframework.data.r2dbc.testing.ExternalDatabase; import org.springframework.data.r2dbc.testing.PostgresTestSupport; +import org.springframework.data.relational.core.mapping.Table; import org.springframework.data.repository.reactive.ReactiveCrudRepository; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.r2dbc.core.DatabaseClient; @@ -61,10 +64,12 @@ public class PostgresR2dbcRepositoryIntegrationTests extends AbstractR2dbcReposi @Autowired JsonPersonRepository jsonPersonRepository; + @Autowired HStorePersonRepository hstorePersonRepository; + @Configuration @EnableR2dbcRepositories(considerNestedRepositories = true, - includeFilters = @Filter(classes = { PostgresLegoSetRepository.class, JsonPersonRepository.class }, - type = FilterType.ASSIGNABLE_TYPE)) + includeFilters = @Filter(classes = { PostgresLegoSetRepository.class, JsonPersonRepository.class, + HStorePersonRepository.class }, type = FilterType.ASSIGNABLE_TYPE)) static class IntegrationTestConfiguration extends AbstractR2dbcConfiguration { @Bean @@ -147,6 +152,28 @@ public class PostgresR2dbcRepositoryIntegrationTests extends AbstractR2dbcReposi }).verifyComplete(); } + @Test + void shouldSaveAndLoadHStore() { + + JdbcTemplate template = new JdbcTemplate(createDataSource()); + + template.execute("DROP TABLE IF EXISTS hstore_person"); + 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" // + + ");"); + + HStorePerson person = new HStorePerson(null, Map.of("hello", "world")); + hstorePersonRepository.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete(); + + hstorePersonRepository.findAll().as(StepVerifier::create).consumeNextWith(actual -> { + + assertThat(actual.hstoreValue).isNotNull(); + assertThat(actual.hstoreValue).containsEntry("hello", "world"); + }).verifyComplete(); + } + @AllArgsConstructor static class JsonPerson { @@ -158,4 +185,17 @@ public class PostgresR2dbcRepositoryIntegrationTests extends AbstractR2dbcReposi interface JsonPersonRepository extends ReactiveCrudRepository { } + + @AllArgsConstructor + @Table("hstore_person") + static class HStorePerson { + + @Id Long id; + + Map hstoreValue; + } + + interface HStorePersonRepository extends ReactiveCrudRepository { + + } }