Closed mp911de closed 1 year ago
Thanks for the suggestion, @mp911de.
How did you decide on those two methods? Several LdapTemplate
methods return a List
and could possibly benefit from a Stream
equivalent. Or, IOW, I'm wondering if any other methods should be considered.
After some further analysis, it seems search(LdapQuery, ContextMapper<T>)
is a better fit. Also, search(LdapQuery, AttributeMapper<T>)
could benefit from a Stream
option.
What I'd recommend are the following three new methods:
Stream<T> findStream(LdapQuery query, Class<T> clazz);
Stream<T> searchStream(LdapQuery query, AttributeMapper<T> mapper);
Stream<T> searchStream(LdapQuery query, ContextMapper<T> mapper);
findStream
/searchStream
are going into the right direction. Maybe just stream
for a less clunky name.
A method returning Stream
and accepting ContextMapper
seems weird at first sight (one could always call stream.map(mapper::mapFromContext)
but given that mapFromContext
can throw an exception, the design proposal makes sense.
It would be great if
LdapTemplate
could bridgeNamingEnumeration
into a Java 8Stream
exposing the following methods:This would be useful in the context of Spring Data to natively expose the LDAP result as stream without collecting results into a
Collection
. SinceNamingEnumeration
is closeable, theStream
needs to be closed after consumption but that is a regular requirement when used in other modules such asJdbcTemplate.queryForStream(…)
or JPA stream queries.501 seems a related ticket.