[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] help and ideas on lazy loading thru aspectj
|
Typically you would use cflow()
pointcut p(): someInterestingEvent() && !cflow(adviceexecution());
This will catch interesting events that are not occuring due to executing advice. You are excluding any join points in the control flow of the advice execution.
Andy.
2008/10/28 Luca Ferrari
<fluca1978@xxxxxxxxxxx>
I'm getting near to the solution, but I've got still a few problems. First of
all the pointcut:
pointcut lazyLoaderRequired( LazyLoading loadingProperties, FilteredLoader
mySelf ) :
( get( @LazyLoading Collection<SerializableObject+>+
SerializableObject+.* )
||
get( @LazyLoading Map<SerializableObject+, DatabaseObject+>+
SerializableObject+.* )
)
&&
@annotation( loadingProperties )
&&
this( mySelf )
&&
(! execution( public void FilteredLoader.loadFilteredData(Class) ) ) ;
so I catch any access to a variable that is a plain collection or a map that
has been annotated with @LazyLoading. This works, so I've got the following
advice:
before( LazyLoading loadingProperties, FilteredLoader mySelf) :
lazyLoaderRequired( loadingProperties, mySelf){
// get the annotation properties
Class requiredType = loadingProperties.type();
try{
// load the data only if it has not already been loaded or I must
override the loaded
// data
if( (! this.loadingMap.containsKey(mySelf) ) ||
( loadingProperties.alwaysReload() && this.loadingMap.containsKey(mySelf) )
){
mySelf.loadFilteredData(requiredType);
this.loadingMap.put(mySelf, requiredType);
System.out.println("Lazy loading for the type " + requiredType + " " +
mySelf);
}
else{
System.out.println("not loading " + requiredType + " " + mySelf);
}
}catch(Exception e){
Logger.exception("Exception caught while performing the lazy loading
within the aspect", e);
}
}
So I got the Class type of the collection I need to load, and invoke the
loadFilteredData on the target. The problem is that there's an infinite
recursion. The loadFilteredData method is the following:
public void loadFilteredData(Class type) throws DatabaseException{
// check what kind of data should I load
if( type == null )
return;
try{
if( type.equals(Skill.class) ){
// load the skills
this.refreshSkills();
}
else
if( type.equals(Role.class) ){
// load the roles
this.refreshRoles();
}
else
if( type.equals(KnowledgeLevel.class) ){
// load the knowledge level
this.refreshHires();
}
else
if( type.equals(Hire.class) ){
// load the hires
this.refreshHires();
}
}catch(SQLException e){
Logger.exception("Exception caught while loading filtered data", e);
throw new DatabaseException("Exception caught while loading filtered data
of type " + type);
}
}
I guess the problem is in the loadFIlteredData method, that invokes another
method (e.g., refreshSkills()) that access a variable that is annotated with
@LazyLoading, and so there's the recursion. How should I avoid the recursion,
so excluding everything that happens since loadFilteredData ahead?