Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 63fcd73

Browse files
JoseLionmp911de
authored andcommitted
#493 - Add HStore support on Postgres dialect.
Original pull request: #493.
1 parent 1b2332e commit 63fcd73

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

‎src/main/java/org/springframework/data/r2dbc/dialect/PostgresDialect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Collections;
1212
import java.util.HashSet;
1313
import java.util.List;
14+
import java.util.Map;
1415
import java.util.Set;
1516
import java.util.UUID;
1617
import java.util.function.Consumer;
@@ -48,7 +49,7 @@ public class PostgresDialect extends org.springframework.data.relational.core.di
4849

4950
static {
5051

51-
Set<Class<?>> simpleTypes = new HashSet<>(Arrays.asList(UUID.class, URL.class, URI.class, InetAddress.class));
52+
Set<Class<?>> simpleTypes = new HashSet<>(Arrays.asList(UUID.class, URL.class, URI.class, InetAddress.class, Map.class));
5253

5354
// conditional Postgres Geo support.
5455
Stream.of("io.r2dbc.postgresql.codec.Box", //
@@ -307,5 +308,4 @@ public byte[] convert(Json source) {
307308
return source.asArray();
308309
}
309310
}
310-
311311
}

‎src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryIntegrationTests.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20+
import java.util.Map;
21+
2022
import io.r2dbc.postgresql.codec.Json;
2123
import io.r2dbc.spi.ConnectionFactory;
2224
import lombok.AllArgsConstructor;
@@ -42,6 +44,7 @@
4244
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
4345
import org.springframework.data.r2dbc.testing.ExternalDatabase;
4446
import org.springframework.data.r2dbc.testing.PostgresTestSupport;
47+
import org.springframework.data.relational.core.mapping.Table;
4548
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
4649
import org.springframework.jdbc.core.JdbcTemplate;
4750
import org.springframework.r2dbc.core.DatabaseClient;
@@ -61,10 +64,12 @@ public class PostgresR2dbcRepositoryIntegrationTests extends AbstractR2dbcReposi
6164

6265
@Autowired JsonPersonRepository jsonPersonRepository;
6366

67+
@Autowired HStorePersonRepository hstorePersonRepository;
68+
6469
@Configuration
6570
@EnableR2dbcRepositories(considerNestedRepositories = true,
66-
includeFilters = @Filter(classes = { PostgresLegoSetRepository.class, JsonPersonRepository.class },
67-
type = FilterType.ASSIGNABLE_TYPE))
71+
includeFilters = @Filter(classes = { PostgresLegoSetRepository.class, JsonPersonRepository.class,
72+
HStorePersonRepository.class }, type = FilterType.ASSIGNABLE_TYPE))
6873
static class IntegrationTestConfiguration extends AbstractR2dbcConfiguration {
6974

7075
@Bean
@@ -147,6 +152,28 @@ void shouldSaveAndLoadJson() {
147152
}).verifyComplete();
148153
}
149154

155+
@Test
156+
void shouldSaveAndLoadHStore() {
157+
158+
JdbcTemplate template = new JdbcTemplate(createDataSource());
159+
160+
template.execute("DROP TABLE IF EXISTS hstore_person");
161+
template.execute("CREATE EXTENSION IF NOT EXISTS hstore;");
162+
template.execute("CREATE TABLE hstore_person (\n" //
163+
+ " id SERIAL PRIMARY KEY,\n" //
164+
+ " hstore_value HSTORE NOT NULL" //
165+
+ ");");
166+
167+
HStorePerson person = new HStorePerson(null, Map.of("hello", "world"));
168+
hstorePersonRepository.save(person).as(StepVerifier::create).expectNextCount(1).verifyComplete();
169+
170+
hstorePersonRepository.findAll().as(StepVerifier::create).consumeNextWith(actual -> {
171+
172+
assertThat(actual.hstoreValue).isNotNull();
173+
assertThat(actual.hstoreValue).containsEntry("hello", "world");
174+
}).verifyComplete();
175+
}
176+
150177
@AllArgsConstructor
151178
static class JsonPerson {
152179

@@ -158,4 +185,17 @@ static class JsonPerson {
158185
interface JsonPersonRepository extends ReactiveCrudRepository<JsonPerson, Long> {
159186

160187
}
188+
189+
@AllArgsConstructor
190+
@Table("hstore_person")
191+
static class HStorePerson {
192+
193+
@Id Long id;
194+
195+
Map<String, String> hstoreValue;
196+
}
197+
198+
interface HStorePersonRepository extends ReactiveCrudRepository<HStorePerson, Long> {
199+
200+
}
161201
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /