22
22
import java .sql .JDBCType ;
23
23
import java .sql .ResultSet ;
24
24
import java .util .ArrayList ;
25
+ import java .util .Iterator ;
25
26
import java .util .List ;
26
27
import java .util .Properties ;
27
28
import java .util .Set ;
28
29
import java .util .stream .Stream ;
29
30
30
31
import org .assertj .core .api .Assertions ;
32
+ import org .jetbrains .annotations .NotNull ;
31
33
import org .junit .jupiter .api .BeforeEach ;
32
34
import org .junit .jupiter .api .Test ;
33
35
import org .mockito .ArgumentCaptor ;
@@ -211,7 +213,6 @@ void convertsEnumCollectionParameterUsingCustomConverterWhenRegisteredForType()
211
213
assertThat (sqlParameterSource .getValue ("directions" )).asList ().containsExactlyInAnyOrder (-1 , 1 );
212
214
}
213
215
214
-
215
216
@ Test // GH-1212
216
217
void doesNotConvertNonCollectionParameter () {
217
218
@@ -222,6 +223,18 @@ void doesNotConvertNonCollectionParameter() {
222
223
assertThat (sqlParameterSource .getValue ("value" )).isEqualTo (1 );
223
224
}
224
225
226
+ @ Test // GH-1343
227
+ void appliesConverterToIterable () {
228
+
229
+ SqlParameterSource sqlParameterSource = forMethod ("findByListContainer" , ListContainer .class ) //
230
+ .withCustomConverters (ListContainerToStringConverter .INSTANCE )
231
+ .withArguments (new ListContainer ("one" , "two" , "three" )) //
232
+ .extractParameterSource ();
233
+
234
+ assertThat (sqlParameterSource .getValue ("value" )).isEqualTo ("one" );
235
+
236
+ }
237
+
225
238
QueryFixture forMethod (String name , Class ... paramTypes ) {
226
239
return new QueryFixture (createMethod (name , paramTypes ));
227
240
}
@@ -321,6 +334,9 @@ interface MyRepository extends Repository<Object, Long> {
321
334
@ Query (value = "some sql statement" )
322
335
List <Object > findBySimpleValue (Integer value );
323
336
337
+ @ Query (value = "some sql statement" )
338
+ List <Object > findByListContainer (ListContainer value );
339
+
324
340
@ Query ("SELECT * FROM table WHERE c = :#{myext.testValue} AND c2 = :#{myext.doSomething()}" )
325
341
Object findBySpelExpression (Object object );
326
342
}
@@ -417,6 +433,32 @@ public Direction convert(Integer source) {
417
433
}
418
434
}
419
435
436
+ static class ListContainer implements Iterable <String > {
437
+
438
+ private final List <String > values ;
439
+
440
+ ListContainer (String ... values ) {
441
+ this .values = List .of (values );
442
+ }
443
+
444
+ @ NotNull
445
+ @ Override
446
+ public Iterator <String > iterator () {
447
+ return values .iterator ();
448
+ }
449
+ }
450
+
451
+ @ WritingConverter
452
+ enum ListContainerToStringConverter implements Converter <ListContainer , String > {
453
+
454
+ INSTANCE ;
455
+
456
+ @ Override
457
+ public String convert (ListContainer source ) {
458
+ return source .values .get (0 );
459
+ }
460
+ }
461
+
420
462
private static class DummyEntity {
421
463
private Long id ;
422
464
0 commit comments