Skip to content

Add support to return a Java 8 Stream from LdapTemplate #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mp911de opened this issue Aug 31, 2021 · 3 comments
Closed

Add support to return a Java 8 Stream from LdapTemplate #586

mp911de opened this issue Aug 31, 2021 · 3 comments

Comments

@mp911de
Copy link
Member

mp911de commented Aug 31, 2021

It would be great if LdapTemplate could bridge NamingEnumeration into a Java 8 Stream exposing the following methods:

Stream<T> find(LdapQuery query, Class<T> clazz);

Stream<T> find(LdapQuery query, ContextMapper<T> mapper);

This would be useful in the context of Spring Data to natively expose the LDAP result as stream without collecting results into a Collection. Since NamingEnumeration is closeable, the Stream needs to be closed after consumption but that is a regular requirement when used in other modules such as JdbcTemplate.queryForStream(…) or JPA stream queries.

#501 seems a related ticket.

@jzheaux jzheaux added this to the 3.0.0-M3 milestone Jul 19, 2022
@jzheaux jzheaux self-assigned this Jul 19, 2022
@jzheaux
Copy link
Collaborator

jzheaux commented Jul 21, 2022

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.

@jzheaux
Copy link
Collaborator

jzheaux commented Jul 21, 2022

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);

@mp911de
Copy link
Member Author

mp911de commented Jul 22, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants