Skip to content

Commit fbeffae

Browse files
Expose new*DataLoader methods for *PublisherBatchLoader
This is keeping in line with the other methods found in `DataLoaderFactory`.
1 parent a3132b7 commit fbeffae

File tree

3 files changed

+278
-10
lines changed

3 files changed

+278
-10
lines changed

src/main/java/org/dataloader/DataLoaderFactory.java

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,274 @@ public static <K, V> DataLoader<K, V> newMappedDataLoaderWithTry(MappedBatchLoad
278278
return mkDataLoader(batchLoadFunction, options);
279279
}
280280

281+
/**
282+
* Creates new DataLoader with the specified batch loader function and default options
283+
* (batching, caching and unlimited batch size).
284+
*
285+
* @param batchLoadFunction the batch load function to use
286+
* @param <K> the key type
287+
* @param <V> the value type
288+
*
289+
* @return a new DataLoader
290+
*/
291+
public static <K, V> DataLoader<K, V> newPublisherDataLoader(PublisherBatchLoader<K, V> batchLoadFunction) {
292+
return newPublisherDataLoader(batchLoadFunction, null);
293+
}
294+
295+
/**
296+
* Creates new DataLoader with the specified batch loader function with the provided options
297+
*
298+
* @param batchLoadFunction the batch load function to use
299+
* @param options the options to use
300+
* @param <K> the key type
301+
* @param <V> the value type
302+
*
303+
* @return a new DataLoader
304+
*/
305+
public static <K, V> DataLoader<K, V> newPublisherDataLoader(PublisherBatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
306+
return mkDataLoader(batchLoadFunction, options);
307+
}
308+
309+
/**
310+
* Creates new DataLoader with the specified batch loader function and default options
311+
* (batching, caching and unlimited batch size) where the batch loader function returns a list of
312+
* {@link org.dataloader.Try} objects.
313+
* <p>
314+
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then
315+
* you can use this form to create the data loader.
316+
* <p>
317+
* Using Try objects allows you to capture a value returned or an exception that might
318+
* have occurred trying to get a value. .
319+
*
320+
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
321+
* @param <K> the key type
322+
* @param <V> the value type
323+
*
324+
* @return a new DataLoader
325+
*/
326+
public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(PublisherBatchLoader<K, Try<V>> batchLoadFunction) {
327+
return newPublisherDataLoaderWithTry(batchLoadFunction, null);
328+
}
329+
330+
/**
331+
* Creates new DataLoader with the specified batch loader function and with the provided options
332+
* where the batch loader function returns a list of
333+
* {@link org.dataloader.Try} objects.
334+
*
335+
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
336+
* @param options the options to use
337+
* @param <K> the key type
338+
* @param <V> the value type
339+
*
340+
* @return a new DataLoader
341+
*
342+
* @see #newDataLoaderWithTry(BatchLoader)
343+
*/
344+
public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(PublisherBatchLoader<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
345+
return mkDataLoader(batchLoadFunction, options);
346+
}
347+
348+
/**
349+
* Creates new DataLoader with the specified batch loader function and default options
350+
* (batching, caching and unlimited batch size).
351+
*
352+
* @param batchLoadFunction the batch load function to use
353+
* @param <K> the key type
354+
* @param <V> the value type
355+
*
356+
* @return a new DataLoader
357+
*/
358+
public static <K, V> DataLoader<K, V> newPublisherDataLoader(PublisherBatchLoaderWithContext<K, V> batchLoadFunction) {
359+
return newPublisherDataLoader(batchLoadFunction, null);
360+
}
361+
362+
/**
363+
* Creates new DataLoader with the specified batch loader function with the provided options
364+
*
365+
* @param batchLoadFunction the batch load function to use
366+
* @param options the options to use
367+
* @param <K> the key type
368+
* @param <V> the value type
369+
*
370+
* @return a new DataLoader
371+
*/
372+
public static <K, V> DataLoader<K, V> newPublisherDataLoader(PublisherBatchLoaderWithContext<K, V> batchLoadFunction, DataLoaderOptions options) {
373+
return mkDataLoader(batchLoadFunction, options);
374+
}
375+
376+
/**
377+
* Creates new DataLoader with the specified batch loader function and default options
378+
* (batching, caching and unlimited batch size) where the batch loader function returns a list of
379+
* {@link org.dataloader.Try} objects.
380+
* <p>
381+
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then
382+
* you can use this form to create the data loader.
383+
* <p>
384+
* Using Try objects allows you to capture a value returned or an exception that might
385+
* have occurred trying to get a value. .
386+
*
387+
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
388+
* @param <K> the key type
389+
* @param <V> the value type
390+
*
391+
* @return a new DataLoader
392+
*/
393+
public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(PublisherBatchLoaderWithContext<K, Try<V>> batchLoadFunction) {
394+
return newPublisherDataLoaderWithTry(batchLoadFunction, null);
395+
}
396+
397+
/**
398+
* Creates new DataLoader with the specified batch loader function and with the provided options
399+
* where the batch loader function returns a list of
400+
* {@link org.dataloader.Try} objects.
401+
*
402+
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
403+
* @param options the options to use
404+
* @param <K> the key type
405+
* @param <V> the value type
406+
*
407+
* @return a new DataLoader
408+
*
409+
* @see #newPublisherDataLoaderWithTry(PublisherBatchLoader)
410+
*/
411+
public static <K, V> DataLoader<K, V> newPublisherDataLoaderWithTry(PublisherBatchLoaderWithContext<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
412+
return mkDataLoader(batchLoadFunction, options);
413+
}
414+
415+
/**
416+
* Creates new DataLoader with the specified batch loader function and default options
417+
* (batching, caching and unlimited batch size).
418+
*
419+
* @param batchLoadFunction the batch load function to use
420+
* @param <K> the key type
421+
* @param <V> the value type
422+
*
423+
* @return a new DataLoader
424+
*/
425+
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedPublisherBatchLoader<K, V> batchLoadFunction) {
426+
return newMappedPublisherDataLoader(batchLoadFunction, null);
427+
}
428+
429+
/**
430+
* Creates new DataLoader with the specified batch loader function with the provided options
431+
*
432+
* @param batchLoadFunction the batch load function to use
433+
* @param options the options to use
434+
* @param <K> the key type
435+
* @param <V> the value type
436+
*
437+
* @return a new DataLoader
438+
*/
439+
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedPublisherBatchLoader<K, V> batchLoadFunction, DataLoaderOptions options) {
440+
return mkDataLoader(batchLoadFunction, options);
441+
}
442+
443+
/**
444+
* Creates new DataLoader with the specified batch loader function and default options
445+
* (batching, caching and unlimited batch size) where the batch loader function returns a list of
446+
* {@link org.dataloader.Try} objects.
447+
* <p>
448+
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then
449+
* you can use this form to create the data loader.
450+
* <p>
451+
* Using Try objects allows you to capture a value returned or an exception that might
452+
* have occurred trying to get a value. .
453+
*
454+
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
455+
* @param <K> the key type
456+
* @param <V> the value type
457+
*
458+
* @return a new DataLoader
459+
*/
460+
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(MappedPublisherBatchLoader<K, Try<V>> batchLoadFunction) {
461+
return newMappedPublisherDataLoaderWithTry(batchLoadFunction, null);
462+
}
463+
464+
/**
465+
* Creates new DataLoader with the specified batch loader function and with the provided options
466+
* where the batch loader function returns a list of
467+
* {@link org.dataloader.Try} objects.
468+
*
469+
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
470+
* @param options the options to use
471+
* @param <K> the key type
472+
* @param <V> the value type
473+
*
474+
* @return a new DataLoader
475+
*
476+
* @see #newDataLoaderWithTry(BatchLoader)
477+
*/
478+
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(MappedPublisherBatchLoader<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
479+
return mkDataLoader(batchLoadFunction, options);
480+
}
481+
482+
/**
483+
* Creates new DataLoader with the specified batch loader function and default options
484+
* (batching, caching and unlimited batch size).
485+
*
486+
* @param batchLoadFunction the batch load function to use
487+
* @param <K> the key type
488+
* @param <V> the value type
489+
*
490+
* @return a new DataLoader
491+
*/
492+
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedPublisherBatchLoaderWithContext<K, V> batchLoadFunction) {
493+
return newMappedPublisherDataLoader(batchLoadFunction, null);
494+
}
495+
496+
/**
497+
* Creates new DataLoader with the specified batch loader function with the provided options
498+
*
499+
* @param batchLoadFunction the batch load function to use
500+
* @param options the options to use
501+
* @param <K> the key type
502+
* @param <V> the value type
503+
*
504+
* @return a new DataLoader
505+
*/
506+
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoader(MappedPublisherBatchLoaderWithContext<K, V> batchLoadFunction, DataLoaderOptions options) {
507+
return mkDataLoader(batchLoadFunction, options);
508+
}
509+
510+
/**
511+
* Creates new DataLoader with the specified batch loader function and default options
512+
* (batching, caching and unlimited batch size) where the batch loader function returns a list of
513+
* {@link org.dataloader.Try} objects.
514+
* <p>
515+
* If it's important you to know the exact status of each item in a batch call and whether it threw exceptions then
516+
* you can use this form to create the data loader.
517+
* <p>
518+
* Using Try objects allows you to capture a value returned or an exception that might
519+
* have occurred trying to get a value. .
520+
*
521+
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
522+
* @param <K> the key type
523+
* @param <V> the value type
524+
*
525+
* @return a new DataLoader
526+
*/
527+
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(MappedPublisherBatchLoaderWithContext<K, Try<V>> batchLoadFunction) {
528+
return newMappedPublisherDataLoaderWithTry(batchLoadFunction, null);
529+
}
530+
531+
/**
532+
* Creates new DataLoader with the specified batch loader function and with the provided options
533+
* where the batch loader function returns a list of
534+
* {@link org.dataloader.Try} objects.
535+
*
536+
* @param batchLoadFunction the batch load function to use that uses {@link org.dataloader.Try} objects
537+
* @param options the options to use
538+
* @param <K> the key type
539+
* @param <V> the value type
540+
*
541+
* @return a new DataLoader
542+
*
543+
* @see #newMappedPublisherDataLoaderWithTry(MappedPublisherBatchLoader)
544+
*/
545+
public static <K, V> DataLoader<K, V> newMappedPublisherDataLoaderWithTry(MappedPublisherBatchLoaderWithContext<K, Try<V>> batchLoadFunction, DataLoaderOptions options) {
546+
return mkDataLoader(batchLoadFunction, options);
547+
}
548+
281549
static <K, V> DataLoader<K, V> mkDataLoader(Object batchLoadFunction, DataLoaderOptions options) {
282550
return new DataLoader<>(batchLoadFunction, options);
283551
}

