[Erp5-report] r11359 - /erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Nov 17 16:46:13 CET 2006
Author: seb
Date: Fri Nov 17 16:46:11 2006
New Revision: 11359
URL: http://svn.erp5.org?rev=11359&view=rev
Log:
added method isIndexable and beforeUncatalogObject
Modified:
erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
Modified: erp5/trunk/products/ZSQLCatalog/SQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SQLCatalog.py?rev=11359&r1=11358&r2=11359&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SQLCatalog.py (original)
+++ erp5/trunk/products/ZSQLCatalog/SQLCatalog.py Fri Nov 17 16:46:11 2006
@@ -288,6 +288,11 @@
'type' : 'selection',
'select_variable' : 'getCatalogMethodIds',
'mode' : 'w' },
+ { 'id' : 'sql_catalog_delete_uid',
+ 'description' : 'A method to delete a uid value',
+ 'type' : 'selection',
+ 'select_variable' : 'getCatalogMethodIds',
+ 'mode' : 'w' },
{ 'id' : 'sql_catalog_object_list',
'description' : 'Methods to be called to catalog the list of objects',
'type' : 'multiple selection',
@@ -410,6 +415,7 @@
)
sql_catalog_produce_reserved = ''
+ sql_catalog_delete_uid = ''
sql_catalog_clear_reserved = ''
sql_catalog_reserve_uid = ''
sql_catalog_object_list = ()
@@ -835,35 +841,60 @@
uid_list = [x.uid for x in method(count = UID_BUFFER_SIZE, instance_id = instance_id) if x.uid != 0]
self._v_uid_buffer.extend(uid_list)
- def newUid(self):
- """
- This is where uid generation takes place. We should consider a multi-threaded environment
- with multiple ZEO clients on a single ZEO server.
-
- The main risk is the following:
-
- - objects a/b/c/d/e/f are created (a is parent of b which is parent of ... of f)
-
- - one reindexing node N1 starts reindexing f
-
- - another reindexing node N2 starts reindexing e
-
- - there is a strong risk that N1 and N2 start reindexing at the same time
- and provide different uid values for a/b/c/d/e
-
- Similar problems may happen with relations and acquisition of uid values (ex. order_uid)
- with the risk of graph loops
- """
- if withCMF:
- zope_root = getToolByName(self, 'portal_url').getPortalObject().aq_parent
- site_root = getToolByName(self, 'portal_url').getPortalObject()
- else:
- zope_root = self.getPhysicalRoot()
- site_root = self.aq_parent
+ def isIndexable(self):
+ """
+ This is required to check in many methods that
+ the site root and zope root are indexable
+ """
+ zope_root = self.getZopeRoot()
+ site_root = self.getSiteRoot()
root_indexable = int(getattr(zope_root, 'isIndexable', 1))
site_indexable = int(getattr(site_root, 'isIndexable', 1))
if not (root_indexable and site_indexable):
+ return False
+ return True
+
+ def getSiteRoot(self):
+ """
+ Returns the root of the site
+ """
+ if withCMF:
+ site_root = getToolByName(self, 'portal_url').getPortalObject()
+ else:
+ site_root = self.aq_parent
+ return site_root
+
+ def getZopeRoot(self):
+ """
+ Returns the root of the zope
+ """
+ if withCMF:
+ zope_root = getToolByName(self, 'portal_url').getPortalObject().aq_parent
+ else:
+ zope_root = self.getPhysicalRoot()
+ return zope_root
+
+ def newUid(self):
+ """
+ This is where uid generation takes place. We should consider a multi-threaded environment
+ with multiple ZEO clients on a single ZEO server.
+
+ The main risk is the following:
+
+ - objects a/b/c/d/e/f are created (a is parent of b which is parent of ... of f)
+
+ - one reindexing node N1 starts reindexing f
+
+ - another reindexing node N2 starts reindexing e
+
+ - there is a strong risk that N1 and N2 start reindexing at the same time
+ and provide different uid values for a/b/c/d/e
+
+ Similar problems may happen with relations and acquisition of uid values (ex. order_uid)
+ with the risk of graph loops
+ """
+ if not self.isIndexable():
return None
klass = self.__class__
@@ -1020,17 +1051,10 @@
LOG('SQLCatalog', TRACE, 'catalogging %d objects' % len(object_list))
#LOG('catalogObjectList', 0, 'called with %r' % (object_list,))
- if withCMF:
- zope_root = getToolByName(self, 'portal_url').getPortalObject().aq_parent
- site_root = getToolByName(self, 'portal_url').getPortalObject()
- else:
- zope_root = self.getPhysicalRoot()
- site_root = self.aq_parent
-
- root_indexable = int(getattr(zope_root, 'isIndexable', 1))
- site_indexable = int(getattr(site_root, 'isIndexable', 1))
- if not (root_indexable and site_indexable):
- return
+ if not self.isIndexable():
+ return None
+
+ site_root = self.getSiteRoot()
for object in object_list:
path = object.getPath()
@@ -1192,6 +1216,21 @@
if psyco is not None: psyco.bind(catalogObjectList)
+ def beforeUncatalogObject(self, path=None,uid=None):
+ """
+ Set the path as deleted
+ """
+ if not self.isIndexable():
+ return None
+
+ if uid is None and path is not None:
+ uid = self.getUidForPath(path)
+ method_name = self.sql_catalog_delete_uid
+ if uid is None:
+ return None
+ method = getattr(self, method_name)
+ method(uid = uid)
+
def uncatalogObject(self, path=None,uid=None):
"""
Uncatalog and object from the Catalog.
@@ -1205,16 +1244,7 @@
XXX Add filter of methods
"""
- if withCMF:
- zope_root = getToolByName(self, 'portal_url').getPortalObject().aq_parent
- site_root = getToolByName(self, 'portal_url').getPortalObject()
- else:
- zope_root = self.getPhysicalRoot()
- site_root = self.aq_parent
-
- root_indexable = int(getattr(zope_root, 'isIndexable', 1))
- site_indexable = int(getattr(site_root, 'isIndexable', 1))
- if not (root_indexable and site_indexable):
+ if not self.isIndexable():
return None
if uid is None and path is not None:
More information about the Erp5-report
mailing list