[ZODB-Dev] Persistent sub-objects: noob question

Jeremy Hylton jeremy at zope.com
Sat Jan 17 18:38:29 EST 2004


On Sat, 2004-01-17 at 18:21, Paul Winkler wrote:
> > > Given this class:
> > > 
> > > class Foo(Persistent):
> > >     def __init__(self):
> > >         self.bar = OOBTree()
> > > 
> > >     def store(self, key, value):
> > >         self.bar[value] = key
> > >         self._p_changed = 1  # redundant
[snip]
> > > - Or does it cause an unnecessary copy of the entire OOBTree
> > > to be saved?
> > 
> > No.  The BTree is already marked as change.  More specifically, some
> > part of the BTree is marked as changed.  For a large tree, it will
> > usually mark just a single bucket as changed.
> 
> OK, so then self._p_changed = 1 only affects
> non-Persistent attributes?

Sort of.  It only affects self.  Each object that is an instance of
Persistent, including the various BTrees, are stored in separate
database records.  Any other object reachable from the Persistent
instance is stored in the same database record.  The _p_changed
attribute marks a specific Persistent instance as changed.

A bit of terminology is helpful:  self and self.bar are first-class
persistent objects.  They have their own oids, can be named explicitly,
and are stored in their own record.  A hypothetical "self.baz = 12" is a
second-class persistent object.  It is persisted in the database, but
doesn't have an oid and can't be accessed separately from its container.

Jeremy





More information about the ZODB-Dev mailing list