Skip to content

[WIP] Add support for mandatory single result in LdapClient search operations#1446

Draft
therepanic wants to merge 1 commit intospring-projects:mainfrom
therepanic:gh-1404
Draft

[WIP] Add support for mandatory single result in LdapClient search operations#1446
therepanic wants to merge 1 commit intospring-projects:mainfrom
therepanic:gh-1404

Conversation

@therepanic
Copy link
Contributor

@therepanic therepanic commented Mar 16, 2026

This commit added the single, optional, list, and stream methods to the LdapClient#SearchSpec and deprecated the implementations that will be deprecated by this change.

Please note that this is a WIP: I have a couple of comments that would be helpful to address.

Closes: gh-1404

Closes: spring-projectsgh-1404

Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
Comment on lines +418 to +430
default <T> MappedSearchSpec<T> map(ContextMapper<T> mapper) {
return new MappedSearchSpec<T>() {
@Override
public List<T> list() {
return toList(mapper);
}

@Override
public Stream<T> stream() {
return toStream(mapper);
}
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently a poorly implemented implementation that uses methods we've depricated. Should we literally take the default implementation for these methods from DefaultLdapClient?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer we not use deprecated code where possible. If needed, the copy-paste can be abstracted away in a package-private utility class. Are there any other concerns other than the duplication?

Comment on lines +668 to +673
interface MappedSearchSpec<T extends @Nullable Object> {

/**
* Retrieve the result as a lazily resolved stream of mapped objects, retaining
* the order from the original database result.
* @return the result Stream, containing mapped objects, needing to be closed once
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of this class is essentially copied from JdbcClient

Comment on lines +376 to +380
*/
default <O extends LdapDataEntry> O single() {
ContextMapper<O> cast = (ctx) -> (O) ctx;
return map(cast).single();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there's a better idea for the default implementation?

Also, should we create tests for the default implementations of these methods? Besides, I don't think we need to reimplement them in DefaultLdapClient?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's please test them. It will help us to know when we inadvertently make a non-passive change down the road.

Copy link
Collaborator

@jzheaux jzheaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far, @therepanic! If you feel good about it, let's go ahead and proceed with testing and with updating the documentation.

/**
* Retrieve a single search result as a required {@link LdapDataEntry} instance.
* @return the single result object (never {@code null})
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add @since 4.1 to new classes and methods.

Comment on lines +376 to +380
*/
default <O extends LdapDataEntry> O single() {
ContextMapper<O> cast = (ctx) -> (O) ctx;
return map(cast).single();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's please test them. It will help us to know when we inadvertently make a non-passive change down the road.

Comment on lines +418 to +430
default <T> MappedSearchSpec<T> map(ContextMapper<T> mapper) {
return new MappedSearchSpec<T>() {
@Override
public List<T> list() {
return toList(mapper);
}

@Override
public Stream<T> stream() {
return toStream(mapper);
}
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer we not use deprecated code where possible. If needed, the copy-paste can be abstracted away in a package-private utility class. Are there any other concerns other than the duplication?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for mandatory single result in LdapClient search operations

2 participants