@@ -309,11 +309,11 @@ private MappingInfo getMappingInfo(Method method, Object handler, Class<?> handl
309
309
String typeName ;
310
310
String field ;
311
311
boolean batchMapping = false ;
312
+ int batchSize = -1 ;
312
313
HandlerMethod handlerMethod = createHandlerMethod (method , handler , handlerType );
313
314
314
315
Annotation annotation = annotations .iterator ().next ();
315
- if (annotation instanceof SchemaMapping ) {
316
- SchemaMapping mapping = (SchemaMapping ) annotation ;
316
+ if (annotation instanceof SchemaMapping mapping ) {
317
317
typeName = mapping .typeName ();
318
318
field = (StringUtils .hasText (mapping .field ()) ? mapping .field () : method .getName ());
319
319
}
@@ -322,6 +322,7 @@ private MappingInfo getMappingInfo(Method method, Object handler, Class<?> handl
322
322
typeName = mapping .typeName ();
323
323
field = (StringUtils .hasText (mapping .field ()) ? mapping .field () : method .getName ());
324
324
batchMapping = true ;
325
+ batchSize = mapping .maxBatchSize ();
325
326
}
326
327
327
328
if (!StringUtils .hasText (typeName )) {
@@ -354,7 +355,7 @@ private MappingInfo getMappingInfo(Method method, Object handler, Class<?> handl
354
355
"No parentType specified, and a source/parent method argument was also not found: " +
355
356
handlerMethod .getShortLogMessage ());
356
357
357
- return new MappingInfo (typeName , field , batchMapping , handlerMethod );
358
+ return new MappingInfo (typeName , field , batchMapping , batchSize , handlerMethod );
358
359
}
359
360
360
361
private HandlerMethod createHandlerMethod (Method method , Object handler , Class <?> handlerType ) {
@@ -394,11 +395,16 @@ private String registerBatchLoader(MappingInfo info) {
394
395
Class <?> clazz = returnType .getParameterType ();
395
396
Class <?> nestedClass = (clazz .equals (Callable .class ) ? returnType .nested ().getNestedParameterType () : clazz );
396
397
398
+ BatchLoaderRegistry .RegistrationSpec <Object , Object > registration = registry .forName (dataLoaderKey );
399
+ if (info .getMaxBatchSize () > 0 ) {
400
+ registration .withOptions (options -> options .setMaxBatchSize (info .getMaxBatchSize ()));
401
+ }
402
+
397
403
if (clazz .equals (Flux .class ) || Collection .class .isAssignableFrom (nestedClass )) {
398
- registry . forName ( dataLoaderKey ) .registerBatchLoader (invocable ::invokeForIterable );
404
+ registration .registerBatchLoader (invocable ::invokeForIterable );
399
405
}
400
406
else if (clazz .equals (Mono .class ) || nestedClass .equals (Map .class )) {
401
- registry . forName ( dataLoaderKey ) .registerMappedBatchLoader (invocable ::invokeForMap );
407
+ registration .registerMappedBatchLoader (invocable ::invokeForMap );
402
408
}
403
409
else {
404
410
throw new IllegalStateException ("@BatchMapping method is expected to return " +
@@ -434,12 +440,18 @@ private static class MappingInfo {
434
440
435
441
private final boolean batchMapping ;
436
442
443
+ private final int maxBatchSize ;
444
+
437
445
private final HandlerMethod handlerMethod ;
438
446
439
- public MappingInfo (String typeName , String field , boolean batchMapping , HandlerMethod handlerMethod ) {
447
+ public MappingInfo (
448
+ String typeName , String field , boolean batchMapping , int maxBatchSize ,
449
+ HandlerMethod handlerMethod ) {
450
+
440
451
this .coordinates = FieldCoordinates .coordinates (typeName , field );
441
- this .handlerMethod = handlerMethod ;
442
452
this .batchMapping = batchMapping ;
453
+ this .maxBatchSize = maxBatchSize ;
454
+ this .handlerMethod = handlerMethod ;
443
455
}
444
456
445
457
public FieldCoordinates getCoordinates () {
@@ -451,6 +463,10 @@ public boolean isBatchMapping() {
451
463
return this .batchMapping ;
452
464
}
453
465
466
+ public int getMaxBatchSize () {
467
+ return this .maxBatchSize ;
468
+ }
469
+
454
470
public HandlerMethod getHandlerMethod () {
455
471
return this .handlerMethod ;
456
472
}
0 commit comments