Skip to main content

[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

You can try using a perthis aspect and use declare parents to add the
required interface.  You will need to annotate the fields that are
lazy loaded.  Here's a sketch of what it might look like:

public aspect LazyLoader perthis(SerializableObject) {

  public interface FilteredSerializableObject<T>{
       public List<T> loadFiltered(SerializableObject owner);
  }

  declare parents <list_of_types> implements FilteredSerializableObject<T>;

   public List<T>
FilteredSerializableObject.loadFiltered(SerializableObject owner) {
    if (!this.hasBeenLoaded) {
      <implement_method>  // delegate to owner???
      hasBeenLoaded = true;
    }
  }
  privater boolean FilteredSerializableObject.hasBeenLoaded = false;

  before(FilteredSerializableObject obj) : get(@LazyLoaded
SerializableObject+.*) && target(obj) {
    obj.loadFiltered(aspectOf());  // not quite right because field is
initially null
  }

}

This won't work exactly, but maybe this will give you an idea on how
to get started.


Back to the top