-
Notifications
You must be signed in to change notification settings - Fork 677
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
Add FluentQuery support to QuerydslPredicateExecutor
and QueryByExampleExecutor
#2421
Conversation
…ExampleExecutor. FluentQuery allows extending a query specification initially defined by a Example probe or a Querydsl Predicate and fetching the actual result through a functional programming model: interface PersonRepository extends QuerydslPredicateExecutor<Person> { <S extends T, R> R findBy(Predicate predicate, Function<FluentQuery.FetchableFluentQuery<S>, R> queryFunction); } PersonRepository repo = …; List<PersonProjection> result = repo.findBy(QPerson.person.name.eq("Walter"), q -> q.sort(Sort.by("lastname")).as(PersonProjection.class).all());
49aa6cc
to
390a82b
Compare
QueryByExampleExecutor
and ReactiveQueryByExampleExecutor
QueryByExampleExecutor
and QueryByExampleExecutor
QueryByExampleExecutor
and QueryByExampleExecutor
QuerydslPredicateExecutor
and QueryByExampleExecutor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition in general seems nice, but I wonder why you don't default the methods and throw an UnsupportedOperationException
?
* @return all entities matching the given {@link Predicate}. | ||
* @since 2.6 | ||
*/ | ||
<S extends T, R> R findBy(Predicate predicate, Function<FluentQuery.FetchableFluentQuery<S>, R> queryFunction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not defaulting it?
* @return all entities matching the given {@link Example}. | ||
* @since 2.6 | ||
*/ | ||
<S extends T, R> R findBy(Example<S> example, Function<FluentQuery.FetchableFluentQuery<S>, R> queryFunction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
This extension provides much more flexibility and is a pre-requisite to turn the other methods into default ones. We do not want to raise false expectations in terms of supported API to then throw an exception if e.g. streaming or projections aren't supported. All default repository methods are invoked on the interface as we do not delicate these calls into the actual implementations. |
But the change here will break all other modules. |
Another option might be an additional |
That's a consequence of the current arrangement. Modules can still throw an
Introducing another set of interfaces (for imperative/reactive and Querydsl/Query-by-Example) break the concise programming model as the fluent method cannot be discovered from the marker interface that introduced Querydsl/Query-by-Example functionality to a repository. Each module would have to consider additional marker interfaces to contribute further fragments. As a consequence, we end up with a much more complex arrangement. |
I don't understand this sentiment in connection with your original above:
So either commons or a module will throw an exception and leave unfulfilled expectations. Doesn't make much sense to me. Note that I am totally in for this new feature, but breaking all modules with the reasoning here doesn't work for me. |
Please add a note to the relevant |
Document that FluentQuery instances are immutable. Introduce oneValue/firstValue methods and turn one/first methods into methods returning Optional to simplify nullable method handling.
…ExampleExecutor. FluentQuery allows extending a query specification initially defined by a Example probe or a Querydsl Predicate and fetching the actual result through a functional programming model: interface PersonRepository extends QuerydslPredicateExecutor<Person> { <S extends T, R> R findBy(Predicate predicate, Function<FluentQuery.FetchableFluentQuery<S>, R> queryFunction); } PersonRepository repo = …; List<PersonProjection> result = repo.findBy(QPerson.person.name.eq("Walter"), q -> q.sort(Sort.by("lastname")).as(PersonProjection.class).all()); Closes: #2228 Original pull request: #2421.
That's merged now. |
FluentQuery
allows extending a query specification initially defined by a Example probe or a Querydsl Predicate and fetching the actual result through a functional programming model:Closes #2228