[CalendarServer-changes] [7122] CalendarServer/branches/users/glyph/oracle/twext/enterprise

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 7 19:01:19 PST 2011


Revision: 7122
          http://trac.macosforge.org/projects/calendarserver/changeset/7122
Author:   glyph at apple.com
Date:     2011-03-07 19:01:19 -0800 (Mon, 07 Mar 2011)
Log Message:
-----------
parameterize paramstyle on connection pool

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/adbapi2.py
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/test/test_adbapi2.py

Modified: CalendarServer/branches/users/glyph/oracle/twext/enterprise/adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/twext/enterprise/adbapi2.py	2011-03-08 03:01:07 UTC (rev 7121)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/adbapi2.py	2011-03-08 03:01:19 UTC (rev 7122)
@@ -57,8 +57,9 @@
 
 
 # FIXME: there should be no default for DEFAULT_PARAM_STYLE, it should be
-# discovered dynamically everywhere.  Right now we're only using pgdb so we only
-# support that.
+# discovered dynamically everywhere.  Right now it's specified as an explicit
+# argument to the ConnectionPool but it should probably be determined
+# automatically from the database binding.
 
 DEFAULT_PARAM_STYLE = 'pyformat'
 
@@ -69,9 +70,6 @@
     """
     implements(IAsyncTransaction)
 
-    # See DEFAULT_PARAM_STYLE FIXME above.
-    paramstyle = DEFAULT_PARAM_STYLE
-
     def __init__(self, pool, threadHolder, connection, cursor):
         self._pool       = pool
         self._completed  = True
@@ -80,6 +78,14 @@
         self._holder     = threadHolder
 
 
+    @property
+    def paramstyle(self):
+        """
+        The paramstyle attribute is mirrored from the connection pool.
+        """
+        return self._pool.paramstyle
+
+
     def _reallyExecSQL(self, sql, args=None, raiseOnZeroRowCount=None):
         if args is None:
             args = []
@@ -171,6 +177,7 @@
         return holder.stop()
 
 
+
 class _NoTxn(object):
     """
     An L{IAsyncTransaction} that indicates a local failure before we could even
@@ -179,6 +186,9 @@
     """
     implements(IAsyncTransaction)
 
+    def __init__(self, pool):
+        self.paramstyle = pool.paramstyle
+
     def _everything(self, *a, **kw):
         """
         Everything fails with a L{ConnectionError}.
@@ -201,9 +211,6 @@
 
     implements(IAsyncTransaction)
 
-    # See DEFAULT_PARAM_STYLE FIXME above.
-    paramstyle = DEFAULT_PARAM_STYLE
-
     def __init__(self):
         self._spool = []
 
@@ -257,7 +264,7 @@
 
 
 class _SingleTxn(proxyForInterface(iface=IAsyncTransaction,
-                                     originalAttribute='_baseTxn')):
+                                   originalAttribute='_baseTxn')):
     """
     A L{_SingleTxn} is a single-use wrapper for the longer-lived
     L{_ConnectedTxn}, so that if a badly-behaved API client accidentally hangs
@@ -320,7 +327,7 @@
         Stop waiting for a free transaction and fail.
         """
         self._pool._waiting.remove(self)
-        self._unspoolOnto(_NoTxn())
+        self._unspoolOnto(_NoTxn(self))
 
 
     def _checkComplete(self):
@@ -425,6 +432,7 @@
         super(ConnectionPool, self).__init__()
         self.connectionFactory = connectionFactory
         self.maxConnections = maxConnections
+        self.paramstyle = DEFAULT_PARAM_STYLE
 
         self._free       = []
         self._busy       = []
@@ -495,7 +503,7 @@
         @return: an L{IAsyncTransaction}
         """
         if self._stopping:
-            return _NoTxn()
+            return _NoTxn(self)
         if self._free:
             basetxn = self._free.pop(0)
             self._busy.append(basetxn)

Modified: CalendarServer/branches/users/glyph/oracle/twext/enterprise/test/test_adbapi2.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/twext/enterprise/test/test_adbapi2.py	2011-03-08 03:01:07 UTC (rev 7121)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/test/test_adbapi2.py	2011-03-08 03:01:19 UTC (rev 7122)
@@ -657,4 +657,17 @@
         self.assertEquals(len(self.factory.connections), 2)
 
 
+    def test_propagateParamstyle(self):
+        """
+        Each different type of L{IAsyncTransaction} relays the C{paramstyle}
+        attribute from the L{ConnectionPool}.
+        """
+        TEST_PARAMSTYLE = "justtesting"
+        self.pool.paramstyle = TEST_PARAMSTYLE
+        waittxn = self.pool.connection()
+        self.assertEquals(waittxn.paramstyle, TEST_PARAMSTYLE)
+        self.pool.stopService()
+        notxn = self.pool.connection()
+        self.assertEquals(notxn.paramstyle, TEST_PARAMSTYLE)
 
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110307/d2df4e0c/attachment-0001.html>


More information about the calendarserver-changes mailing list