[z3-checkins] r22105 - in
z3/sqlos/branch/jinty-connection/src/sqlos: . ftests
jinty at codespeak.net
jinty at codespeak.net
Fri Jan 13 13:13:24 CET 2006
Author: jinty
Date: Fri Jan 13 13:12:43 2006
New Revision: 22105
Modified:
z3/sqlos/branch/jinty-connection/src/sqlos/adapter.py
z3/sqlos/branch/jinty-connection/src/sqlos/connection.py
z3/sqlos/branch/jinty-connection/src/sqlos/ftests/connection.txt
Log:
Make changes to the adapter so that it ignores the thread safe pool of
connections that the sqlobject dbconnection maintains. Also fix up the handling
of DatabaseException errors. This brings the number of "thread safe ways of
managing connections" that we use from 3 to 2!!!
With the above changes we can remove the use of the sqlobject Transaction
object for databases that support transactions. This is a preclude to getting
rid of our connection cache.
Seeing as the connection cache will die soon, we rather just test our
connection descripter.
Modified: z3/sqlos/branch/jinty-connection/src/sqlos/adapter.py
==============================================================================
--- z3/sqlos/branch/jinty-connection/src/sqlos/adapter.py (original)
+++ z3/sqlos/branch/jinty-connection/src/sqlos/adapter.py Fri Jan 13 13:12:43 2006
@@ -37,11 +37,38 @@
def makeConnection(self):
return self._connection
+ def getConnection(self):
+ # we override this because we really don't care about sqlobjects idea
+ # of threadsafe pool of db connections. zope.app.rdb takes care of
+ # that for us
+ return self.makeConnection()
+
+ def releaseConnection(self, conn, explicit=False):
+ # we simply lobotomize this method because zope.app.rdb
+ # takes care of all commits/rollbacks as well as all threading issues
+ # with connections
+ pass
+
+ def close(self):
+ # there is no sane way of doing this I can see. It would be nice to
+ # raise an error here, but sqlobject.dbconnection registers this method
+ # to be called when python exits.
+ pass
+
+ def _executeRetry(self, conn, cursor, query):
+ try:
+ return cursor.execute(query)
+ except Exception, exc:
+ raise DatabaseException(str(exc.args))
+
def _runWithConnection(self, meth, *args):
conn = self.getConnection()
try:
try:
val = meth(conn, *args)
+ except DatabaseException:
+ raise # We may have already raised Database exception in
+ # _executeRetry, so we re-raise it
except Exception, exc:
raise DatabaseException, tuple(exc.args)
finally:
@@ -59,7 +86,6 @@
super(MySQLAdapter, self).__init__(connection)
def _executeRetry(*args, **kw):
- # XXX - this should be done for all connections -jinty
try:
return mysqlconnection.MySQLConnection._executeRetry(*args, **kw)
except Exception, exc:
Modified: z3/sqlos/branch/jinty-connection/src/sqlos/connection.py
==============================================================================
--- z3/sqlos/branch/jinty-connection/src/sqlos/connection.py (original)
+++ z3/sqlos/branch/jinty-connection/src/sqlos/connection.py Fri Jan 13 13:12:43 2006
@@ -93,10 +93,7 @@
"name %s. Please verify your setup." % name,
SQLObjectWarning, 3)
conn = IZopeSQLConnection(newconn())
- if conn.supportTransactions:
- connCache[key] = conn.transaction()
- else: # At least MySQL does not support transactions
- connCache[key] = conn
+ connCache[key] = conn
return connCache[key]
Modified: z3/sqlos/branch/jinty-connection/src/sqlos/ftests/connection.txt
==============================================================================
--- z3/sqlos/branch/jinty-connection/src/sqlos/ftests/connection.txt (original)
+++ z3/sqlos/branch/jinty-connection/src/sqlos/ftests/connection.txt Fri Jan 13 13:12:43 2006
@@ -1,21 +1,24 @@
-Here we test how the connections work with threading
+Here we test how the connection descriptor works:
- >>> from sqlos.connection import getConnection, releaseConnection
- >>> from sqlos.interfaces import IConnectionName
- >>> from zope.app import zapi
+ >>> from sqlos.connection import ConnectionDescriptor
+ >>> from sqlos.adapter import ConnectionAdapter
Get the connection name defined in sqlos:
- >>> ut = zapi.getUtility(IConnectionName)
+ >>> class Dummy:
+ ... connection = ConnectionDescriptor()
+ >>> dummy = Dummy()
-Make sure that the connections are released:
+Assert that if we get a the real connection twice, we get the same connection:
- >>> releaseConnection(ut.name)
+ >>> conn1 = dummy.connection.makeConnection()
+ >>> conn2 = dummy.connection.makeConnection()
+ >>> conn1 is conn2
+ True
-Assert that if we get a connection twice, we get the same connection:
+getConnection gives us the same result:
- >>> conn1 = getConnection(None, ut.name)
- >>> conn2 = getConnection(None, ut.name)
+ >>> conn2 = dummy.connection.getConnection()
>>> conn1 is conn2
True
@@ -23,18 +26,10 @@
>>> log = []
>>> def f():
- ... conn = getConnection(None, ut.name)
- ... log.append(conn)
+ ... log.append(dummy.connection.makeConnection())
>>> import threading
>>> thread = threading.Thread(target=f)
>>> thread.start()
>>> thread.join()
>>> log[0] is not conn1
True
-
-Releasing a connection will release it from the current thread:
-
- >>> releaseConnection(ut.name)
- >>> conn = getConnection(None, ut.name)
- >>> conn is not conn1
- True
More information about the z3-checkins
mailing list