-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Implement FluentQuery support for Querydsl and Query by Example #2326
Conversation
I should drop the DtoInstantistingConverter since it isn’t used (yet). |
import org.springframework.data.mapping.model.ParameterValueProvider; | ||
import org.springframework.util.Assert; | ||
|
||
public class DtoInstantiatingConverter implements Converter<Object, Object> { |
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.
For the time being I suggest removing this class as the DTO support needs some additional work.
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.
Done.
|
||
this.targetType = dtoType; | ||
this.context = context; | ||
System.out.println(this.context.getManagedTypes()); |
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.
😬
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.
Gone
* @author Mark Paluch | ||
* @since 2.6 | ||
*/ | ||
public class FetchableFluentQueryByExample<S, R> extends FluentQuerySupport<R> implements FetchableFluentQuery<R> { |
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.
Since this is a new type, we don't need any additional authors. Additionally, I'd make this class package-private.
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.
I will drop the additional authors. However, SimpleJpaRepository
, the primary user of this class, is in a separate package, hence. package-private won't work.
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.
I've move this to the same package and adjusted visibility.
@Override | ||
public <NR> FetchableFluentQuery<NR> as(Class<NR> resultType) { | ||
|
||
return new FetchableFluentQueryByExample<S, NR>(this.example, resultType, this.sort, this.properties, this.finder, |
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.
We might want to reject resultType
that are classes for a clear and early indication that DTO's aren't supported yet.
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.
Done.
public Stream<R> stream() { | ||
|
||
if (this.resultType != this.example.getProbeType()) { | ||
System.out.println("You have a projection!"); |
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.
😬
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.
Removed.
* @author Michael J. Simons | ||
* @since 2.6 | ||
*/ | ||
abstract class FluentQuerySupport<R> { |
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.
Author is only you.
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.
Done
|
||
protected Class<R> resultType; | ||
protected Sort sort; | ||
@Nullable protected Set<String> properties; |
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.
Nit: We put @Nullable
after the visibility modifier. It would make sense to keep all of these properties final
.
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.
Done
|
||
private Page<R> readPage(Pageable pageable) { | ||
|
||
JPQLQuery<S> pagedQuery = this.pagedFinder.apply(this.sort, pageable); |
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.
properties
(from project
) aren't evaluated yet within the projection. Not sure what it requires to construct an entity graph from these properties.
@@ -164,6 +167,13 @@ public QuerydslJpaRepository(JpaEntityInformation<T, ID> entityInformation, Enti | |||
return PageableExecutionUtils.getPage(query.fetch(), pageable, countQuery::fetchCount); | |||
} | |||
|
|||
@Override | |||
public <S extends T, R> R findBy(Predicate predicate, |
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.
👍
*/ | ||
private static class ExampleSpecification<T> implements Specification<T> { | ||
public static class ExampleSpecification<T> implements Specification<T> { |
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.
Can we keep this class private? We should not expose it.
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.
Done
Can we move the fluent query classes into the support package? That way we can keep them package-private. |
Packages moved, visibility adjusted. |
Add support for both QueryByExampleExecutor and QuerydslPredicateExecutor. This is used in SimpleJpaRepository and QuerydslJpaPredicateExecutor, resulting in various test cases proving support by both examples and Querydsl predicates. NOTE: Class-based DTOs are NOT supported yet. Closes #2294. Related: #2327.
11e4558
to
64beaab
Compare
Branch has been polished and force pushed. Opened #2327 to track class-based DTOs. |
Add support for both QueryByExampleExecutor and QuerydslPredicateExecutor. This is used in SimpleJpaRepository and QuerydslJpaPredicateExecutor, resulting in various test cases proving support by both examples and Querydsl predicates. NOTE: Class-based DTOs are NOT supported yet. See #2294 Original pull request: #2326.
That's merged and polished now. |
No description provided.