@@ -309,11 +309,11 @@ private MappingInfo getMappingInfo(Method method, Object handler, Class<?> handl
309309 String typeName ;
310310 String field ;
311311 boolean batchMapping = false ;
312+ int batchSize = -1 ;
312313 HandlerMethod handlerMethod = createHandlerMethod (method , handler , handlerType );
313314
314315 Annotation annotation = annotations .iterator ().next ();
315- if (annotation instanceof SchemaMapping ) {
316- SchemaMapping mapping = (SchemaMapping ) annotation ;
316+ if (annotation instanceof SchemaMapping mapping ) {
317317 typeName = mapping .typeName ();
318318 field = (StringUtils .hasText (mapping .field ()) ? mapping .field () : method .getName ());
319319 }
@@ -322,6 +322,7 @@ private MappingInfo getMappingInfo(Method method, Object handler, Class<?> handl
322322 typeName = mapping .typeName ();
323323 field = (StringUtils .hasText (mapping .field ()) ? mapping .field () : method .getName ());
324324 batchMapping = true ;
325+ batchSize = mapping .maxBatchSize ();
325326 }
326327
327328 if (!StringUtils .hasText (typeName )) {
@@ -354,7 +355,7 @@ private MappingInfo getMappingInfo(Method method, Object handler, Class<?> handl
354355 "No parentType specified, and a source/parent method argument was also not found: " +
355356 handlerMethod .getShortLogMessage ());
356357
357- return new MappingInfo (typeName , field , batchMapping , handlerMethod );
358+ return new MappingInfo (typeName , field , batchMapping , batchSize , handlerMethod );
358359 }
359360
360361 private HandlerMethod createHandlerMethod (Method method , Object handler , Class <?> handlerType ) {
@@ -394,11 +395,16 @@ private String registerBatchLoader(MappingInfo info) {
394395 Class <?> clazz = returnType .getParameterType ();
395396 Class <?> nestedClass = (clazz .equals (Callable .class ) ? returnType .nested ().getNestedParameterType () : clazz );
396397
398+ BatchLoaderRegistry .RegistrationSpec <Object , Object > registration = registry .forName (dataLoaderKey );
399+ if (info .getMaxBatchSize () > 0 ) {
400+ registration .withOptions (options -> options .setMaxBatchSize (info .getMaxBatchSize ()));
401+ }
402+
397403 if (clazz .equals (Flux .class ) || Collection .class .isAssignableFrom (nestedClass )) {
398- registry . forName ( dataLoaderKey ) .registerBatchLoader (invocable ::invokeForIterable );
404+ registration .registerBatchLoader (invocable ::invokeForIterable );
399405 }
400406 else if (clazz .equals (Mono .class ) || nestedClass .equals (Map .class )) {
401- registry . forName ( dataLoaderKey ) .registerMappedBatchLoader (invocable ::invokeForMap );
407+ registration .registerMappedBatchLoader (invocable ::invokeForMap );
402408 }
403409 else {
404410 throw new IllegalStateException ("@BatchMapping method is expected to return " +
@@ -434,12 +440,18 @@ private static class MappingInfo {
434440
435441 private final boolean batchMapping ;
436442
443+ private final int maxBatchSize ;
444+
437445 private final HandlerMethod handlerMethod ;
438446
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+
440451 this .coordinates = FieldCoordinates .coordinates (typeName , field );
441- this .handlerMethod = handlerMethod ;
442452 this .batchMapping = batchMapping ;
453+ this .maxBatchSize = maxBatchSize ;
454+ this .handlerMethod = handlerMethod ;
443455 }
444456
445457 public FieldCoordinates getCoordinates () {
@@ -451,6 +463,10 @@ public boolean isBatchMapping() {
451463 return this .batchMapping ;
452464 }
453465
466+ public int getMaxBatchSize () {
467+ return this .maxBatchSize ;
468+ }
469+
454470 public HandlerMethod getHandlerMethod () {
455471 return this .handlerMethod ;
456472 }
0 commit comments