[ZODB-Dev] zodb connection question
Jim Fulton
jim at zope.com
Tue Jul 12 10:00:23 EDT 2005
Jürgen Herrmann wrote:
> [ Jim Fulton wrote:]
>
>>Jürgen Herrmann wrote:
>>
>>>hi all!
>>>
>>>i'm trying to form a patch that will result in a method
>>>"_before_commit()"
>>>being called on each modified object in a transaction (if that method
>>>exists of course) right before commit.
>>>main sense is to automate/delay (re)cataloging.
>>>
>>>first i looked at the Transaction class, as there have been heavy
>>>modifications to it from zodb 3.2 to 3.4
>>
>>Patching is generally a bad idea.
>>
>>I suggest creatinga new catalog (by subclassing or adapting an existing
>>one)
>>that:
>>
>>- queues updates
>>
>>- registers a before-commit callback with the TM on the first update
>> in a transaction
>>
>>- processes the queue in the callback
>>
>>I did this recently for with Zope 3's catalog and it worked very well.
>>(I happend to use subclassing and would use adaptation if I were to
>>do it again.)
>>
>>Jim
>
>
> hi jim!
>
> thanks for your reply, i already thought about such a solution and
> discarded it because it would still be necessary to call a method
> on an object to recatalog it. this step (the programmer's responsibility)
> i want to eliminate for several reasons.
Which are?
> so, what i need is a way to have my mechanism called before transaction
> commits (would be possible to use the hooks provided by zodb 3.4 for
> that, sure) and cycle through all modified objects (that's where the
> hooks in 3.4 are not enough for me, they don't provide any way to access
> a list of modified objects).
I would oppose a per-object callback mechanism. OTOH, I would not
oppose providing enough hooks to allow you to implement such a mechanism
yourself without patching ZODB. Note however, that such a mechanism might
not help you anyway, as discussed below.
> as i showed in my first post, the callback to modified objects works
> as expected, but in the called method i'm not able to acquire the
> responsible Catalog for the modified object.
That's because objects registered are not acquisition wrapped.
> up to what point can i modify objects in a transaction? why doesn't
> acquisition on my objects work in Connection::tpc_begin() ???
The objects are not acquisition wrapped.
IMO, ZODB is way too low a level to do what you want to do.
Note that what you are trying to do would be easier in Zope 3
because Zope 3 relies far less on wrappers for acquisition.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the ZODB-Dev
mailing list