[ZODB] getOID( object )?

Mike C. Fletcher mcfletch at geocities.com
Sun Feb 10 09:40:33 CET 2002


Well, since I haven't heard another approach, I'm going with the 
sub-transaction approach to ensuring the object's storage:

def _storeEvent( self, event ):
     """Creates an oid for the event by storing it during a 
sub-transaction"""
     ### NOTE: this is _not_ thread-safe!!!
     # store the object with a key that's not a possible OID
     self._events[ 0 ] = event
     # end the previous sub-transaction, so that the object has an OID
     get_transaction().commit( 1 )
     self._events[ event.getID() ] = event
     del self._events[ 0 ]
     return event.getID()

Where getID is just returning _p_oid for the Persistence-based objects.

Just in case anyone else ever needs to do the same thing :) .

Enjoy,
Mike

Mike C. Fletcher wrote:
...
> 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.
...
_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/






More information about the Python-list mailing list