On Fri, Jun 3, 2011 at 11:58 PM, Igor Drobiazko
<[email protected]> wrote:
> Looks like we need to discuss the "copying annotations to proxies with
> plastic" issue again. I just tried to migrate tapestry-jpa to plastic and
> experience some problems. I didn't commit it because I don't want to break
> the build, so here is an example of CommitAfterMethodAdvice.
>
> public class CommitAfterMethodAdvice implements MethodAdvice
> {
>
> private final EntityManagerManager manager;
>
> public CommitAfterMethodAdvice(final EntityManagerManager manager)
> {
> super();
> this.manager = manager;
> }
>
> public void advise(final MethodInvocation invocation)
> {
> final EntityTransaction transaction = getTransaction(invocation);
>
> if (transaction != null && !transaction.isActive())
> {
> transaction.begin();
> }
>
> try
> {
> invocation.proceed();
> }
> catch (final RuntimeException e)
> {
> if (transaction != null && transaction.isActive())
> {
> transaction.rollback();
> }
>
> throw e;
> }
>
> // Success or checked exception:
>
> if (transaction != null && transaction.isActive())
> {
> transaction.commit();
> }
>
> }
>
> private EntityTransaction getTransaction(final MethodInvocation
> invocation)
> {
> final PersistenceContext annotation =
> invocation.getAnnotation(PersistenceContext.class);
So you're saying that the annotation isn't visible here? I would
think that it would be visible here, on a component class. I'm not as
sure what happens when this advise is used in the context of a service
and a MethodAdviceReceiver.
>
> EntityManager em = JpaInternalUtils.getEntityManager(manager,
> annotation);
>
> if (em == null)
> return null;
>
> return em.getTransaction();
> }
>
> }
>
>
> The problem is invocation.getAnnotation(PersistenceContext.class) which
> always returns null. If I recall it correctly, Plastic doesn't copy
> annotations to proxies, so that my DAO proxies loose the annotations. Here
> is the DAO:
>
> public interface UserDAO
> {
> @CommitAfter
> @PersistenceContext(unitName = AppConstants.TEST_PERSISTENCE_UNIT)
> void add(User user);
>
> .....
> }
>
> What I don't get, is why PlasticClass is able to see the
> @ CommitAfter annotation, but the MethodInvocation of the corresponding
> advise not. Here is the Worker.
>
> public class CommitAfterWorker implements ComponentClassTransformWorker2
> {
> private final CommitAfterMethodAdvice advice;
>
> public CommitAfterWorker(final EntityManagerManager manager)
> {
> advice = new CommitAfterMethodAdvice(manager);
> }
>
> public void transform(PlasticClass plasticClass, TransformationSupport
> support, MutableComponentModel model)
> {
Here, the @CommitAfter is actually on the class. No interface vs.
implementation confusion.
> for (final PlasticMethod method :
> plasticClass.getMethodsWithAnnotation(CommitAfter.class))
> {
> method.addAdvice(advice);
> }
> }
> }
>
>
> Any ideas?
>
> --
> Best regards,
>
> Igor Drobiazko
> http://tapestry5.de
>
--
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!
(971) 678-5210
http://howardlewisship.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]