[Zope-Checkins] CVS: Zope/lib/python/Shared/DC/ZRDB - DA.py:1.105.4.1 TM.py:1.10.4.1

Chris McDonough chrism@zope.com
Sun, 24 Nov 2002 18:43:51 -0500


Update of /cvs-repository/Zope/lib/python/Shared/DC/ZRDB
In directory cvs.zope.org:/tmp/cvs-serv10098/DC/ZRDB

Modified Files:
      Tag: chrism-install-branch
	DA.py TM.py 
Log Message:
Merge with HEAD.


=== Zope/lib/python/Shared/DC/ZRDB/DA.py 1.105 => 1.105.4.1 ===
--- Zope/lib/python/Shared/DC/ZRDB/DA.py:1.105	Wed Aug 14 17:50:59 2002
+++ Zope/lib/python/Shared/DC/ZRDB/DA.py	Sun Nov 24 18:43:49 2002
@@ -74,6 +74,7 @@
     _zclass=None
     allow_simple_one_argument_traversal=None
     template_class=SQL
+    connection_hook=None
 
     manage_options=(
         (
@@ -183,7 +184,7 @@
 
     def manage_advanced(self, max_rows, max_cache, cache_time,
                         class_name, class_file, direct=None,
-                        REQUEST=None, zclass=''):
+                        REQUEST=None, zclass='', connection_hook=None):
         """Change advanced properties
 
         The arguments are:
@@ -230,6 +231,8 @@
         self._v_brain=getBrain(self.class_file_, self.class_name_, 1)
         self.allow_simple_one_argument_traversal=direct
 
+        self.connection_hook = connection_hook
+
         if zclass:
             for d in self.aq_acquire('_getProductRegistryData')('zclasses'):
                 if ("%s/%s" % (d.get('product'),d.get('id'))) == zclass:
@@ -341,7 +344,11 @@
     def _searchable_result_columns(self): return self._col
 
     def _cached_result(self, DB__, query):
-
+        pure_query = query
+        # we need to munge the incoming query key in the cache
+        # so that the same request to a different db is returned
+        query += '\nDBConnId: %s' % self.connection_hook
+        
         # Try to fetch from cache
         if hasattr(self,'_v_cache'): cache=self._v_cache
         else: cache=self._v_cache={}, Bucket()
@@ -364,7 +371,8 @@
             k, r = cache[query]
             if k > t: return r
 
-        result=apply(DB__.query, query)
+        # call the pure query
+        result=apply(DB__.query, pure_query)
         if self.cache_time_ > 0:
             tcache[int(now)]=query
             cache[query]= now, result
@@ -389,11 +397,18 @@
                 if hasattr(self, 'REQUEST'): REQUEST=self.REQUEST
                 else: REQUEST={}
 
-        try: dbc=getattr(self, self.connection_id)
+        # connection hook
+        c = self.connection_id
+        # for backwards compatability
+        hk = self.connection_hook
+        # go get the connection hook and call it
+        if hk: c = getattr(self, hk)()
+           
+        try: dbc=getattr(self, c)
         except AttributeError:
             raise AttributeError, (
                 "The database connection <em>%s</em> cannot be found." % (
-                self.connection_id))
+                c))
 
         try: DB__=dbc()
         except: raise 'Database Error', (


=== Zope/lib/python/Shared/DC/ZRDB/TM.py 1.10 => 1.10.4.1 ===
--- Zope/lib/python/Shared/DC/ZRDB/TM.py:1.10	Wed Aug 14 17:50:59 2002
+++ Zope/lib/python/Shared/DC/ZRDB/TM.py	Sun Nov 24 18:43:50 2002
@@ -17,12 +17,15 @@
 class TM:
     """Mix-in class that provides transaction management support
 
-    A sub class should call self._register() whenever it performs
-    any transaction-dependent operations (e.g. sql statements).
+    A sub class should call self._register() whenever it performs any
+    transaction-dependent operations (e.g. sql statements).
 
-    The sub class will need to override _finish, to finallize work,
-    _abort, to roll-back work, and perhaps _begin, if any work is needed
-    at the start of a transaction.
+    The sub class will need to override _finish, to finalize work,
+    _abort, to roll-back work, and perhaps _begin, if any work is
+    needed at the start of a transaction.
+
+    A subclass that uses locking during transaction commit must
+    defined a sortKey() method.
     """
 
     _registered=None