Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Quick Question

I believe you can try the adviceexecution() pointcut.  Since you are
using around advice, the runtime will always know when it is inside
advice.

So, something like this:

void around(SuppressableQuery query) : execution(protected void
   SimpleQuery.appendConstraints()) && this(query) &&
!cflow(adviceexecution() { ... }


However, there is a chance that the compiler might be doing something
that is too smart and it might try to convert around advice into
before advice (although probably wouldn't happen in this case).

On Thu, Dec 11, 2008 at 1:28 PM, Dave Whittaker <dave@xxxxxxxxxx> wrote:
> How would I fashion a point cut that matched a method invocation only if it
> had not already been applied to an overridden form of that method in a
> superclass?  For instance in one project I have:
>
> public class SimpleQuery{
>
>        public void appendConstraints(){
>                ..add default constraints..
>        }
>
> }
>
> public interface SuppressableQuery{
>
>        ...some stuff relevant to suppression...
>
> }
>
> public aspect SuppressableQueryAspect{
>
>        void around(SuppressableQuery query) : execution(protected void
> SimpleQuery.appendConstraints()) && this(query) {
>                /* Not really important what this does, just when it is
> applied */
>                if(query.getSuppressed() != null){
>                        query.addClause(
>                                        (query.getSuppressed() ? "" : "NOT ")
> + "EXISTS (SELECT suppression.partitionId " +
>                                        "FROM " +
> query.getSuppressionType().getName() +
>                                        " suppression WHERE
> suppression.partitionId IN (:suppressionOrder) " +
>                                        "AND suppression.entity = " +
> query.getSuppressedEntityField() + ")");
>                        query.addParameter("suppressionOrder",
> query.getSuppressionOrder());
>                }
>                proceed(query);
>        }
>
> }
>
> Then in another project with a jar containing the jar from the first project
> on the aspect path:
>
> public class ProfileQuery extends SimpleQuery<Profile> implements
>        PartitionedQuery<Profile>, SuppressableQuery<Profile> {
>
>        @Override
>        protected void appendConstraints() {
>                super.appendConstraints();
>                if(onetOccupationStub != null){
>                        addClause(alias("delegate") + " =
> :onetOccupationStub");
>                        addParameter("onetOccupationStub",
> onetOccupationStub);
>                }
>        }
>
> }
>
> What I'm seeing is that  the clause is added to the query twice, when I only
> want it to match one invocation of appendConstraints, in this case the one
> in ProfileQuery.  Can that be done?
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top