[Erp5-report] r36290 jm - /erp5/trunk/products/ERP5/Document/

nobody at svn.erp5.org nobody at svn.erp5.org
Sat Jun 12 18:49:30 CEST 2010


Author: jm
Date: Sat Jun 12 18:49:29 2010
New Revision: 36290

URL: http://svn.erp5.org?rev=36290&view=rev
Log:
Id Tool: refactoring/optimization

Modified:
    erp5/trunk/products/ERP5/Document/IdGenerator.py
    erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py
    erp5/trunk/products/ERP5/Document/ZODBContinuousIncreasingIdGenerator.py

Modified: erp5/trunk/products/ERP5/Document/IdGenerator.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/IdGenerator.py?rev=36290&r1=36289&r2=36290&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/IdGenerator.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/IdGenerator.py [utf8] Sat Jun 12 18:49:29 2010
@@ -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)

Modified: erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py?rev=36290&r1=36289&r2=36290&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/SQLNonContinuousIncreasingIdGenerator.py [utf8] Sat Jun 12 18:49:29 2010
@@ -141,8 +141,7 @@ class SQLNonContinuousIncreasingIdGenera
     """
       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 SQLNonContinuousIncreasingIdGenera
     """
       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')

Modified: erp5/trunk/products/ERP5/Document/ZODBContinuousIncreasingIdGenerator.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/ZODBContinuousIncreasingIdGenerator.py?rev=36290&r1=36289&r2=36290&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/ZODBContinuousIncreasingIdGenerator.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/ZODBContinuousIncreasingIdGenerator.py [utf8] Sat Jun 12 18:49:29 2010
@@ -75,8 +75,7 @@ class ZODBContinuousIncreasingIdGenerato
     """
       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 ZODBContinuousIncreasingIdGenerato
     """
       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')




More information about the Erp5-report mailing list