33import org .dataloader .annotations .PublicApi ;
44import org .jspecify .annotations .Nullable ;
55
6+ import static org .dataloader .impl .Assertions .nonNull ;
7+
68/**
79 * A factory class to create {@link DataLoader}s
810 */
@@ -23,6 +25,20 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadF
2325 return newDataLoader (batchLoadFunction , null );
2426 }
2527
28+ /**
29+ * Creates new DataLoader with the specified batch loader function and default options
30+ * (batching, caching and unlimited batch size).
31+ *
32+ * @param name the name to use
33+ * @param batchLoadFunction the batch load function to use
34+ * @param <K> the key type
35+ * @param <V> the value type
36+ * @return a new DataLoader
37+ */
38+ public static <K , V > DataLoader <K , V > newDataLoader (String name , BatchLoader <K , V > batchLoadFunction ) {
39+ return newDataLoader (name , batchLoadFunction , null );
40+ }
41+
2642 /**
2743 * Creates new DataLoader with the specified batch loader function with the provided options
2844 *
@@ -46,8 +62,8 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadF
4662 * @param <V> the value type
4763 * @return a new DataLoader
4864 */
49- public static <K , V > DataLoader <K , V > newDataLoader (@ Nullable String name , BatchLoader <K , V > batchLoadFunction , DataLoaderOptions options ) {
50- return mkDataLoader (name , batchLoadFunction , options );
65+ public static <K , V > DataLoader <K , V > newDataLoader (String name , BatchLoader <K , V > batchLoadFunction , DataLoaderOptions options ) {
66+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
5167 }
5268
5369 /**
@@ -99,8 +115,8 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>
99115 * @return a new DataLoader
100116 * @see #newDataLoaderWithTry(BatchLoader)
101117 */
102- public static <K , V > DataLoader <K , V > newDataLoaderWithTry (@ Nullable String name , BatchLoader <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
103- return mkDataLoader (name , batchLoadFunction , options );
118+ public static <K , V > DataLoader <K , V > newDataLoaderWithTry (String name , BatchLoader <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
119+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
104120 }
105121
106122 /**
@@ -139,8 +155,8 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V>
139155 * @param <V> the value type
140156 * @return a new DataLoader
141157 */
142- public static <K , V > DataLoader <K , V > newDataLoader (@ Nullable String name , BatchLoaderWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
143- return mkDataLoader (name , batchLoadFunction , options );
158+ public static <K , V > DataLoader <K , V > newDataLoader (String name , BatchLoaderWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
159+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
144160 }
145161
146162 /**
@@ -192,8 +208,8 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContex
192208 * @return a new DataLoader
193209 * @see #newDataLoaderWithTry(BatchLoader)
194210 */
195- public static <K , V > DataLoader <K , V > newDataLoaderWithTry (@ Nullable String name , BatchLoaderWithContext <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
196- return mkDataLoader (name , batchLoadFunction , options );
211+ public static <K , V > DataLoader <K , V > newDataLoaderWithTry (String name , BatchLoaderWithContext <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
212+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
197213 }
198214
199215 /**
@@ -231,8 +247,8 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V
231247 * @param <V> the value type
232248 * @return a new DataLoader
233249 */
234- public static <K , V > DataLoader <K , V > newMappedDataLoader (@ Nullable String name , MappedBatchLoader <K , V > batchLoadFunction , @ Nullable DataLoaderOptions options ) {
235- return mkDataLoader (name , batchLoadFunction , options );
250+ public static <K , V > DataLoader <K , V > newMappedDataLoader (String name , MappedBatchLoader <K , V > batchLoadFunction , @ Nullable DataLoaderOptions options ) {
251+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
236252 }
237253
238254 /**
@@ -285,8 +301,8 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
285301 * @return a new DataLoader
286302 * @see #newDataLoaderWithTry(BatchLoader)
287303 */
288- public static <K , V > DataLoader <K , V > newMappedDataLoaderWithTry (@ Nullable String name , MappedBatchLoader <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
289- return mkDataLoader (name , batchLoadFunction , options );
304+ public static <K , V > DataLoader <K , V > newMappedDataLoaderWithTry (String name , MappedBatchLoader <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
305+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
290306 }
291307
292308 /**
@@ -325,8 +341,8 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithC
325341 * @param <V> the value type
326342 * @return a new DataLoader
327343 */
328- public static <K , V > DataLoader <K , V > newMappedDataLoader (@ Nullable String name , MappedBatchLoaderWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
329- return mkDataLoader (name , batchLoadFunction , options );
344+ public static <K , V > DataLoader <K , V > newMappedDataLoader (String name , MappedBatchLoaderWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
345+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
330346 }
331347
332348 /**
@@ -378,8 +394,8 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
378394 * @return a new DataLoader
379395 * @see #newDataLoaderWithTry(BatchLoader)
380396 */
381- public static <K , V > DataLoader <K , V > newMappedDataLoaderWithTry (@ Nullable String name , MappedBatchLoaderWithContext <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
382- return mkDataLoader (name , batchLoadFunction , options );
397+ public static <K , V > DataLoader <K , V > newMappedDataLoaderWithTry (String name , MappedBatchLoaderWithContext <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
398+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
383399 }
384400
385401 /**
@@ -418,8 +434,8 @@ public static <K, V> DataLoader<K, V> newPublisherDataLoader(BatchPublisher<K, V
418434 * @param <V> the value type
419435 * @return a new DataLoader
420436 */
421- public static <K , V > DataLoader <K , V > newPublisherDataLoader (@ Nullable String name , BatchPublisher <K , V > batchLoadFunction , DataLoaderOptions options ) {
422- return mkDataLoader (name , batchLoadFunction , options );
437+ public static <K , V > DataLoader <K , V > newPublisherDataLoader (String name , BatchPublisher <K , V > batchLoadFunction , DataLoaderOptions options ) {
438+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
423439 }
424440
425441 /**
@@ -471,8 +487,8 @@ public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(BatchPublish
471487 * @return a new DataLoader
472488 * @see #newDataLoaderWithTry(BatchLoader)
473489 */
474- public static <K , V > DataLoader <K , V > newPublisherDataLoaderWithTry (@ Nullable String name , BatchPublisher <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
475- return mkDataLoader (name , batchLoadFunction , options );
490+ public static <K , V > DataLoader <K , V > newPublisherDataLoaderWithTry (String name , BatchPublisher <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
491+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
476492 }
477493
478494 /**
@@ -511,8 +527,8 @@ public static <K, V> DataLoader<K, V> newPublisherDataLoader(BatchPublisherWithC
511527 * @param <V> the value type
512528 * @return a new DataLoader
513529 */
514- public static <K , V > DataLoader <K , V > newPublisherDataLoader (@ Nullable String name , BatchPublisherWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
515- return mkDataLoader (name , batchLoadFunction , options );
530+ public static <K , V > DataLoader <K , V > newPublisherDataLoader (String name , BatchPublisherWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
531+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
516532 }
517533
518534 /**
@@ -564,8 +580,8 @@ public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(BatchPublish
564580 * @return a new DataLoader
565581 * @see #newPublisherDataLoaderWithTry(BatchPublisher)
566582 */
567- public static <K , V > DataLoader <K , V > newPublisherDataLoaderWithTry (@ Nullable String name , BatchPublisherWithContext <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
568- return mkDataLoader (name , batchLoadFunction , options );
583+ public static <K , V > DataLoader <K , V > newPublisherDataLoaderWithTry (String name , BatchPublisherWithContext <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
584+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
569585 }
570586
571587 /**
@@ -604,8 +620,8 @@ public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedBatchPu
604620 * @param <V> the value type
605621 * @return a new DataLoader
606622 */
607- public static <K , V > DataLoader <K , V > newMappedPublisherDataLoader (@ Nullable String name , MappedBatchPublisher <K , V > batchLoadFunction , DataLoaderOptions options ) {
608- return mkDataLoader (name , batchLoadFunction , options );
623+ public static <K , V > DataLoader <K , V > newMappedPublisherDataLoader (String name , MappedBatchPublisher <K , V > batchLoadFunction , DataLoaderOptions options ) {
624+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
609625 }
610626
611627 /**
@@ -657,8 +673,8 @@ public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(Mapped
657673 * @return a new DataLoader
658674 * @see #newDataLoaderWithTry(BatchLoader)
659675 */
660- public static <K , V > DataLoader <K , V > newMappedPublisherDataLoaderWithTry (@ Nullable String name , MappedBatchPublisher <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
661- return mkDataLoader (name , batchLoadFunction , options );
676+ public static <K , V > DataLoader <K , V > newMappedPublisherDataLoaderWithTry (String name , MappedBatchPublisher <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
677+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
662678 }
663679
664680 /**
@@ -697,8 +713,8 @@ public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedBatchPu
697713 * @param <V> the value type
698714 * @return a new DataLoader
699715 */
700- public static <K , V > DataLoader <K , V > newMappedPublisherDataLoader (@ Nullable String name , MappedBatchPublisherWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
701- return mkDataLoader (name , batchLoadFunction , options );
716+ public static <K , V > DataLoader <K , V > newMappedPublisherDataLoader (String name , MappedBatchPublisherWithContext <K , V > batchLoadFunction , DataLoaderOptions options ) {
717+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
702718 }
703719
704720 /**
@@ -750,11 +766,11 @@ public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(Mapped
750766 * @return a new DataLoader
751767 * @see #newMappedPublisherDataLoaderWithTry(MappedBatchPublisher)
752768 */
753- public static <K , V > DataLoader <K , V > newMappedPublisherDataLoaderWithTry (@ Nullable String name , MappedBatchPublisherWithContext <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
754- return mkDataLoader (name , batchLoadFunction , options );
769+ public static <K , V > DataLoader <K , V > newMappedPublisherDataLoaderWithTry (String name , MappedBatchPublisherWithContext <K , Try <V >> batchLoadFunction , DataLoaderOptions options ) {
770+ return mkDataLoader (nonNull ( name ) , batchLoadFunction , options );
755771 }
756772
757- static <K , V > DataLoader <K , V > mkDataLoader (@ Nullable String name , Object batchLoadFunction , DataLoaderOptions options ) {
773+ static <K , V > DataLoader <K , V > mkDataLoader (@ Nullable String name , Object batchLoadFunction , @ Nullable DataLoaderOptions options ) {
758774 return new DataLoader <>(name , batchLoadFunction , options );
759775 }
760776
0 commit comments