[ZODB] getOID( object )?

Mike C. Fletcher mcfletch at geocities.com
Fri Feb 8 23:38:59 CET 2002


I'm doing some refactoring in a little project here, and realising that 
I'm maintaining duplicate information for my objects to create unique ID 
values.  Since ZODB is maintaining the IDs anyway, I'd like to be able 
to use those instead.

In particular, I have a lot of objects that need to have unique 
identifiers across iterations of the programme (I use these to create 
indices which allow for loading only those items which are seen in the 
current visualisation).  I currently do this by storing an incremented 
index in the database root, and manually assign an ID integer to each 
new object.  This is a really hacky-feeling approach, and I'd like to 
eliminate it entirely.

I read in the developer's documentation that I can use _p_oid if the 
object has already been stored, but I'm wondering if there's a way to 
get the oid _before_ I store the object (since I want to store the index 
information at the same time as the object itself).

Alternately, is there a way to force a Persistence.Persistence-based 
object to be stored immediately (preferably without requiring that I 
commit the whole transaction, as I'm not sure the indexing will work for 
all objects, and may need to abort) so that I can rely on there being a 
_p_oid available?  Could I use a sub-transaction, commit that and then 
use the oid?  It seems a bit of overkill for something this trivial.

By the way, ZODB is _really_ fun to work with.  Automated persistence 
machinery makes visualisation programming very slick-feeling (the GUI is 
just reflecting the object namespace living in the database).

Secondary question: given an oid from the ZODB, is there a readily 
accessible getObject( oid ) method that can go directly to the object? 
Not a big problem, I can just use the oid as keys in a PersistentMapping.

Thoughts appreciated,
Mike
_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/






More information about the Python-list mailing list