17
17
18
18
import static org .assertj .core .api .Assertions .*;
19
19
20
+ import java .util .Map ;
21
+
20
22
import io .r2dbc .postgresql .codec .Json ;
21
23
import io .r2dbc .spi .ConnectionFactory ;
22
24
import lombok .AllArgsConstructor ;
42
44
import org .springframework .data .r2dbc .repository .support .R2dbcRepositoryFactory ;
43
45
import org .springframework .data .r2dbc .testing .ExternalDatabase ;
44
46
import org .springframework .data .r2dbc .testing .PostgresTestSupport ;
47
+ import org .springframework .data .relational .core .mapping .Table ;
45
48
import org .springframework .data .repository .reactive .ReactiveCrudRepository ;
46
49
import org .springframework .jdbc .core .JdbcTemplate ;
47
50
import org .springframework .r2dbc .core .DatabaseClient ;
@@ -61,10 +64,12 @@ public class PostgresR2dbcRepositoryIntegrationTests extends AbstractR2dbcReposi
61
64
62
65
@ Autowired JsonPersonRepository jsonPersonRepository ;
63
66
67
+ @ Autowired HStorePersonRepository hstorePersonRepository ;
68
+
64
69
@ Configuration
65
70
@ 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 ))
68
73
static class IntegrationTestConfiguration extends AbstractR2dbcConfiguration {
69
74
70
75
@ Bean
@@ -147,6 +152,28 @@ void shouldSaveAndLoadJson() {
147
152
}).verifyComplete ();
148
153
}
149
154
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
+
150
177
@ AllArgsConstructor
151
178
static class JsonPerson {
152
179
@@ -158,4 +185,17 @@ static class JsonPerson {
158
185
interface JsonPersonRepository extends ReactiveCrudRepository <JsonPerson , Long > {
159
186
160
187
}
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
+ }
161
201
}
0 commit comments