[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
| [aspectj-users] How to capture a series of related joinpoints? | 
Hi!  I'm a new AspectJ user and I'm struggling with trying to figure out 
how to capture a "transaction" as a series of related joinpoints.
Imagine a method:
void addActivities() {
 Account a = new Account();
 a.addActivity("Woke up");
 a.addActivity("Went to work"):
 a.addActivity("Ate lunch"):
 a.addActivity("Went home"):
}
What I want to do is encapsulate the 4 calls to addActivity() into a 
single transaction.  Then I can (for example) open a session
at the first call, and close it at the final call.  This allows me to 
avoid opening and closing multiple sessions.
Initially I thought I could use cflowbelow for this, believing that it 
meant "below" in the current method.  My code looked like this:
public aspect ActivityTransaction {
 pointcut InsertActivity(String s): call(void addActivity(String))
                                 && target(Account)
                                 && args(s);
 pointcut StartActivityTransaction(): InsertActivity(String)
                                   && !cflowbelow(InsertActivity(String));
 after(String s) returning : InsertActivity(s) {
   System.out.println("  inserted: " + s);
 }
 void around() : StartActivityTransaction() {
   System.out.println("Activity Transaction Started: " + new Date());
   proceed();
   System.out.println("Activity Transaction Ended:   " + new Date());
 }
However, it calls the around advice on all 4 addActivity() calls.  So, 
now understanding that cflowbelow means "below" in the stacktrace, I'm 
trying to figure out another method to group these related calls from a 
single parent method invocation.
Is there a way to do this in AspectJ?  It seems to me (from my naive 
newbie point of view) to be a valid sort of thing to want to
do.
Thanks for any help!