Skip to content

Commit 19234f1

Browse files
committed
PR changes
1 parent 8a26727 commit 19234f1

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,13 @@ For example, let's assume you want to load users from a database, you could prob
221221
@Override
222222
public CompletionStage<Map<Long, User>> load(Set<Long> userIds, BatchLoaderEnvironment environment) {
223223
SecurityCtx callCtx = environment.getContext();
224-
return CompletableFuture.supplyAsync(() -> userManager.loadMapOfUsersById(callCtx, userIds));
224+
return CompletableFuture.supplyAsync(() -> userManager.loadMapOfUsersByIds(callCtx, userIds));
225225
}
226226
};
227227

228228
DataLoader<Long, User> userLoader = DataLoader.newMappedDataLoader(mapBatchLoader);
229229

230230
// ...
231-
232-
// ...
233231
```
234232

235233
### Error object is not a thing in a type safe Java world

src/main/java/org/dataloader/DataLoaderHelper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.LinkedHashSet;
1010
import java.util.List;
1111
import java.util.Map;
12+
import java.util.Set;
1213
import java.util.concurrent.CompletableFuture;
1314
import java.util.concurrent.CompletionStage;
1415
import java.util.stream.Collectors;
@@ -275,10 +276,11 @@ private CompletionStage<List<V>> invokeListBatchLoader(List<K> keys, BatchLoader
275276
@SuppressWarnings("unchecked")
276277
private CompletionStage<List<V>> invokeMapBatchLoader(List<K> keys, BatchLoaderEnvironment environment) {
277278
CompletionStage<Map<K, V>> loadResult;
279+
Set<K> setOfKeys = new LinkedHashSet<>(keys);
278280
if (batchLoadFunction instanceof MappedBatchLoaderWithContext) {
279-
loadResult = ((MappedBatchLoaderWithContext<K, V>) batchLoadFunction).load(new LinkedHashSet<>(keys), environment);
281+
loadResult = ((MappedBatchLoaderWithContext<K, V>) batchLoadFunction).load(setOfKeys, environment);
280282
} else {
281-
loadResult = ((MappedBatchLoader<K, V>) batchLoadFunction).load(new LinkedHashSet<>(keys));
283+
loadResult = ((MappedBatchLoader<K, V>) batchLoadFunction).load(setOfKeys);
282284
}
283285
CompletionStage<Map<K, V>> mapBatchLoad = nonNull(loadResult, "Your batch loader function MUST return a non null CompletionStage promise");
284286
return mapBatchLoad.thenApply(map -> {

src/test/java/ReadmeExamples.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private void mapBatchLoader() {
108108
@Override
109109
public CompletionStage<Map<Long, User>> load(Set<Long> userIds, BatchLoaderEnvironment environment) {
110110
SecurityCtx callCtx = environment.getContext();
111-
return CompletableFuture.supplyAsync(() -> userManager.loadMapOfUsersById(callCtx, userIds));
111+
return CompletableFuture.supplyAsync(() -> userManager.loadMapOfUsersByIds(callCtx, userIds));
112112
}
113113
};
114114

src/test/java/org/dataloader/fixtures/UserManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public List<User> loadUsersById(List<Long> userIds) {
5252
return userIds.stream().map(this::loadUserById).collect(Collectors.toList());
5353
}
5454

55-
public Map<Long, User> loadMapOfUsersById(SecurityCtx callCtx, Set<Long> userIds) {
55+
public Map<Long, User> loadMapOfUsersByIds(SecurityCtx callCtx, Set<Long> userIds) {
5656
Map<Long, User> map = new HashMap<>();
5757
userIds.forEach(userId -> {
5858
User user = loadUserById(userId);

0 commit comments

Comments
 (0)