class AddressBatchLoader implements BatchLoader<Long, Address> {

    @Override
    public CompletionStage<List<Address>> load(List<Long> keys) {
        return CompletableFuture.supplyAsync(() -> {
            if (keys == null || keys.isEmpty()) {
                return Collections.emptyList();
            }

            DynamicQuery query = DynamicQueryFactoryUtil.forClass(Address.class);
            query.add(PropertyFactoryUtil.forName("addressId")
                    .in(keys.stream()
                            .mapToLong(l -> l)
                            .toArray()));
            return addressLocalService.dynamicQuery(query);
        });
    }

}