Commit fc160321 authored by Ayush Tiwari's avatar Ayush Tiwari Committed by Ayush Tiwari

Products.ZSQLCatalog.SQLcatalog: Add function to get normal or deferred connection id for catalog

And, change in files where this was being used
parent 77d399f9
......@@ -115,12 +115,7 @@ class Inventory(Delivery):
if sql_catalog_id is not None:
# try to get connection used in the catalog
catalog = portal.portal_catalog[sql_catalog_id]
for method in catalog.objectValues():
if method.meta_type == "Z SQL Method":
if 'deferred' not in method.connection_id \
and 'transactionless' not in method.connection_id:
connection_id = method.connection_id
break
connection_id = catalog.getConnectionId()
default_inventory_calculation_list = ({ "inventory_params" : {"section": self.getDestinationSection(),
"node" : self.getDestination(),
......
......@@ -126,16 +126,9 @@ class ArchiveTool(BaseTool):
# Guess connection id from current catalog
source_catalog = portal_catalog.getSQLCatalog()
source_catalog_id = source_catalog.getId()
if source_connection_id is None or source_deferred_connection_id is None:
for method in source_catalog.objectValues():
if method.meta_type == "Z SQL Method":
if source_deferred_connection_id is None and 'deferred' in method.connection_id:
source_deferred_connection_id = method.connection_id
elif source_connection_id is None and 'transactionless' not in method.connection_id:
source_connection_id = method.connection_id
if source_connection_id is not None and \
source_deferred_connection_id is not None:
break
source_connection_id = source_catalog.getConnectionId()
source_deferred_connection_id = source_catalog.getConnectionId(deferred=True)
if source_connection_id is None or source_deferred_connection_id is None:
raise ValueError, "Unable to determine connection id for the current catalog"
......
......@@ -2801,6 +2801,26 @@ class Catalog(Folder,
return filter_dict
return None
security.declarePublic('getConnectionId')
def getConnectionId(self, deferred=False):
"""
Returns the 'normal' connection being used by the SQL Method(s) in this
catalog.
If 'deferred' is True, then returns the deferred connection
"""
for method in self.objectValues():
if method.meta_type in ['Z SQL Method',]:
if deferred:
if 'deferred' in method.connection_id:
return method.connection_id
else:
continue
else:
if 'deferred' in method.connection_id:
continue
else:
return method.connection_id
security.declarePrivate('getFilterableMethodList')
def getFilterableMethodList(self):
"""
......
  • I think this is ahack, so the method should be documented as being a hack (it should log a deprecation warning and the docstring should tell about the depreciation).

    This is nothing new, of course, and this change is good in that it factorises two hacks into a single one - progress ! But still, needing the new method is dubious: there may be more than 2 connections used by ZSQLMethods in a catalog, I believe. At least, technically nothing prevents it, and I know ERP5 instances where we do have more than 2. Also, relying on connection name to guess its properties is dirty. But I have no better idea.

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