spring-projects / spring-projects/spring-data-rest
When using QueryDsl developers should be able to provide their own implementation of EntityPathResolver [DATAREST-694]
@odrotbohm is already working on this.
Since Dec 31, 2020.
- Dominant language
- Java
- Stars
- 958
- Forks
- 568
- PR merge metrics
- No merged PRs in 30d
Description
Vladimir Tsanev opened DATAREST-694 and commented
Use case that we have, has following requirements:
- Enable QueryDsl for rest repositories. So applications consuming the
/\{repository\}/somethingendpoints can specify filters with?property=value. - Currently only exporting JpaRepositories via rest.
- Not actually using QueryDsl in application code that depends on repositories (it will be used only by client side applications, consuming the rest endpoints).
- Do not want QueryDsl Query classes generated, some of the reasons:
- Too much unused classes
- Complicates the build
- Not really concerned about performance of query dsl path creating (caching them is sufficient enough).
Spring Data defines a strategy interface for resolving QueryDsl entity paths - EntityPathResolver.
We want to provide our own implementation to be used by spring data jpa/rest, based on PathBuilder instead of the generated query classes.
However currently it is a painful experience to meet to above requirements. Here are some of the problems we met and some suggestions for improvements.
EntityPathResolverprovided byQuerydslBindingsFactoryis not actually used when creating instances ofQueryDslJpaRepository,
but a hard-coded reference toSimpleEntityPathResolver.INSTANCE- Currently this could be worked around by providing custom repositoryFactoryBeanClass
- it would be better if sharing the same resolver between
JpaRepositoryFactoryandQuerydslBindingsFactorywas easier.
QueryPredicateBuilder(wrongly?) assumes thatPathinstances returned by the resolver are instances of generated querydsl classes (seereifyPath).- To workaround this we provide our custom implementation of
QueryPredicateBuilder, butQueryPredicateBuilderis a class that and cannot be easily extended. We also want to be able to wrap it to provide alternative chained implementations.- To provide custom
QueryPredicateBuilder, one should extendRepositoryRestMvcConfigurationand overriderepoRequestArgumentResolver().
- To workaround this we provide our custom implementation of
QuerydslAwareRootResourceInformationHandlerMethodArgumentResolver is package private, and we need to copy paste it in order to instantiate it in our configuration!
Maybe having QuerydslPredicateBuilder as a bean like QuerydslBindingsFactory would be better, extending RepositoryRestMvcConfiguration is something that we want to avoid because it disables spring boot's auto configuration.
Affects: 2.4 GA (Gosling)
8 votes, 9 watchers
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.