[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - sqlmapper.py:1.4
Shane Hathaway
shane@zope.com
Sun, 18 May 2003 00:16:32 -0400
Update of /cvs-repository/Products/Ape/lib/apelib/zope2
In directory cvs.zope.org:/tmp/cvs-serv23359/zope2
Modified Files:
sqlmapper.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/zope2/sqlmapper.py 1.3 => 1.4 ===
--- Products/Ape/lib/apelib/zope2/sqlmapper.py:1.3 Tue Apr 29 18:11:52 2003
+++ Products/Ape/lib/apelib/zope2/sqlmapper.py Sun May 18 00:16:31 2003
@@ -22,34 +22,22 @@
from apelib.zope2 import basemapper
-def createConnectorMapper(conn):
+def createAbstractMapper():
"""Object mapper factory, with extra return arg for testing purposes
"""
root_mapper = basemapper.createZope2Mapper(0, 1)
- root_mapper.setKeychainGenerator(keygen.SQLKeychainGenerator(conn))
+ root_mapper.setKeychainGenerator(keygen.SQLKeychainGenerator())
- folder_items_gw = structure.SQLFolderItems(conn)
- item_id_gw = structure.SQLItemId(conn)
- remainder_gw = structure.SQLRemainder(conn)
- file_data_gw = structure.SQLObjectData(conn)
- modtime_gw = structure.SQLModTime(conn)
- properties_gw = properties.SQLProperties(conn)
- security_gw = security.SQLSecurityAttributes(conn)
- userlist_gw = security.SQLUserList(conn)
- classification_gw = classification.SQLClassification(conn)
- keychain_gen = keygen.SQLKeychainGenerator(conn)
- gws = (
- folder_items_gw,
- remainder_gw,
- item_id_gw,
- file_data_gw,
- modtime_gw,
- properties_gw,
- security_gw,
- userlist_gw,
- classification_gw,
- keychain_gen,
- )
+ folder_items_gw = structure.SQLFolderItems()
+ item_id_gw = structure.SQLItemId()
+ remainder_gw = structure.SQLRemainder()
+ file_data_gw = structure.SQLObjectData()
+ modtime_gw = structure.SQLModTime()
+ properties_gw = properties.SQLProperties()
+ security_gw = security.SQLSecurityAttributes()
+ userlist_gw = security.SQLUserList()
+ classification_gw = classification.SQLClassification()
+ keychain_gen = keygen.SQLKeychainGenerator()
root_mapper.getClassifier().setGateway(classification_gw)
@@ -128,11 +116,10 @@
root_mapper.checkConfiguration()
- return root_mapper, {'db': conn}, gws
+ return root_mapper
-def createMapper(module_name, params='', kwparams='',
- table_prefix='zodb', volatile=1):
+def createMapper(module_name, **kw):
"""Object mapper factory.
Usage in database configuration file:
@@ -142,8 +129,7 @@
kwparams=
table_prefix=zodb
"""
- # The "volatile" argument is ignored.
- conn = dbapi.DBAPIConnector(
- module_name, params, kwparams, prefix=table_prefix)
- return createConnectorMapper(conn)[:2]
+ mapper = createAbstractMapper()
+ conn = dbapi.DBAPIConnector(module_name, **kw)
+ return mapper, {'db': conn}