[Zodb-checkins] CVS: Zope3/lib/python/ZODB - Connection.py:1.60.6.14 DB.py:1.34.4.8

Jeremy Hylton jeremy@zope.com
Wed, 20 Mar 2002 15:25:08 -0500


Update of /cvs-repository/Zope3/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv2608

Modified Files:
      Tag: Zope-3x-branch
	Connection.py DB.py 
Log Message:
Simplify connection between DB and Connection.

The DB object is passed as the first arg to Connection.  Instead of
calling registerDB() every time the Connection is used, do most
initialization in the constructor.  When a Connection is re-used from
the pool, call reset().

Also, remove indirection in DB to create a Connection.





=== Zope3/lib/python/ZODB/Connection.py 1.60.6.13 => 1.60.6.14 ===
     # when we close by putting something here.
 
-    def __init__(self, version='', cache_size=400,
+    def __init__(self, db, version='', cache_size=400,
                  cache_deactivate_after=60):
         """Create a new Connection"""
+        self._db = db
+        self._storage = db._storage
+        self.new_oid = db._storage.new_oid
         self._version = version
         self._cache = cache = Cache(cache_size, cache_deactivate_after)
         self.cacheGC = cache.incrgc
@@ -105,9 +108,6 @@
         
         self._cache_timestamp = _cache_timestamp # set from global
 
-    def db(self):
-        return self._db
-
     def getVersion(self):
         return self._version
         
@@ -286,11 +286,7 @@
         # required by the IPersistentDataManager interface, but unimplemented
         return None
 
-    def registerDB(self, odb):
-        # defined by ZODB.IConnection
-        self._db = odb
-        self._storage = s = odb._storage
-        self.new_oid = s.new_oid
+    def reset(self):
         if self._cache_timestamp != _cache_timestamp:
             # New code is in place.  Start a new cache.
             self._resetCache()
@@ -300,21 +296,12 @@
             self._invalidated.clear()
         self._opened = time.time()
 
-        return self
-
     def close(self):
         self.cacheGC() # This is a good time to do some GC
-        db = self._db
         self.applyCloseCallbacks()
-        # XXX Is it possible for a connection instance to be
-        # associated with different DBs over its lifetime?
-        self._db = None
-        self._storage = None
-        self._tmp = None
-        self.new_oid = None
         self._opened = None
         # Return the connection to the pool.
-        db._closeConnection(self)
+        self._db._closeConnection(self)
 
     # XXX not sure what the callbacks are for, but they're used by Mount
                         


=== Zope3/lib/python/ZODB/DB.py 1.34.4.7 => 1.34.4.8 ===
     of managing objects is done by the connections.
     """
-    klass = Connection
-
     def __init__(self, storage,
                  pool_size=7,
                  cache_size=400,
@@ -368,17 +366,15 @@
                 # This is a temporary connection.
                 # We won't bother with the pools.  This will be
                 # a one-use connection.
-                c=self.klass(
-                    version=version,
-                    cache_size=self._version_cache_size,
-                    cache_deactivate_after=
-                    self._version_cache_deactivate_after)
-                c.registerDB(self)
+                c = Connection(self, version,
+                               cache_size=self._version_cache_size,
+                               cache_deactivate_after=
+                               self._version_cache_deactivate_after)
                 self._temps.append(c)
-                if transaction is not None: transaction[id(c)]=c
+                if transaction is not None:
+                    transaction[id(c)] = c
                 return c
 
-
             pools,pooll=self._pools
 
             # pools is a mapping object:
@@ -419,19 +415,17 @@
                 c=None
                 if version:
                     if self._version_pool_size > len(allocated) or force:
-                        c=self.klass(
-                            version=version,
-                            cache_size=self._version_cache_size,
-                            cache_deactivate_after=
-                            self._version_cache_deactivate_after)
+                        c = Connection(self, version,
+                                       cache_size=self._version_cache_size,
+                                       cache_deactivate_after=
+                                       self._version_cache_deactivate_after)
                         allocated.append(c)
                         pool.append(c)
                 elif self._pool_size > len(allocated) or force:
-                    c=self.klass(
-                        version=version,
-                        cache_size=self._cache_size,
-                        cache_deactivate_after=
-                        self._cache_deactivate_after)
+                    c = Connection(self, version,
+                                   cache_size=self._cache_size,
+                                   cache_deactivate_after=
+                                   self._cache_deactivate_after)
                     allocated.append(c)
                     pool.append(c)
                     
@@ -462,7 +456,7 @@
 
             c=pool[-1]
             del pool[-1]
-            c.registerDB(self)
+            c.reset()
             for pool, allocated in pooll:
                 for cc in pool:
                     cc.cacheGC()