[ZODB-Dev] zodb4: adding an object before transaction commit

Steve Alexander steve at z3u.com
Mon Oct 6 11:13:55 EDT 2003


This message is about adding a feature to ZODB 4.

I want to do some things with the oids of persistent objects, such as 
use them as keys in a BTree.

The thing is that an object doesn't get an oid until it is added to the 
database, and a transaction is committed.

I'd like a way of saying to a data manager (_p_jar) that I intend to add 
an object to the database, so the data manager can provide that object 
with a suitable _p_jar and _p_oid. The oid would remain as set if the 
object is attached to the database's root object (possibly via other 
objects), and a transaction comimtted.

I chatted briefly with Jim Fulton about this. An API such as 
Connection.add(object) was suggested. For example:

   >>> f = Foo()
   >>> f
   <Some persistent object>
   >>> f._p_oid
   >>> f._p_jar
   >>> root_object._p_jar.add(f)
   >>> f._p_oid
   'somevalidoid'
   >>> f._p_jar
   <some valid Connection>

I guess 'add' would raise a TypeError if the object you want to add is 
not a Persistent object.

--
Steve Alexander





More information about the ZODB-Dev mailing list