Package org.dataloader
Interface BatchLoader<K,V>
-
- Type Parameters:
K
- type parameter indicating the type of keys to use for data load requests.V
- type parameter indicating the type of values returned
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface @PublicSpi public interface BatchLoader<K,V>
A function that is invoked for batch loading a list of data values indicated by the provided list of keys. The function returns a promise of a list of results of individual load requests.There are a few constraints that must be upheld:
- The list of values must be the same size as the list of keys.
- Each index in the list of values must correspond to the same index in the list of keys.
For example, if your batch function was provided the list of keys:
[ 2, 9, 6, 1 ]
and loading from a back-end service returned this list of values:[ { id: 9, name: 'Chicago' }, { id: 1, name: 'New York' }, { id: 2, name: 'San Francisco' }, ]
then the batch loader function contract has been broken.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 may interpret as no value existing for that key.
To uphold the constraints of the batch function, it must return a 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 ]:
[ { id: 2, name: 'San Francisco' }, { id: 9, name: 'Chicago' }, null, { id: 1, name: 'New York' } ]
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.concurrent.CompletionStage<java.util.List<V>>
load(java.util.List<K> keys)
Called to batch load the provided keys and return a promise to a list of values.
-
-
-
Method Detail
-
load
java.util.concurrent.CompletionStage<java.util.List<V>> load(java.util.List<K> keys)
Called to batch load the provided keys and return a promise to a list of values.If you need calling context then implement
BatchLoaderWithContext
- Parameters:
keys
- the collection of keys to load- Returns:
- a promise of the values for those keys
-
-