src/test/java/org/dataloader/DataLoaderMappedPublisherBatchLoaderTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import static java.util.Arrays.asList;
1414
import static org.awaitility.Awaitility.await;
15-
import static org.dataloader.DataLoaderFactory.mkDataLoader;
15+
import static org.dataloader.DataLoaderFactory.newMappedPublisherDataLoader;
1616
import static org.hamcrest.Matchers.equalTo;
1717
import static org.hamcrest.Matchers.is;
1818
import static org.junit.Assert.assertThat;
@@ -22,7 +22,7 @@ public class DataLoaderMappedPublisherBatchLoaderTest {
2222
@Test
2323
public void should_Build_a_really_really_simple_data_loader() {
2424
AtomicBoolean success = new AtomicBoolean();
25-
DataLoader<Integer, Integer> identityLoader = mkDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
25+
DataLoader<Integer, Integer> identityLoader = newMappedPublisherDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
2626

2727
CompletionStage<Integer> future1 = identityLoader.load(1);
2828

@@ -37,7 +37,7 @@ public void should_Build_a_really_really_simple_data_loader() {
3737
@Test
3838
public void should_Support_loading_multiple_keys_in_one_call() {
3939
AtomicBoolean success = new AtomicBoolean();
40-
DataLoader<Integer, Integer> identityLoader = mkDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
40+
DataLoader<Integer, Integer> identityLoader = newMappedPublisherDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
4141

4242
CompletionStage<List<Integer>> futureAll = identityLoader.loadMany(asList(1, 2));
4343
futureAll.thenAccept(promisedValues -> {
@@ -51,7 +51,7 @@ public void should_Support_loading_multiple_keys_in_one_call() {
5151

5252
@Test
5353
public void simple_dataloader() {
54-
DataLoader<String, String> loader = mkDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
54+
DataLoader<String, String> loader = newMappedPublisherDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
5555

5656
loader.load("A");
5757
loader.load("B");
@@ -65,7 +65,7 @@ public void simple_dataloader() {
6565

6666
@Test
6767
public void should_observer_batch_multiple_requests() throws ExecutionException, InterruptedException {
68-
DataLoader<Integer, Integer> identityLoader = mkDataLoader(keysAsValues(), new DataLoaderOptions());
68+
DataLoader<Integer, Integer> identityLoader = newMappedPublisherDataLoader(keysAsValues(), new DataLoaderOptions());
6969

7070
CompletableFuture<Integer> future1 = identityLoader.load(1);
7171
CompletableFuture<Integer> future2 = identityLoader.load(2);

src/test/java/org/dataloader/DataLoaderPublisherBatchLoaderTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import static java.util.Arrays.asList;
1313
import static org.awaitility.Awaitility.await;
14-
import static org.dataloader.DataLoaderFactory.mkDataLoader;
14+
import static org.dataloader.DataLoaderFactory.newPublisherDataLoader;
1515
import static org.hamcrest.Matchers.equalTo;
1616
import static org.hamcrest.Matchers.is;
1717
import static org.junit.Assert.assertThat;
@@ -21,7 +21,7 @@ public class DataLoaderPublisherBatchLoaderTest {
2121
@Test
2222
public void should_Build_a_really_really_simple_data_loader() {
2323
AtomicBoolean success = new AtomicBoolean();
24-
DataLoader<Integer, Integer> identityLoader = mkDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
24+
DataLoader<Integer, Integer> identityLoader = newPublisherDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
2525

2626
CompletionStage<Integer> future1 = identityLoader.load(1);
2727

@@ -36,7 +36,7 @@ public void should_Build_a_really_really_simple_data_loader() {
3636
@Test
3737
public void should_Support_loading_multiple_keys_in_one_call() {
3838
AtomicBoolean success = new AtomicBoolean();
39-
DataLoader<Integer, Integer> identityLoader = mkDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
39+
DataLoader<Integer, Integer> identityLoader = newPublisherDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
4040

4141
CompletionStage<List<Integer>> futureAll = identityLoader.loadMany(asList(1, 2));
4242
futureAll.thenAccept(promisedValues -> {
@@ -50,7 +50,7 @@ public void should_Support_loading_multiple_keys_in_one_call() {
5050

5151
@Test
5252
public void simple_dataloader() {
53-
DataLoader<String, String> loader = mkDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
53+
DataLoader<String, String> loader = newPublisherDataLoader(keysAsValues(), DataLoaderOptions.newOptions());
5454

5555
loader.load("A");
5656
loader.load("B");
@@ -64,7 +64,7 @@ public void simple_dataloader() {
6464

6565
@Test
6666
public void should_observer_batch_multiple_requests() throws ExecutionException, InterruptedException {
67-
DataLoader<Integer, Integer> identityLoader = mkDataLoader(keysAsValues(), new DataLoaderOptions());
67+
DataLoader<Integer, Integer> identityLoader = newPublisherDataLoader(keysAsValues(), new DataLoaderOptions());
6868

6969
CompletableFuture<Integer> future1 = identityLoader.load(1);
7070
CompletableFuture<Integer> future2 = identityLoader.load(2);

0 commit comments

Comments
 (0)