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
Support @UnitOfWork
outside of Jersey resources
#1361
Support @UnitOfWork
outside of Jersey resources
#1361
Conversation
Personally I don't have any way to test this change even though there's been a lot of chatter about it. Does anyone else have a way to validate this and/or merge it in? |
Extract operations that should be performed on a `@UnitOfWork` method in an aspect. The aspect provides a public API for 3 operations: * Open session/open transaction before a method invocation; * Close session/commit transaction after the method invocation; * Close session/rollback transaction in case of an error. It will allow to create proxies/AOP solutions for handling the `@UnitOfWork` annotation outside of Jersey resources.
Add a factory for creating proxies for components with the `@UnitOfWork` annotations on methods. This will allow to users to use Hibernate data access objects with declarative transactions outside Jersey resources. A new created proxy will: * detect the annotation on a component method; * open a transaction before starting the method; * commit the transcation after ending the method; * rollback tre transaction in a case of a faulure; Javassist is used for the proxy generation. Resolves #1334, #1240
A simple way to test this is to try to use |
@harshil07, @paukiatwee, @dotCipher, @yiweig, @vvondra can anyone confirm if this PR resolves your issue? |
Happy to test @jplock but I'm not entirely sure on how to build the module for java 8. |
This PR is against the 0.9 branch, which still uses Java 7. Something like this should work, though. git checkout -b arteam-generalize_unit_of_work release/0.9.x
git pull https://github.com/arteam/dropwizard.git generalize_unit_of_work
cd ./dropwizard-bom
mvn install
cd ../
mvn install -DskipTests=true -P dev |
@jplock In the end, since I use dropwizard-guice, I went with a simple proxy using https://github.com/google/guice/wiki/AOP or I actually inject a TransactionProvider class which has a method I can pass a callback to which will be executed transactionally |
I tested this PR and it is working! Passed all my tests. My app at Github. Set up
Authenticator
Previously |
Excellent! Thank you for confirming @paukiatwee. |
Support `@UnitOfWork` outside of Jersey resources
@arteam are you going to cherry pick this into |
Yes, will do. |
@dropwizard/committers, what do you think about releasing 0.9.2 with this workaround? |
+1 from me |
+1 Thanks & Regards On Tue, Jan 12, 2016 at 10:19 PM, Justin Plock notifications@github.com
|
+1 |
This PR provides the ability to use the
@UnitOfWork
annotation outside of Jersey resources.It consists from two changes:
@UnitOfWork
methods fromUnitOfWorkApplicationListener
into an aspect. It allows to perform these operations outside of the listener (for example, in proxies or AOP providers).@UnitOfWork
aware proxies. A created proxy willdetect the annotation on component methods and will open/close a Hibernate session around them.
It uses aforementioned aspect for this. Javassist is used for creating proxies, because it has a
simple API for that and it's shipped with Hibernate.
Now to use
@UnitOfWork
in authenticators, one need just to create proxy like this:This change is intended to 0.9.* branch. Reference issues: #1334 , #1240