[z3-checkins] r19454 - in z3/sqlos/branch/andres-db/src/sqlos: .
interfaces
andres at codespeak.net
andres at codespeak.net
Thu Nov 3 02:01:57 CET 2005
Author: andres
Date: Thu Nov 3 02:01:56 2005
New Revision: 19454
Modified:
z3/sqlos/branch/andres-db/src/sqlos/configure.zcml
z3/sqlos/branch/andres-db/src/sqlos/connection.py
z3/sqlos/branch/andres-db/src/sqlos/interfaces/__init__.py
Log:
Implemented one idea how it could work. It does. At least for Postgres. But its not really nice.
Modified: z3/sqlos/branch/andres-db/src/sqlos/configure.zcml
==============================================================================
--- z3/sqlos/branch/andres-db/src/sqlos/configure.zcml (original)
+++ z3/sqlos/branch/andres-db/src/sqlos/configure.zcml Thu Nov 3 02:01:56 2005
@@ -131,19 +131,26 @@
/>
</class>
- <!--
- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- For now, you need to change the factory here if you want
- to use a diferent connection type.
- XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
-
<adapter
- provides=".interfaces.IZopeSQLConnection"
+ provides=".interfaces.IZopePsycopgConnection"
for="zope.app.rdb.interfaces.IZopeConnection"
permission="zope.Public"
factory=".adapter.PostgresAdapter"
/>
- -->
+
+ <adapter
+ provides=".interfaces.IZopeMySQLdbConnection"
+ for="zope.app.rdb.interfaces.IZopeConnection"
+ permission="zope.Public"
+ factory=".adapter.MySQLAdapter"
+ />
+
+ <adapter
+ provides=".interfaces.IZopePysqlite2Connection"
+ for="zope.app.rdb.interfaces.IZopeConnection"
+ permission="zope.Public"
+ factory=".adapter.SQLiteAdapter"
+ />
<adapter
provides="zope.app.container.interfaces.INameChooser"
Modified: z3/sqlos/branch/andres-db/src/sqlos/connection.py
==============================================================================
--- z3/sqlos/branch/andres-db/src/sqlos/connection.py (original)
+++ z3/sqlos/branch/andres-db/src/sqlos/connection.py Thu Nov 3 02:01:56 2005
@@ -17,7 +17,8 @@
from zope.app import zapi
from zope.app.rdb.interfaces import IZopeDatabaseAdapter
-from sqlos.interfaces import IZopeSQLConnection, IConnectionName
+from sqlos.interfaces import IConnectionName,IZopePysqlite2Connection
+from sqlos.interfaces import IZopePsycopgConnection, IZopeMySQLdbConnection
class SQLObjectWarning(UserWarning):
@@ -58,6 +59,21 @@
# This code was heavily based on ZODB.Transaction
connCache = {}
+def fuzzyGetConnection(conn):
+ connid = str(type(conn))
+ if connid.startswith("<class 'sqlitedbda"):#XXX is that correct?
+ return IZopePysqlite2Connection(conn())
+
+ elif connid.startswith("<class 'mysqldbda"):
+ return IZopeMySQLdbConnection(conn())
+
+ elif connid.startswith("<class 'psycopgda"):
+ return IZopePsycopgConnection(conn())
+
+ else:
+ raise NotImplementedError('Not adapter written or fuzzy logic has gone wild')
+
+
try:
import thread
except:
@@ -71,7 +87,8 @@
warnings.warn("Couldn't find a rdb connection by the "
"name %s. Please verify your setup." % name,
SQLObjectWarning, 3)
- connCache[name] = IZopeSQLConnection(newconn())
+ connCache[name] = fuzzyGetConnection(newconn)
+
return connCache[name]
def releaseConnection(name):
@@ -91,13 +108,12 @@
if newconn is None:
warnings.warn("Couldn't find a rdb connection by the "
"name %s. Please verify your setup." % name,
- SQLObjectWarning, 3)
- conn = IZopeSQLConnection(newconn())
+ SQLObjectWarning, 3)
+ conn = fuzzyGetConnection(newconn)
if conn.supportTransactions:
connCache[key] = conn.transaction()
else: # At least MySQL does not support transactions
connCache[key] = conn
-
return connCache[key]
def releaseConnection(name):
Modified: z3/sqlos/branch/andres-db/src/sqlos/interfaces/__init__.py
==============================================================================
--- z3/sqlos/branch/andres-db/src/sqlos/interfaces/__init__.py (original)
+++ z3/sqlos/branch/andres-db/src/sqlos/interfaces/__init__.py Thu Nov 3 02:01:56 2005
@@ -154,6 +154,15 @@
class IZopeSQLConnection(ISQLConnection):
""" """
+class IZopePsycopgConnection(ISQLConnection):
+ """ """
+
+class IZopeMySQLdbConnection(ISQLConnection):
+ """ """
+
+class IZopePysqlite2Connection(ISQLConnection):
+ """ """
+
class ISQLAttributeAnnotatable(IAttributeAnnotatable):
"""
Store annotations in the annotations table, keyed by
More information about the z3-checkins
mailing list