Update of /cvsroot/webware/Webware/MiddleKit/Core
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23031/Core
Modified Files:
Klass.py Klasses.py
Log Message:
Added new setting UseHashForClassIds defaults to False. When False, class
ids are 1, 2, 3, ... When True, class ids are hashes of their respective
class names which has advantages.
Index: Klass.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Core/Klass.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** Klass.py 19 Feb 2005 22:47:12 -0000 1.29
--- Klass.py 19 Feb 2005 23:14:15 -0000 1.30
***************
*** 5,8 ****
--- 5,9 ----
from MiddleKit.Core.ObjRefAttr import ObjRefAttr
from MiddleDict import MiddleDict
+ from sets import Set
***************
*** 136,140 ****
def setId(self, id):
! self._id = id
--- 137,154 ----
def setId(self, id):
! if isinstance(id, Set):
! # create an id that is a hash of the klass name
! # see Klasses.assignClassIds()
! allIds = id
! limit = 2000000000 # the limit of 2 billion keeps the id easily in the range of a 32 bit signed int without going negative
! id = abs(hash(self.name()) % limit)
! assert id>0 and id<limit
! while id in allIds:
! # adjust for collision
! id += 1
! assert id>0 and id<limit
! self._id = id
! else:
! self._id = id
***************
*** 318,322 ****
from the model.
"""
! return self._klassContainer._model.setting(name, default)
--- 332,336 ----
from the model.
"""
! return self._klassContainer.setting(name, default)
Index: Klasses.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiddleKit/Core/Klasses.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** Klasses.py 19 Feb 2005 22:47:12 -0000 1.18
--- Klasses.py 19 Feb 2005 23:14:16 -0000 1.19
***************
*** 3,6 ****
--- 3,7 ----
from Klass import Klass
from Attr import Attr
+ from MiscUtils import NoDefault
from MiscUtils.DataTable import DataTable
from MiscUtils.DictForArgs import *
***************
*** 56,63 ****
def assignClassIds(self, generator):
! id = 1
! for klass in self._model._allKlassesInOrder:
! klass.setId(id)
! id += 1
--- 57,75 ----
def assignClassIds(self, generator):
! if self.setting('UseHashForClassIds', False):
! # This is better because class ids will likely stay the same even as
! # you change your MiddleKit model. For example, class ids across
! # different sandboxes of your application (development, test and
! # production) would match up even as you add and remove classes.
! # However, renaming classes changes the id!
! from sets import Set
! allIds = Set()
! for klass in self._model._allKlassesInOrder:
! klass.setId(allIds)
! else:
! id = 1
! for klass in self._model._allKlassesInOrder:
! klass.setId(id)
! id += 1
***************
*** 172,175 ****
--- 184,194 ----
return 'ObjRefAttr'
+ def setting(self, name, default=NoDefault):
+ """
+ Returns the value of a particular configuration setting taken
+ from the model.
+ """
+ return self._model.setting(name, default)
+
## Debugging ##
|