Hi!

Some time ago we discussed whether we could add extra information on an 
Association. At the time we concluded no, but I have had a discussion 
about it again with a fellow Jaywayer. Here's an alternative syntax that 
might work.

Instead of making specialized subtypes of ManyAssociation and 
Association we could simply introduce something that can be referenced 
and which includes both the associated object and the properties for the 
association. Example:
interface Movie
{
   ManyAssociation<AssociationRole<Actor,ActorRole>> actors();
}

interface ActorRole
{
   Property<String> roleName();
}

with this one could do:
Actor superstar = ...;
ActorRole villain = ...;
movie.actors().add(new AssociationRole(superstar,villain));

where AssociationRole looks something like
public final class AssociationRole<A,R>
{
   A association;
   R role;

   public AssociationRole(A a, R r)
   {
     association = a;
     role = r;
   }

   public A association();
   public R role();
}

Making it a class instead of an interface makes it easy for EntityStores 
to detect it during storing and create new instances of it during 
loading, and also makes it trivial to instantiate new roles in client 
code as above. If the R side points to another Entity it is even 
possible to update that without having to "re-set" the AssociationRole. 
If it points to a value-object the owning association would have to be 
set again whenever it is to be updated. Both have pros and cons.

What say ye? Emil, how would this map to Neo for example?

Also, what would this do to indexing/querying? How hard would it be to 
make it work do you think?

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to