|
16 | 16 |
|
17 | 17 | package org.dataloader;
|
18 | 18 |
|
19 |
| -import org.dataloader.impl.CombinedFuturesImpl; |
20 |
| - |
21 |
| -import java.util.Collection; |
| 19 | +import java.util.List; |
22 | 20 |
|
23 | 21 | /**
|
24 |
| - * Function that is invoked for batch loading the list of data values indicated by the provided list of keys. The |
25 |
| - * function returns a {@link CombinedFuturesImpl} to aggregate results of individual load requests. |
| 22 | + * A function that is invoked for batch loading a list of data values indicated by the provided list of keys. The |
| 23 | + * function returns a {@link PromisedValues} to aggregate results of individual load requests. |
| 24 | + * |
| 25 | + * There are a few constraints that must be upheld: |
| 26 | + * <ul> |
| 27 | + * <li>The list of values must be the same size as the list of keys.</li> |
| 28 | + * <li>Each index in the list of values must correspond to the same index in the list of keys.</li> |
| 29 | + * </ul> |
| 30 | + * |
| 31 | + * For example, if your batch function was provided the list of keys: [ 2, 9, 6, 1 ], and loading from a back-end service returned the values: |
| 32 | + * |
| 33 | + * <pre> |
| 34 | + * [ |
| 35 | + * { id: 9, name: 'Chicago' }, |
| 36 | + * { id: 1, name: 'New York' }, |
| 37 | + * { id: 2, name: 'San Francisco' }, |
| 38 | + * ] |
| 39 | + * </pre> |
| 40 | + * |
| 41 | + * The back-end service returned results in a different order than we requested, likely because it was more efficient for it to do so. Also, it omitted a result for key 6, which we can interpret as no value |
| 42 | + * existing for that key. |
| 43 | + * |
| 44 | + * To uphold the constraints of the batch function, it must return an List of values the same length as the List of keys, and re-order them to ensure each index aligns with the original keys [ 2, 9, 6, 1 ]: |
| 45 | + * |
| 46 | + * <pre> |
| 47 | + * [ |
| 48 | + * { id: 2, name: 'San Francisco' }, |
| 49 | + * { id: 9, name: 'Chicago' }, |
| 50 | + * null, |
| 51 | + * { id: 1, name: 'New York' } |
| 52 | + * ] |
| 53 | + * </pre> |
26 | 54 | *
|
27 | 55 | * @param <K> type parameter indicating the type of keys to use for data load requests.
|
| 56 | + * @param <V> type parameter indicating the type of values returned |
28 | 57 | *
|
29 | 58 | * @author <a href="https://github.com/aschrijver/">Arnold Schrijver</a>
|
30 | 59 | */
|
31 | 60 | @FunctionalInterface
|
32 |
| -public interface BatchLoader<K> { |
| 61 | +public interface BatchLoader<K, V> { |
33 | 62 |
|
34 | 63 | /**
|
35 |
| - * Batch load the provided keys and return a composite future of the result. |
| 64 | + * Called to batch load the provided keys and return a {@link PromisedValues} which is a promise to a list of values |
36 | 65 | *
|
37 |
| - * @param keys the list of keys to load |
| 66 | + * @param keys the collection of keys to load |
38 | 67 | *
|
39 |
| - * @return the composite future |
| 68 | + * @return a promise of the values for those keys |
40 | 69 | */
|
41 |
| - CombinedFutures load(Collection<K> keys); |
| 70 | + PromisedValues<V> load(List<K> keys); |
42 | 71 | }
|
0 commit comments