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
Improve lookupFragmentInterface to supports a better hierarchy in repository composition [DATACMNS-1537] #1965
Comments
Jens Schauder commented arielcarrera please clarify what you want improved, what exactly isn't working? |
arielcarrera commented Hello Jens Schauder, if you have a project using the CDI Extension, when you make a compose with your repository fragments in a multilevel hierarchy and if you want to add some base fragment with custom implementation... it is not working. |
Mark Paluch commented Sorry, I do not understand what you're trying to achieve. Please outline your use-case with a simple code sample without us requiring to understand your repository code |
arielcarrera commented Hi Mark, I will make a sample project without my fix. Give me a while |
Mark Paluch commented No need for a sample project in the first place. Having interface declaration stubs and class stubs here should be sufficient |
arielcarrera commented Hi Mark, I do a new sample project with a minimal repository hierarchy. When you execute my junit Test (RepositoryTest.java) you get something like this:
So, in my new sample project you have:
|
arielcarrera commented I do not know if the minimum example that I have uploaded is sufficient to understand the flexibility that could be achieved by improving the search for fragments in a hierarchical way. Tell me if you do not understand something or I'm wrong, or if you want a PR to test a possible improvement. Best regards |
Mark Paluch commented Thanks a lot. So what you basically want to achieve is using fragments in ``@NoRepositoryBean``s. This is currently not supported, neither in when using Spring's dependency management nor using CDI. We currently only inspect top-level repository interfaces only for fragment declarations and do not consider ones that are Changing this approach results in a more extensive scanning. The actual question is: Where do we stop? Each fragment causes a scan for a custom implementation. This is already cached but nevertheless we potentially would scan for implementations of We also need to find a proper rule for base packages. Right now, fragment implementation are expected to be found within the either configured base packages (for Spring) and the fragment interface package for CDI. Typically, you'd expect the implementation somewhere close to the fragment interface and so we would scan for components outside the repository interface |
arielcarrera commented I will try to check my code and improve my lookup method... I hope to send to you a draft or a pull request in a few days |
Mark Paluch commented This is not about code changes in the first place, it is about defining how fragment lookup is supposed to work and whether we want to incorporate this change at all |
arielcarrera commented You're right Mark, discuss if you're interested in the change, in my personal opinion I think it brings several advantages compared to the current implementation. Secondly, It would add more tools to customize the repositories allowing to make more complex compositions that are usually needed for build base/core classes of projects. It would allow for example to create a class/fragment "Helper" with methods like getEntityManager, getUserTransaction, getCriteriaBuilder, etc ... and inherit it from any interface in the hierarchy (without extend a class). Of course the same can be achieved without the need to support this but I think this can be more flexible.
Regarding the disadvantage of requiring a more extensive scan: "Where do we stop?": Different strategies could be proposed for example by means of a cache to avoid cyclic references, a parameter of maximum depth, an annotation to enable or disable scanning, etc. "Each fragment causes a scan for a custom implementation. This is already cached but nevertheless we would like to scan for implementations of CrudRepository and the like": If it is saved in cache and it is done only once, the search for the implementation does not seem like a great penalty, however you could evaluate any strategy to skip or enable this type of search by annotation, or initialize the cache with a "No implementation" value for some interfaces, etc. Please let me know if I can be of any help |
arielcarrera commented Hi Mark Paluch, do you have any news about this? Can I help you with something? |
Duplicates #2142. @arielcarrera after reiterating a few times, we came to the decision to not implement fragment support. Resolving hierarchies along with method precedence introduces another level of complexity and we want to keep things simple. |
Ok Thanks Mark, Is there no chance to provide a default implementation and open the possibility to provide a custom implementation / discovery leaving this complexity in the hands of the user? |
You can assemble a repository via Something along the lines of:
The order of |
arielcarrera opened DATACMNS-1537 and commented
Improve method lookupFragmentInterface in CdiRepositoryBean to supports a better hierarchy in repository composition
Check my test project:
https://github.com/arielcarrera/cdi-spring-data-jpa-test
Usage of CustomJpaRepository/Impl in a base interface.
https://github.com/arielcarrera/cdi-spring-data-jpa-test/blob/master/src/main/java/com/github/arielcarrera/cdi/repositories/helpers/CustomJpaRepository.java
Issue Links:
("is duplicated by")
The text was updated successfully, but these errors were encountered: