[Zope] Which method to generate IDs for objects?

Dieter Maurer dieter@handshake.de
Fri, 18 Jan 2002 20:20:54 +0100


Tim Hicks writes:
 > > It is not thread safe and therefore the later "_setObject"
 > > may raise a BadRequest exception due to duplicate ids.
 > >
 > > It is therefore better, to use the "_setObject" directly:
 > >
 > >    while 1:
 > >      try: self._setObject(str(intid),o); break;
 > >      except BadRequest: intid= intid+1
 > 
 > I follow this, and understand the points you both raise.  Dieter, your
 > (partial) solution won't work from a PythonScript though because of the _ in
 > _setObject, right?
Right!

 > ...
 > >    I store the "intid" counter in an object attribute, in order
 > >    not to make so many unsuccessful trials. True, usually,
 > >    ZODB objects should not be used for counting. But I write
 > >    the object anyway (for the new object), thus there is no
 > >    additional penalty to write the counter.
 > 
 > I don't understand why storing the 'intid' in an object attribute cuts down
 > on the unsuccessful trials.  Do you mean storing it persistently in the
 > parent object?
Precisely that.


Dieter