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):
security.declareProtected(Permissions.AccessContentsInformation,
'getLatestVersionValue')
def getLatestVersionValue(self, **kw):
def getLatestVersionValue(self):
"""
Return the last generator with the reference
"""
id_tool = getToolByName(self, 'portal_ids', None)
last_id = id_tool._getLatestIdGenerator(self.getReference())
last_version = id_tool._getOb(last_id)
return last_version
id_tool = self.getPortalObject().portal_ids
return id_tool._getLatestGeneratorValue(self.getReference())
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,
'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
Use int to store the last_id, use also a persistant mapping for to be
persistent.
"""
specialise = self.getSpecialiseValue()
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)
return self._getLatestSpecialiseValue().generateNewId(*args, **kw)
security.declareProtected(Permissions.AccessContentsInformation,
'generateNewIdList')
......@@ -92,12 +92,9 @@ class IdGenerator(Base):
# For compatibilty with sql data, must not use id_group as a list
if not isinstance(id_group, str):
raise TypeError, 'id_group is not a string'
specialise = self.getSpecialiseValue()
if specialise is None:
raise ValueError, "the id generator %s doesn't have specialise value" %\
self.getReference()
return specialise.getLatestVersionValue().generateNewIdList(id_group=id_group, \
id_count=id_count, default=default)
return self._getLatestSpecialiseValue().generateNewIdList(id_group=id_group,
id_count=id_count,
default=default)
security.declareProtected(Permissions.ModifyPortalContent,
'initializeGenerator')
......@@ -107,11 +104,7 @@ class IdGenerator(Base):
is created. Some generators will need to do some initialization like
creating SQL Database, prepare some data in ZODB, etc
"""
specialise = self.getSpecialiseValue()
if specialise is None:
raise ValueError, "the id generator %s doesn't have specialise value" %\
self.getReference()
specialise.getLatestVersionValue().initializeGenerator()
self._getLatestSpecialiseValue().initializeGenerator()
security.declareProtected(Permissions.ModifyPortalContent,
'clearGenerator')
......@@ -125,11 +118,7 @@ class IdGenerator(Base):
in this case a particular error will be raised (to be determined and
added here)
"""
specialise = self.getSpecialiseValue()
if specialise is None:
raise ValueError, "the id generator %s doesn't have specialise value" %\
self.getReference()
specialise.getLatestVersionValue().clearGenerator()
self._getLatestSpecialiseValue().clearGenerator()
security.declareProtected(Permissions.ModifyPortalContent,
'exportGeneratorIdDict')
......@@ -137,22 +126,13 @@ class IdGenerator(Base):
"""
Export last id values in a dictionnary in the form { group_id : last_id }
"""
specialise = self.getSpecialiseValue()
if specialise is None:
raise ValueError, "the id generator %s doesn't have specialise value" %\
self.getReference()
return specialise.getLatestVersionValue().exportGeneratorIdDict()
return self._getLatestSpecialiseValue().exportGeneratorIdDict()
security.declareProtected(Permissions.ModifyPortalContent,
'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
another one.
"""
specialise = self.getSpecialiseValue()
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)
return self._getLatestSpecialiseValue().importGeneratorIdDict(*args, **kw)
......@@ -141,8 +141,7 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
"""
Generate the next id in the sequence of ids of a particular group
"""
new_id = self._generateNewId(id_group=id_group, default=default)
return new_id
return self._generateNewId(id_group=id_group, default=default)
security.declareProtected(Permissions.AccessContentsInformation,
'generateNewIdList')
......@@ -150,9 +149,9 @@ class SQLNonContinuousIncreasingIdGenerator(IdGenerator):
"""
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, \
default=default)
return range(new_id - id_count + 1, new_id + 1)
new_id = 1 + self._generateNewId(id_group=id_group, id_count=id_count,
default=default)
return range(new_id - id_count, new_id)
security.declareProtected(Permissions.AccessContentsInformation,
'initializeGenerator')
......
......@@ -75,8 +75,7 @@ class ZODBContinuousIncreasingIdGenerator(IdGenerator):
"""
Generate the next id in the sequence of ids of a particular group
"""
new_id = self._generateNewId(id_group=id_group, default=default)
return new_id
return self._generateNewId(id_group=id_group, default=default)
security.declareProtected(Permissions.AccessContentsInformation,
'generateNewIdList')
......@@ -84,9 +83,9 @@ class ZODBContinuousIncreasingIdGenerator(IdGenerator):
"""
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, \
default=default)
return range(new_id - id_count + 1, new_id + 1)
new_id = 1 + self._generateNewId(id_group=id_group, id_count=id_count,
default=default)
return range(new_id - id_count, new_id)
security.declareProtected(Permissions.AccessContentsInformation,
'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