[ZODB-Dev] listener on persistent objects
Dieter Maurer
dieter at handshake.de
Thu Apr 24 22:35:23 EDT 2003
heiko hees wrote at 2003-4-23 22:56 +0200:
> we seek to implement an application, which allows external apps to to
> receive events on object change (w/o ZEO).
> since the Persistent-class already tracks object changes, we assume,
> there must be a hook to be notified if any object change occures. any
> hints on using this hook?
It has been "__setattr__" but I think Jim made it now internal to
"Persistent". However, you may still use "__setattr__".
Note, that "__setattr__" is a bit prone to infinite loops.
You must assign to "__dict__" to avoid recursion.
> further we need to determin all parents (objects referencing) of a
> certain Persistent-instance. gc.get_referers([obj]) doesn´t seem to work.
ZODB does not maintain this information.
Your application must do it when it has a need.
> and finally it would be great if we could access a Persistent-instance
> by OID.
That's easy:
If "o" is a persistent objects (already stored in ZODB),
then "o._p_jar" is its ZODB connection reference.
If "c" is a ZODB connection, then "c[oid]" returns the
object with "oid" (or a POSKeyError, if no such object exists).
Dieter
More information about the ZODB-Dev
mailing list