[Zope] q: How should I get a guaranteed unique id in Zope?

Joe Block jpb@ApesSeekingKnowledge.net
Mon, 14 Jan 2002 21:34:58 -0500


I just discovered Zope a couple of weeks ago, and have started migrating 
a cgi based web application that I was writing in straight python to 
Zope both as a learning exercise and to take advantage of Zope's feature 
set.

My problem is, I have several sql tables that I'm storing data in that I 
need to be able to have the same jobid in because I'm using the jobid to 
match which comments are attached to which jobs.  When I was using cgis, 
this was easy - I made a class that wrapped the following function

         def makeID(self):
                 idstring = "%s-%s.%s-%s" % (self.prefix, os.getpid(), 
time.time(), self.counter)
                 self.counter = self.counter + 1
                 return idstring

and I could be guaranteed their uniqueness because prefix was the 
hostname of the server the cgi was running on, and the combination of 
the other 3 parts was unique per call to makeID.

Now that I'm using Zope, the pid isn't unique any more, of course.  I 
don't want to store a counter in the database, because from some of the 
postings I saw in the last few days here I think it'll cause my db to 
grow for no reason as it stores unwanted undo information.  I also 
haven't figured out how to lock an object while I update properties 
yet.  I don't want to use an external file either, because the constant 
locking & unlocking seems likely to cause performance problems 
eventually.

I have both _The Zope Book_ and _Zope Web Application Development and 
Content Management_ , and haven't found an answer to my problem in 
either book as yet.

I'm running Zope 2.5.0b3 with Python 2.1.1 on Mac OS X 10.1.2

Thanks,

jpb
--
Joe Block <jpb@ApesSeekingKnowledge.net>

Madness takes its toll. Please have exact change ready.