3
3
import org .dataloader .annotations .PublicApi ;
4
4
import org .jspecify .annotations .Nullable ;
5
5
6
+ import static org .dataloader .impl .Assertions .nonNull ;
7
+
6
8
/**
7
9
* A factory class to create {@link DataLoader}s
8
10
*/
@@ -23,6 +25,20 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadF
23
25
return newDataLoader (batchLoadFunction , null );
24
26
}
25
27
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
+
26
42
/**
27
43
* Creates new DataLoader with the specified batch loader function with the provided options
28
44
*
@@ -46,8 +62,8 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoader<K, V> batchLoadF
46
62
* @param <V> the value type
47
63
* @return a new DataLoader
48
64
*/
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 );
51
67
}
52
68
53
69
/**
@@ -99,8 +115,8 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoader<K, Try<V>
99
115
* @return a new DataLoader
100
116
* @see #newDataLoaderWithTry(BatchLoader)
101
117
*/
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 );
104
120
}
105
121
106
122
/**
@@ -139,8 +155,8 @@ public static <K, V> DataLoader<K, V> newDataLoader(BatchLoaderWithContext<K, V>
139
155
* @param <V> the value type
140
156
* @return a new DataLoader
141
157
*/
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 );
144
160
}
145
161
146
162
/**
@@ -192,8 +208,8 @@ public static <K, V> DataLoader<K, V> newDataLoaderWithTry(BatchLoaderWithContex
192
208
* @return a new DataLoader
193
209
* @see #newDataLoaderWithTry(BatchLoader)
194
210
*/
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 );
197
213
}
198
214
199
215
/**
@@ -231,8 +247,8 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoader<K, V
231
247
* @param <V> the value type
232
248
* @return a new DataLoader
233
249
*/
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 );
236
252
}
237
253
238
254
/**
@@ -285,8 +301,8 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
285
301
* @return a new DataLoader
286
302
* @see #newDataLoaderWithTry(BatchLoader)
287
303
*/
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 );
290
306
}
291
307
292
308
/**
@@ -325,8 +341,8 @@ public static <K, V> DataLoader<K, V> newMappedDataLoader(MappedBatchLoaderWithC
325
341
* @param <V> the value type
326
342
* @return a new DataLoader
327
343
*/
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 );
330
346
}
331
347
332
348
/**
@@ -378,8 +394,8 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
378
394
* @return a new DataLoader
379
395
* @see #newDataLoaderWithTry(BatchLoader)
380
396
*/
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 );
383
399
}
384
400
385
401
/**
@@ -418,8 +434,8 @@ public static <K, V> DataLoader<K, V> newPublisherDataLoader(BatchPublisher<K, V
418
434
* @param <V> the value type
419
435
* @return a new DataLoader
420
436
*/
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 );
423
439
}
424
440
425
441
/**
@@ -471,8 +487,8 @@ public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(BatchPublish
471
487
* @return a new DataLoader
472
488
* @see #newDataLoaderWithTry(BatchLoader)
473
489
*/
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 );
476
492
}
477
493
478
494
/**
@@ -511,8 +527,8 @@ public static <K, V> DataLoader<K, V> newPublisherDataLoader(BatchPublisherWithC
511
527
* @param <V> the value type
512
528
* @return a new DataLoader
513
529
*/
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 );
516
532
}
517
533
518
534
/**
@@ -564,8 +580,8 @@ public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(BatchPublish
564
580
* @return a new DataLoader
565
581
* @see #newPublisherDataLoaderWithTry(BatchPublisher)
566
582
*/
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 );
569
585
}
570
586
571
587
/**
@@ -604,8 +620,8 @@ public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedBatchPu
604
620
* @param <V> the value type
605
621
* @return a new DataLoader
606
622
*/
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 );
609
625
}
610
626
611
627
/**
@@ -657,8 +673,8 @@ public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(Mapped
657
673
* @return a new DataLoader
658
674
* @see #newDataLoaderWithTry(BatchLoader)
659
675
*/
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 );
662
678
}
663
679
664
680
/**
@@ -697,8 +713,8 @@ public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedBatchPu
697
713
* @param <V> the value type
698
714
* @return a new DataLoader
699
715
*/
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 );
702
718
}
703
719
704
720
/**
@@ -750,11 +766,11 @@ public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(Mapped
750
766
* @return a new DataLoader
751
767
* @see #newMappedPublisherDataLoaderWithTry(MappedBatchPublisher)
752
768
*/
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 );
755
771
}
756
772
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 ) {
758
774
return new DataLoader <>(name , batchLoadFunction , options );
759
775
}
760
776
0 commit comments