On 20/10/2007, at 5:58 AM, Kevin Menard wrote:
> 1) Overly verbose syntax. Consider:
>
> a.setSomething(b);
>
> versus
>
> a.setSomething((BType) a.getObjectContext().localObject
> (b.getObjectId(),
> b));
I have a subclass of CayenneContext in our code with this helper method:
public Persistent localObject(Persistent po) {
if (po != null) {
if (po.getObjectContext() == this) {
return po;
}
return localObject(po.getObjectId(), null);
}
return null;
}
It doesn't completely solve your problem, but it does make the syntax
slightly shorter.
Perhaps another idea with an even simpler syntax for you is a pair of
functions in PersistentObject:
a.copyToContext(newContext)
a.copyToContext(b) // copies to the context of b
Personally I like the way contexts are managed in Cayenne. It is
always clear what context an object is in and there are no hidden
surprises. I can see what Kevin is getting at, but I think to obscure
the copying of objects between contexts will be less clear, not more.
Thinking about what context each object is in is part of working with
an ORM.
It would be great to have the context equivalent to generics: some
indicator which tells the programmer what context an object belongs
to and which doesn't let you (at compile time) relate objects from
different contexts. But I can't see how such a thing is possible.
Ari Maniatis
-------------------------->
Aristedes Maniatis
phone +61 2 9660 9700
PGP fingerprint 08 57 20 4B 80 69 59 E2 A9 BF 2D 48 C2 20 0C C8
This archive was generated by hypermail 2.0.0 : Sat Oct 20 2007 - 19:35:26 EDT