Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Inter-type declaration of constructor using annotations

Hi,

I'm currently working on a object-relational mapper using annotations.
Here is a simple example of a persistable class.

@Persistent
public class Article {
   private Person author;

   public Article(Person anAuthor) {
       author = anAuthor;
   }
}

The main problem is that there are two kinds of object construction in
context of OR mapping. Creating a new object that will be inserted into
DB and loading an object from DB. So you need two constructors for a
persistable class.

@Persistent
public class Article {
   private Person author;

   public Article(Transfer transfer) {
       // load data from transfer to entities
   }

   public Article(Person anAuthor) {
       author = anAuthor;
   }
}

I would like to introduce this new "transfer" constructor using
inter-type declarations. Is it possible? I have tried various things:

1)  There is no way to use
public (@Persistent *).new(Transfer transfer) {...}

2) If I create a PersistentRoot class with transfer constructor and use
declare parents : @Perstistent * extends PersistentRoot;

then I cannot use this constructor when creating subclasses. new Article(Transfer transfer); is not usable.

3) With mentioned PersistentRoot I must add constructor to every persistent class by hand.

public Article.new(Transfer transfer) { super(transfer); }

Which is the only working way I have found, but its really ugly hack.

I am new to AspectJ so probably I am missing something. Any ideas?



Back to the top