[Zope-CVS] CVS: Products/Ape/lib/apelib/zodb3 - storage.py:1.3

Shane Hathaway shane@zope.com
Sun, 18 May 2003 00:17:01 -0400


Update of /cvs-repository/Products/Ape/lib/apelib/zodb3
In directory cvs.zope.org:/tmp/cvs-serv23359/zodb3

Modified Files:
	storage.py 
Log Message:
Made the standard SQL gateways static rather than dependent on a
particular database connection.  This is another step toward
simplifying the configuration of mappers.  The change involved the
following:

- Refactored the query generator to generate only one query at a
time.  Gateways no longer use it directly.  Instead, they ask the
database connection to generate a query.  The database connection
caches the generated query.

- Added a setUp method to gateways.  The setUp method can check the
interface of the connection and/or create tables.

- Consolidated the set up procedure for SQL gateways into setUp().

- Added an argument to the execute() method of SQLGatewayBase so it
can find the connection.

- Arranged for ApeStorage to call gateway.setUp().



=== Products/Ape/lib/apelib/zodb3/storage.py 1.2 => 1.3 ===
--- Products/Ape/lib/apelib/zodb3/storage.py:1.2	Tue Apr 29 18:11:51 2003
+++ Products/Ape/lib/apelib/zodb3/storage.py	Sun May 18 00:16:30 2003
@@ -22,7 +22,7 @@
 
 from ZODB import POSException, BaseStorage
 
-from apelib.core.events import MapperEvent, LoadEvent, StoreEvent
+from apelib.core.events import MapperEvent, GatewayEvent, LoadEvent, StoreEvent
 from apelib.core.interfaces import ITPCConnection
 from apelib.core.exceptions import NoStateFoundError, ConfigurationError
 from consts import HASH0, HASH1, DEBUG
@@ -33,7 +33,7 @@
 class ApeStorage(BaseStorage.BaseStorage):
 
     def __init__(self, mapper_resource, connections,
-                 oid_encoder=None, name=''):
+                 oid_encoder=None, name='', clear_all=0):
         """Initializes an ApeStorage.
 
         mapper_resource is a resource for loading the mapper.
@@ -61,6 +61,7 @@
                 c.connect()
                 opened.append((sort_key, c))
                 names.append(c.getName())
+            self.setUpGateways(clear_all)
         except:
             for sort_key, c in opened:
                 c.close()
@@ -90,6 +91,20 @@
     def getMapperResource(self):
         return self._mapper_resource
 
+    def setUpGateways(self, clear_all=0):
+        """Calls a method of all gateways, passing a GatewayEvent.
+        """
+        root_mapper = self._mapper_resource.access(self)
+        todo = [root_mapper]
+        while todo:
+            mapper = todo.pop()
+            gw = mapper.getGateway()
+            event = GatewayEvent(mapper, None, self._conn_map)
+            gw.setUp(event, clear_all)
+            for name in mapper.listSubMappers():
+                m = mapper.getSubMapper(name)
+                todo.append(m)
+
     def hash64(self, value):
         """Returns an 8-byte hash value.
         """
@@ -211,7 +226,7 @@
         # Try to use the root keychain generator to make a keychain.
         root_mapper = self._mapper_resource.access(self)
         kgen = root_mapper.getKeychainGenerator()
-        event = MapperEvent(root_mapper, ())
+        event = GatewayEvent(root_mapper, (), self._conn_map)
         keychain = kgen.makeKeychain(event, None, 1)
         return self._oid_encoder.encode(keychain)