Skip to content
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 support for custom repository proxy post processors in CDI [DATACMNS-1538] #1966

Closed
spring-projects-issues opened this issue May 20, 2019 · 8 comments
Assignees
Labels
in: repository type: enhancement

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented May 20, 2019

arielcarrera opened DATACMNS-1538 and commented

It can be useful to be capable to add custom interceptors. For example a custom Transactional Interceptor in CDI.

If you wish, I can contribute with a PR, I can extract the necessary lines from my test project.

check my test project:

https://github.com/arielcarrera/cdi-spring-data-jpa-test


Issue Links:

  • DATACMNS-1688 Allow to register custom RepositoryProxyPostProcessors

Referenced from: pull request #396, and commits 0988427, 467f60f

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 21, 2019

Jens Schauder commented

Again I need some clarification on what you want to achieve and what your proposed change is.

I appreciate the link to the test project, but without some pointers it is hard to figure out what you did there and for what purpose

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 21, 2019

Jens Schauder commented

This might be helpful/relevant

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 21, 2019

arielcarrera commented

Hi, yes I propose to put a method in CdiRepositoryConfiguration.java like this:

_default Optional<List<RepositoryProxyPostProcessor>> getRepositoryProxyPostProcessorClassList() {_`` _return Optional.empty();_ ``_}_

like this link:

https://github.com/arielcarrera/cdi-spring-data-jpa-test/blob/7d679a5a07062bc8ad149107fbd34abaa17d6f4a/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryConfiguration.java#L85

 

And a change in method applyConfiguration of CdiRepositoryBean to add post processors to the repository factory:

protected static void applyConfiguration(RepositoryFactorySupport repositoryFactory, CdiRepositoryConfiguration configuration) {

....

configuration.getRepositoryProxyPostProcessorClassList().ifPresent(list -> list.forEach(repositoryFactory::addRepositoryProxyPostProcessor));

}

like this link:

https://github.com/arielcarrera/cdi-spring-data-jpa-test/blob/7d679a5a07062bc8ad149107fbd34abaa17d6f4a/src/main/java/org/springframework/data/repository/cdi/CdiRepositoryBean.java#L517

 

 

And an example of usage:

https://github.com/arielcarrera/cdi-spring-data-jpa-test/blob/7d679a5a07062bc8ad149107fbd34abaa17d6f4a/src/main/java/com/github/arielcarrera/cdi/support/config/CustomCdiConfiguration.java#L26

 

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 21, 2019

arielcarrera commented

A real-life use case is to provide a method to add a Custom Transactional Interceptor to the Spring AOT Proxy (like my test project).

(Remember that Spring Data does not provide transaction handling in CDI environments and delegates it to a service layer)

Regards

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 21, 2019

Mark Paluch commented

In CDI it's currently not possible to attach interceptors to beans that are contributed by an extension. Let's add 

default List<RepositoryProxyPostProcessor> getRepositoryProxyPostProcessors()

to our CDI config returning an empty list by default.

While at it, it would also make sense to add QueryCreationListeners in the same manner.

Do you want to submit a pull request along with some tests for this change?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 21, 2019

Mark Paluch commented

Moved this ticket to commons

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 21, 2019

arielcarrera commented

Ok Mark, thank you, I will do this change and submit a PR with some unit tests

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 21, 2019

arielcarrera commented

Hi Mark Paluch, after fight for a while with the code format, I submitted the pull request

#396

 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants