Dean,
Here is a snippet of
my code and the error I get. Look at my comments in the code.
@Aspect
public class
JDBCProfilingAspect extends AbstractProfilingAspect
{
@Pointcut("call(*
java.sql.Statement+.execute* (..)) && @withincode(profiling)")
void
profilingSQLExecute(com.xyz.Profiling profiling) {}
@Around("profilingSQLExecute(profiling)")
public
Object profilingSQLExecute(final ProceedingJoinPoint thisJoinPoint, final
com.xyz.Profiling profiling) throws Throwable
{
//
This line gets execute fine and I get the result I want
System.out.println("Class
Name:" + thisJoinPoint.getClass());
//
call to super aspect to get a logger object
//
This like cause java.lang.IncompatibleClassChangeError error
Logger
logger = getLog(thisJoinPoint);
return
thisJoinPoint.proceed();
}
}
@Aspect
public abstract class
AbstractProfilingAspect
{
protected Logger
getLog(final JoinPoint joinPoint)
{
Logger log =
null;
try
{
log =
Logger.getLogger(joinPoint.getSourceLocation().getClass());
}
catch(Exception
ex)
{
//
ignore it...
}
return log;
}
}
I get this exception
in thread "main" java.lang.IncompatibleClassChangeError in getLog
method. If I override this method in my "JDBCProfilingAspect" I don't get this error.
DP
From:
aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Dean Wampler
Sent: Thursday, January 24, 2008
6:43 PM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] How
to access "withincode" type
Can you show us your advice code? thisJoinPoint is of type JoinPoint.
It's an object with context about the join point you're advising. If you want to call other methods on
the same object you're advising or
access the Profiling object's data,
you have to "bind" those objects variables. You're
already doing this with the Profiling object below; the @withincode() binds the
object to the "profiling" variable declared in both the pointcut and
the advice. So, for example, you can call "profiling.value()" in your
advice to get the value in the @Profile instance. Make sense?
On Jan 24, 2008, at 5:25 PM, Parmar, Dipak (IS Consultant) wrote:
Thanks Ramnivas.
It works now. I can see my advice being called. However, I seems like it
introduced a new problem.
In my around advice,
"thisJointPoint" gives me an instance of my aspect which doesn't have all the JointPoint
interface methods.
@Pointcut("call(*
java.sql.Statement+.execute* (..)) && @withincode(profiling)")
void
profilingSQLExecute(com.xyz.Profiling profiling) {}
@Around("profilingSQLExecute(profiling)")
public Object
profilingSQLExecute(final ProceedingJoinPoint thisJoinPoint, final
com.xyz.Profiling profiling) throws Throwable
Sorry if I'm missing something obvious as I
recently started working on AspectJ.
Dipak,
Since the @Profiling annotation is on the caller method (i.e. not on the call
join point itself), you will need the following pointcut:
@Pointcut("call(* java.sql.Statement+.execute*(..)) &&
withincode(@com.xyz.Profiling * *(..)) && @withincode(profiling)")
void profilingSQLExecute(com.xyz.Profiling profiling) {}
Even the following pointcut should work:
@Pointcut("call(* java.sql.Statement+.execute* (..)) &&
@withincode(profiling)")
void profilingSQLExecute(com.xyz.Profiling profiling) {}
-Ramnivas
Thanks Dean.
With your suggested pointcut definition, I get
a compilation error -- name pattern expected.
I don't want the object of the class,
what I want is an instance of the Profiling annotation. I have tried the
below but didn't
execute my Advice.
@Pointcut("call(* java.sql.Statement+.execute*(..))
&& withincode(@com.xyz.Profiling * *(..)) && @annotation(profiling)")void
profilingSQLExecute(com.xyz.Profiling profiling) {}
Dipak
I presume you want the object of the class that implements
"makeProfileDataBaseCall". I'll call the interface that
declares it "ProfileMaker", since I don't know what it's really called. Try this pointcut:
@Pointcut("call(* java.sql.Statement+.execute*(..))
&& withincode(@com.xyz.Profiling * ..ProfileMaker+.*(..)) &&
target(profileMaker) && @annotation(profiling)")
void profilingSQLExecute(ProfileMaker profileMaker, com.xyz.Profiling
profiling) {}
(I forgot what you called the pointcut method before, so I just
made up a name). Note that you use "target()" and
"@annotation" to bind the object and annotation, respectively, to
variables declared in the method. These variables will then be available in the
advice, so you can get the value of the annotation, etc. The advice
method would require the same argument signature.
Notice also that I used "..ProfileMaker+" to refer to
any subclass (i.e., implementer) of the interface and I used ".."
before the name, which is the package wildcard with arbitrarily-deep nesting.
On Jan 24, 2008, at 12:48 PM, Parmar, Dipak (IS Consultant) wrote:
Here is my pointcut definition
@Pointcut("call(*
java.sql.Statement+.execute*(..)) && withincode(@com.xyz.Profiling *
*(..)) ")
Here is my sample mathod
@Profiling(type=ProfilingType.JDBC)
public void makeProfileDataBaseCall() {
.............
CallableStatement statement = connection.prepareCall("{
call PACKAGE.PROCEDURE(?) }");
statement.execute();
........................
}
How I can get an
instance of "makeProfileDataBaseCall"
method and its annotation? "joinPoint.getSignature()"gives the "execute"
method but not "makeProfileDataBaseCall"
method.
If this can't be possible,
then is there a way to re-write the above pointcut
that limit only JDBC
type of profiling.
Thanks,
DP
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users