K
- type parameter indicating the type of keys to use for data load requests.V
- type parameter indicating the type of values returnedpublic interface MappedBatchLoader<K,V>
There are a few constraints that must be upheld:
DataLoader
that uses this batch loader function MUST be able to cope with
null values coming back as results
This form is useful when you don't have a 1:1 mapping of keys to values or when null is an acceptable value for a missing value.
For example, let's assume you want to load users from a database, you could probably use a query that looks like this:
SELECT * FROM User WHERE id IN (keys)
Given say 10 user id keys you might only get 7 results back. This can be more naturally represented in a map than in an ordered list of values from the batch loader function.
When the map is processed by the DataLoader
code, any keys that are missing in the map
will be replaced with null values. The semantic that the number of DataLoader.load(Object)
requests
are matched with and equal number of values is kept.
This means that if 10 keys are asked for then DataLoader.dispatch()
will return a promise of 10 value results and each
of the DataLoader.load(Object)
will complete with a value, null or an exception.
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.CompletionStage<java.util.Map<K,V>> |
load(java.util.Set<K> keys)
Called to batch load the provided keys and return a promise to a map of values.
|