[Zope] Where to store global Property - Incremental ID / Counter

Dieter Maurer dieter@handshake.de
Thu, 12 Sep 2002 23:21:04 +0200


AdvertisingDept writes:
 > I have a ZClass, instances of which will be created in a single Folder, 
 > not throughout the ZopeObject heirarchy. When creating a new instance, I 
 > would like to assign the id in sequential fashion, similar to 
 > take-a-number queing at the Deli counter.
 >    . . . now serving number 1023
 > 
 > I see two ways of doing this:
 > a) have the add method query the folder and find the highest numbered id 
 > ZclassIntanceObject, add one to that value and make that the id of the 
 > next ZClass instance.
 > 
 > b) Create a 'global' property - lastnumberused. Have the add method query 
 > this property and ...
 > 
 > 
 > Which is the better method via Zope?
 > 
 > a) which requires calculations max( container.objectItems() ) - 
 > considering there may be thousands of Zclass instances in this folder.
 > 
 > b) a property 
 >    where to put it - on the container of the instances, or on the parent 
 > ZClass?
I would go for "b)" because it is more efficient.

I would put it on the folder (as it is very difficult to modify
class attributes).

 >    garbage collection - (I've heard something about zope creating but not 
 > disposing of instances each time a property is updated - a la FScounter - 
 > but have no background to discern if this problem applies to my situation)
This is correct, but not a big issue in your case. You change the object
anyway (it will be rewritten to the ZODB). No problem, to change a
property, too.


Dieter