简体   繁体   English

可以Spring LdapTemplate流结果吗?

[英]Can Spring LdapTemplate stream results?

I am trying to query an active directory for ALL person objects. 我试图查询所有人对象的活动目录。 There are over 700,000 results which are way too many to read into a List . 有超过700,000结果太多,无法读入List My current solution is using paging to get all of the results but I would much rather use the Java-8 Stream-API to get them instead. 我目前的解决方案是使用分页来获取所有结果,但我宁愿使用Java-8 Stream-API来获取它们。 Unfortunately, I have not found any methods on LdapTemplate that return a Stream object. 不幸的是,我没有在LdapTemplate上找到任何返回Stream对象的方法。

I know that this can return all of the results: 我知道这可以返回所有结果:

public List<LdapPerson> findAll() {
        return ldapTemplate.search("","(objectClass=person)", mapper);
    }

but what I'm looking for is something that can return: 但我正在寻找的是可以返回的东西:

public Stream<LdapPerson> findAll(){
   return ldaptemplate.?????????;
}

Can anyone point me in the right direction? 谁能指出我正确的方向?

No, the LdapTemplate doesn't provide a method that directly returns a Stream<T> from a searched elements. 不, LdapTemplate不提供直接从搜索元素返回Stream<T>的方法。 However, since the method, LdapTemplate::search returns a List<T> , then you can use a characteristics of any Collection<T> that is convertible to Stream<T> using a simple call of collection.stream() method: 但是,由于方法LdapTemplate::search返回List<T> ,因此您可以使用collection.stream()方法的简单调用来使用可转换为Stream<T>任何 Collection<T>的特性:

public Stream<LdapPerson> findAll() {
    return ldapTemplate.search("", "(objectClass=person)", mapper).stream();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM