Matt <[EMAIL PROTECTED]> wrote:
> Chris, this was my original confusion .... the two places below where you say
> "You can put instances which do not inherit from Persistence.Persistent in
> your database. They just won't "stick". They'll hang around until the
> server is restarted or for an undetermined amount of time during normal
> "No. It'll work for "a while" or until the server is restarted. :-)"
> actually do persist after restarts ... that's what confused me, they wouldn't
> go away and they should!!
I think that the confusion here lies in the word, "Peristent".
Because it uses the standard Python pickling mechanism, the ZODB
can store all kinds of objects (integers, strings, etc., as well
as class instances). The ZODB is, however, broken up into a
collection of individual records, each of which contains a
series of pickles (one per transaction). Objects which are not
"ZODB aware" get stored in the pickle of their container (actually,
the nearest one which *is* persistence-aware).
Deriving your class from Persistence.Persistent says to the
ZODB, "put me in my *own* pickle, not it the pickle of my container".
The other thing Persistence does is hook the '__setattr__' method,
so that changes you make to the object's attributes automatically
register it with Zope's transaction machinery; this registration
means that a new pickle gets saved to the ZODB at the end of the
transaction. Objects which do not derive from Persistence must
handle this registration themselves, or else risk having such
changes be lost whenever they are reloaded.
Globals.PersistentDictionary is a wrapper class which does does
this kind of registration in its '__setitem__' method.
Tres Seaver [EMAIL PROTECTED]
Digital Creations "Zope Dealers" http://www.zope.org
Zope maillist - [EMAIL PROTECTED]
** No cross posts or HTML encoding! **
(Related lists -