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
REST Data with Panache: support of entity event listeners #27994
Conversation
This comment has been minimized.
This comment has been minimized.
Seems reasonable to me. @yrodiere do you also think this makes sense? |
While it might seem reasonable at first glance, there's already a very similar feature available: JPA entity listeners. See 0852b10#diff-7ed082417d8730c92d0dcf5c59e547878a5c298311afbd529f1a5c9591f150cc for a few tests. I'm struggling to see what this brings, beyond duplicating an already available, standard feature? Note it's also more limited:
If it's about getting to manipulate a Uni, then I'd suggest improving Hibernate Reactive so that it supports Uni in JPA entity listeners? |
9734388
to
27d7367
Compare
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.
So I dug up a bit the Git history, and I must say I was wrong: judging from his past contributions to this extensions, @geoand knows more about it than I do :)
Anyway: @gytis was the original creator of this extension, and @Sgitario seems to have contributed the most since then. So... I'll trust him on the functional side :)
On the technical side, I must say I'm doubtful about the benefits of all the renamings, considering the noise it brings to this PR overall, but I guess there are reasons. Other than that I just spotted a few things; I'll let you see if you want to address them, @Sgitario. Thanks!
.../io/quarkus/hibernate/orm/rest/data/panache/deployment/HibernateOrmPanacheRestProcessor.java
Outdated
Show resolved
Hide resolved
...he/hibernate-reactive-rest-data-panache/deployment/src/test/resources/application.properties
Outdated
Show resolved
Hide resolved
I'll try and have a look later on today or tomorrow |
27d7367
to
c95f658
Compare
Yes, I had refactored the entities used in the tests to reuse the same ones, but it's true that it adds lots of noise in the pull request, so I've reverted these changes to the model and will do it in a separate ticket. Hopefully, now the pull request will be easier to review. PR updated. |
...src/main/java/io/quarkus/rest/data/panache/deployment/utils/ResourceMethodListenerUtils.java
Outdated
Show resolved
Hide resolved
c95f658
to
5ce8fc8
Compare
5ce8fc8
to
d178d56
Compare
REST Data with Panache supports the subscription to the following entity events: * Before/After save events * Before/After update events To suscribe to an entity event, you need to provide a bean that implements the interface `EntityEventListener`, for example: ```java @ApplicationScoped public class PeopleEventListener implements EntityEventListener<Person> { @OverRide public void onBeforeSave(Person person) { System.out.println("Before Save Person: " + person.name); } } ``` When using the REST Data Reactive with Panache extension, you will receive the Uni instance of the entity in the after methods: ```java @ApplicationScoped public class PeopleEventListener implements EntityEventListener<Person> { @OverRide public void onAfterSave(Uni<Person> uni) { uni.subscribe().with(person -> { System.out.println("After Save Person: " + person.name); }); } } ``` Fix quarkusio#29095
d178d56
to
523984b
Compare
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.
Great!
Actually I have one more question: Currently the implementation subscribes to the I am not sure what the proper behavior is here. |
When I implemented this feature, I tried first using onItem and didn't work (the listeners were not invoked), but I can try again. Will keep you posted. |
Yeah, if the Uni is not subscribed to by Quarkus (or the user), then nothing will get executed. I am wondering what behavior we really want though... I can see arguments for either way |
I just confirmed that using |
Okay, fine from side :) |
Merging this pull request as all reviewers are ok with these changes. |
REST Data with Panache supports the subscription to the following entity events:
To suscribe to an entity event, you need to provide a bean that implements the interface
EntityEventListener
, for example:When using the REST Data Reactive with Panache extension, you will receive the Uni instance of the entity in the after methods:
Fix #29095