Commit 22902277 authored by Julien Muchembled's avatar Julien Muchembled

Id Tool: refactoring/optimization

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36290 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 92b56d3b
...@@ -55,29 +55,29 @@ class IdGenerator(Base): ...@@ -55,29 +55,29 @@ class IdGenerator(Base):
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getLatestVersionValue') 'getLatestVersionValue')
def getLatestVersionValue(self, **kw): def getLatestVersionValue(self):
""" """
Return the last generator with the reference Return the last generator with the reference
""" """
id_tool = getToolByName(self, 'portal_ids', None) id_tool = self.getPortalObject().portal_ids
last_id = id_tool._getLatestIdGenerator(self.getReference()) return id_tool._getLatestGeneratorValue(self.getReference())
last_version = id_tool._getOb(last_id)
return last_version def _getLatestSpecialiseValue(self):
specialise = self.getSpecialiseValue()
if specialise is None:
raise ValueError("The id generator %r doesn't have specialise value"
% self.getReference())
return specialise.getLatestVersionValue()
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'generateNewId') 'generateNewId')
def generateNewId(self, id_group=None, default=None,): def generateNewId(self, *args, **kw):
""" """
Generate the next id in the sequence of ids of a particular group Generate the next id in the sequence of ids of a particular group
Use int to store the last_id, use also a persistant mapping for to be Use int to store the last_id, use also a persistant mapping for to be
persistent. persistent.
""" """
specialise = self.getSpecialiseValue() return self._getLatestSpecialiseValue().generateNewId(*args, **kw)
if specialise is None:
raise ValueError, "the id generator %s doesn't have specialise value" %\
self.getReference()
return specialise.getLatestVersionValue().generateNewId(id_group=id_group,
default=default)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'generateNewIdList') 'generateNewIdList')
...@@ -92,12 +92,9 @@ class IdGenerator(Base): ...@@ -92,12 +92,9 @@ class IdGenerator(Base):
# For compatibilty with sql data, must not use id_group as a list # For compatibilty with sql data, must not use id_group as a list
if not isinstance(id_group, str): if not isinstance(id_group, str):
raise TypeError, 'id_group is not a string' raise TypeError, 'id_group is not a string'
specialise = self.getSpecialiseValue() return self._getLatestSpecialiseValue().generateNewIdList(id_group=id_group,
if specialise is None: id_count=id_count,
raise ValueError, "the id generator %s doesn't have specialise value" %\ default=default)
self.getReference()
return specialise.getLatestVersionValue().generateNewIdList(id_group=id_group, \
id_count=id_count, default=default)
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'initializeGenerator') 'initializeGenerator')
...@@ -107,11 +104,7 @@ class IdGenerator(Base): ...@@ -107,11 +104,7 @@ class IdGenerator(Base):
is created. Some generators will need to do some initialization like is created. Some generators will need to do some initialization like
creating SQL Database, prepare some data in ZODB, etc creating SQL Database, prepare some data in ZODB, etc
""" """
specialise = self.getSpecialiseValue() self._getLatestSpecialiseValue().initializeGenerator()
if specialise is None:
raise ValueError, "the id generator %s doesn't have specialise value" %\
self.getReference()
specialise.getLatestVersionValue().initializeGenerator()
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'clearGenerator') 'clearGenerator')
...@@ -125,11 +118,7 @@ class IdGenerator(Base): ...@@ -125,11 +118,7 @@ class IdGenerator(Base):
in this case a particular error will be raised (to be determined and in this case a particular error will be raised (to be determined and
added here) added here)
""" """
specialise = self.getSpecialiseValue() self._getLatestSpecialiseValue().clearGenerator()
if specialise is None:
raise ValueError, "the id generator %s doesn't have specialise value" %\
self.getReference()
specialise.getLatestVersionValue().clearGenerator()
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'exportGeneratorIdDict') 'exportGeneratorIdDict')
...@@ -137,22 +126,13 @@ class IdGenerator(Base): ...@@ -137,22 +126,13 @@ class IdGenerator(Base):
""" """
Export last id values in a dictionnary in the form { group_id : last_id } Export last id values in a dictionnary in the form { group_id : last_id }
""" """
specialise = self.getSpecialiseValue() return self._getLatestSpecialiseValue().exportGeneratorIdDict()
if specialise is None:
raise ValueError, "the id generator %s doesn't have specialise value" %\
self.getReference()
return specialise.getLatestVersionValue().exportGeneratorIdDict()
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'importGeneratorIdDict') 'importGeneratorIdDict')
def importGeneratorIdDict(self, id_dict, clear=False): def importGeneratorIdDict(self, *args, **kw):
""" """
Import data, this is usefull if we want to replace a generator by Import data, this is usefull if we want to replace a generator by
another one. another one.
""" """
specialise = self.getSpecialiseValue() return self._getLatestSpecialiseValue().importGeneratorIdDict(*args, **kw)
if specialise is None:
raise ValueError, "the id generator %s doesn't have specialise value" %\
self.getReference()
specialise.getLatestVersionValue().importGeneratorIdDict(id_dict=id_dict,
clear=clear)
...@@ -141,8 +141,7 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): ...@@ -141,8 +141,7 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
""" """
Generate the next id in the sequence of ids of a particular group Generate the next id in the sequence of ids of a particular group
""" """
new_id = self._generateNewId(id_group=id_group, default=default) return self._generateNewId(id_group=id_group, default=default)
return new_id
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'generateNewIdList') 'generateNewIdList')
...@@ -150,9 +149,9 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator): ...@@ -150,9 +149,9 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
""" """
Generate a list of next ids in the sequence of ids of a particular group Generate a list of next ids in the sequence of ids of a particular group
""" """
new_id = self._generateNewId(id_group=id_group, id_count=id_count, \ new_id = 1 + self._generateNewId(id_group=id_group, id_count=id_count,
default=default) default=default)
return range(new_id - id_count + 1, new_id + 1) return range(new_id - id_count, new_id)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'initializeGenerator') 'initializeGenerator')
......
...@@ -75,8 +75,7 @@ class ZODBContinuousIncreasingIdGenerator(IdGenerator): ...@@ -75,8 +75,7 @@ class ZODBContinuousIncreasingIdGenerator(IdGenerator):
""" """
Generate the next id in the sequence of ids of a particular group Generate the next id in the sequence of ids of a particular group
""" """
new_id = self._generateNewId(id_group=id_group, default=default) return self._generateNewId(id_group=id_group, default=default)
return new_id
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'generateNewIdList') 'generateNewIdList')
...@@ -84,9 +83,9 @@ class ZODBContinuousIncreasingIdGenerator(IdGenerator): ...@@ -84,9 +83,9 @@ class ZODBContinuousIncreasingIdGenerator(IdGenerator):
""" """
Generate a list of next ids in the sequence of ids of a particular group Generate a list of next ids in the sequence of ids of a particular group
""" """
new_id = self._generateNewId(id_group=id_group, id_count=id_count, \ new_id = 1 + self._generateNewId(id_group=id_group, id_count=id_count,
default=default) default=default)
return range(new_id - id_count + 1, new_id + 1) return range(new_id - id_count, new_id)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'initializeGenerator') 'initializeGenerator')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment