You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Andrus Adamchik <an...@objectstyle.org> on 2010/11/11 18:46:13 UTC

Contextual callbacks

You may have noticed that I moved cayenne-mixins from github to Apache SVN. Now I am applying the mixin design to a set of real-life problems, and it works pretty well in some scenarios and less so in others (notably the issue with mixin property access code generation is in the later category).

Now I am getting to the interesting area of working with implicit mixin relationships. E.g. an audit object may have an (unmapped, implicit) relationship to a set of unrelated entities based on UUID String stored in an audit object column. UUID looks like "Artist:3487" or "Join:1:2:3", etc. This is essentially vertical inheritance, just without the mapping, and I want to keep it that way instead of creating an open-ended number of subclasses. So meta-ORM...

Problem #1: fetching a list of N Audit objects, prefetching a list of N related auditable objects from M (M <= N) tables. I am solving that with a generic property in Audit and a POST_LOAD callback reading Auditable. I don't want to execute N Auditable queries, instead I would like to prefetch them in batches. To do that, POST_LOAD would record UUID of Audit object, and then when all POST_LOAD's are called, I'd run M prefetch queries organized by Auditable type. But since callbacks are invoked outside a transaction, we don't have a context to gather UUIDs, and don't know when the query ended.

So a few solutions that I see here:

* extend the scope of the Transaction object, and add post-callbacks hook to it. Also add a property map to transaction that would allow user apps to attach arbitrary stuff to it. I wanted to do it some time back. Now is a good occasion.

* create a special callbacks context spanning either POST_<commit> or POST_LOAD, so it would allow to look at all objects processed in a given transaction. It will have its own callback events.

There are probably other solutions as well. Just thinking out loud...

Andrus

 



Re: Contextual callbacks

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Nov 11, 2010, at 7:46 PM, Andrus Adamchik wrote:

> 
> * extend the scope of the Transaction object, and add post-callbacks hook to it. Also add a property map to transaction that would allow user apps to attach arbitrary stuff to it. I wanted to do it some time back. Now is a good occasion.
> 
> * create a special callbacks context spanning either POST_<commit> or POST_LOAD, so it would allow to look at all objects processed in a given transaction. It will have its own callback events.

Ultimately I came up with this solution:

https://issues.apache.org/jira/browse/CAY-1508

I have a local patch already, and combined with CAY-1509, I think annotated DataChannelFilters are going to be a powerful new abstraction allowing to optimize object lifecycle tracking. A few operations are not wrapped by the filter (POST_ADD, PRE_REMOVE, and POST_LOAD when called on rollback), but I think we can go pretty far by wrapping just query and commit ops.

To be sure something similar to channel filters was already achievable since like 1.2 via DataChannel decoration. I know personally I haven't been comfortable with decoration, and I am still reluctant to use it in my apps, so I wanted something that won't interfere with channel/context parent/child relationships. Moreover filters are much more flexible, as they can be installed at runtime without breaking the existing channel/context structure.

Andrus