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

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


Revision: 7123
          http://trac.macosforge.org/projects/calendarserver/changeset/7123
Author:   glyph at apple.com
Date:     2011-03-07 19:01:31 -0800 (Mon, 07 Mar 2011)
Log Message:
-----------
placeholder for the connection pool's awareness of the dialect.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/adbapi2.py
    CalendarServer/branches/users/glyph/oracle/twext/enterprise/ienterprise.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:19 UTC (rev 7122)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/adbapi2.py	2011-03-08 03:01:31 UTC (rev 7123)
@@ -53,16 +53,31 @@
 from twisted.internet.defer import succeed
 from twext.enterprise.ienterprise import ConnectionError
 from twisted.internet.defer import fail
-from twext.enterprise.ienterprise import AlreadyFinishedError, IAsyncTransaction
+from twext.enterprise.ienterprise import (
+    AlreadyFinishedError, IAsyncTransaction, POSTGRES_DIALECT
+)
 
 
-# FIXME: there should be no default for DEFAULT_PARAM_STYLE, it should be
+# FIXME: there should be no defaults for connection metadata, it should be
 # 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'
+DEFAULT_DIALECT = POSTGRES_DIALECT
 
+
+def _forward(thunk):
+    """
+    Forward an attribute to the connection pool.
+    """
+    @property
+    def getter(self):
+        return getattr(self._pool, thunk.func_name)
+    return getter
+
+
+
 class _ConnectedTxn(object):
     """
     L{IAsyncTransaction} implementation based on a L{ThreadHolder} in the
@@ -78,14 +93,19 @@
         self._holder     = threadHolder
 
 
-    @property
+    @_forward
     def paramstyle(self):
         """
         The paramstyle attribute is mirrored from the connection pool.
         """
-        return self._pool.paramstyle
 
+    @_forward
+    def dialect(self):
+        """
+        The dialect attribute is mirrored from the connection pool.
+        """
 
+
     def _reallyExecSQL(self, sql, args=None, raiseOnZeroRowCount=None):
         if args is None:
             args = []
@@ -188,13 +208,16 @@
 
     def __init__(self, pool):
         self.paramstyle = pool.paramstyle
+        self.dialect = pool.dialect
 
+
     def _everything(self, *a, **kw):
         """
         Everything fails with a L{ConnectionError}.
         """
         return fail(ConnectionError())
 
+
     execSQL = _everything
     commit  = _everything
     abort   = _everything
@@ -327,7 +350,7 @@
         Stop waiting for a free transaction and fail.
         """
         self._pool._waiting.remove(self)
-        self._unspoolOnto(_NoTxn(self))
+        self._unspoolOnto(_NoTxn(self._pool))
 
 
     def _checkComplete(self):
@@ -433,6 +456,7 @@
         self.connectionFactory = connectionFactory
         self.maxConnections = maxConnections
         self.paramstyle = DEFAULT_PARAM_STYLE
+        self.dialect = DEFAULT_DIALECT
 
         self._free       = []
         self._busy       = []

Modified: CalendarServer/branches/users/glyph/oracle/twext/enterprise/ienterprise.py
===================================================================
--- CalendarServer/branches/users/glyph/oracle/twext/enterprise/ienterprise.py	2011-03-08 03:01:19 UTC (rev 7122)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/ienterprise.py	2011-03-08 03:01:31 UTC (rev 7123)
@@ -40,6 +40,10 @@
 
 
 
+POSTGRES_DIALECT = 'postgres-dialect'
+
+
+
 class IAsyncTransaction(Interface):
     """
     Asynchronous execution of SQL.
@@ -54,6 +58,13 @@
         """)
 
 
+    dialect = Attribute(
+        """
+        A copy of the 'dialect' attribute from the connection pool.  One of the
+        C{*_DIALECT} constants in this module, such as C{POSTGRES_DIALECT}.
+        """)
+
+
     def execSQL(sql, args=(), raiseOnZeroRowCount=None):
         """
         Execute some SQL.

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:19 UTC (rev 7122)
+++ CalendarServer/branches/users/glyph/oracle/twext/enterprise/test/test_adbapi2.py	2011-03-08 03:01:31 UTC (rev 7123)
@@ -671,3 +671,16 @@
         self.assertEquals(notxn.paramstyle, TEST_PARAMSTYLE)
 
 
+    def test_propagateDialect(self):
+        """
+        Each different type of L{IAsyncTransaction} relays the C{dialect}
+        attribute from the L{ConnectionPool}.
+        """
+        TEST_DIALECT = "otherdialect"
+        self.pool.dialect = TEST_DIALECT
+        waittxn = self.pool.connection()
+        self.assertEquals(waittxn.dialect, TEST_DIALECT)
+        self.pool.stopService()
+        notxn = self.pool.connection()
+        self.assertEquals(notxn.dialect, TEST_DIALECT)
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110307/9e273436/attachment.html>


More information about the calendarserver-changes mailing list