[Checkins] SVN: Zope/branches/2.12/ merge branch rochael-TM_sortKey: add a setSortKey method to Shared.setSortKey() method to Shared.DC.ZRDB.TM.TM

Leonardo Rochael Almeida leorochael at gmail.com
Fri Jun 18 15:18:30 EDT 2010


Log message for revision 113622:
  merge branch rochael-TM_sortKey: add a setSortKey method to Shared.setSortKey() method to Shared.DC.ZRDB.TM.TM

Changed:
  U   Zope/branches/2.12/doc/CHANGES.rst
  U   Zope/branches/2.12/src/Shared/DC/ZRDB/TM.py
  A   Zope/branches/2.12/src/Shared/DC/ZRDB/tests/testTM.py

-=-
Modified: Zope/branches/2.12/doc/CHANGES.rst
===================================================================
--- Zope/branches/2.12/doc/CHANGES.rst	2010-06-18 19:04:36 UTC (rev 113621)
+++ Zope/branches/2.12/doc/CHANGES.rst	2010-06-18 19:18:30 UTC (rev 113622)
@@ -38,6 +38,10 @@
   - Missing = 2.13.1
   - Persistence = 2.13.2
 
+- Added "setSortKey()" method to the "Shared.DC.ZRDB.TM.TM" class
+  to allow database connections to specify the commit order without
+  needing to override the sortKey() method.
+
 2.12.7 (2010-06-13)
 -------------------
 

Modified: Zope/branches/2.12/src/Shared/DC/ZRDB/TM.py
===================================================================
--- Zope/branches/2.12/src/Shared/DC/ZRDB/TM.py	2010-06-18 19:04:36 UTC (rev 113621)
+++ Zope/branches/2.12/src/Shared/DC/ZRDB/TM.py	2010-06-18 19:18:30 UTC (rev 113622)
@@ -26,7 +26,7 @@
     needed at the start of a transaction.
 
     A subclass that uses locking during transaction commit must
-    defined a sortKey() method.
+    define a sortKey() method.
     """
 
     _registered=None
@@ -66,14 +66,19 @@
 
     tpc_abort = abort
 
+    # Most DA's talking to RDBMS systems do not care about commit order, so
+    # return the constant 1
+    _sort_key = 1
+
     def sortKey(self, *ignored):
-        """ The sortKey method is used for recent ZODB compatibility which
-            needs to have a known commit order for lock acquisition.  Most
-            DA's talking to RDBMS systems do not care about commit order, so
-            return the constant 1
+        """ The sortKey method is used by ZODB to have a known commit order for
+            lock acquisition.
         """
-        return 1
+        return self._sort_key
 
+    def setSortKey(self, sort_key):
+        self._sort_key = sort_key
+
 class Surrogate:
 
     def __init__(self, db):

Copied: Zope/branches/2.12/src/Shared/DC/ZRDB/tests/testTM.py (from rev 113621, Zope/branches/rochael-TM_sortKey/src/Shared/DC/ZRDB/tests/testTM.py)
===================================================================
--- Zope/branches/2.12/src/Shared/DC/ZRDB/tests/testTM.py	                        (rev 0)
+++ Zope/branches/2.12/src/Shared/DC/ZRDB/tests/testTM.py	2010-06-18 19:18:30 UTC (rev 113622)
@@ -0,0 +1,29 @@
+##############################################################################
+#
+# Copyright (c) 2009 Zope Foundation and Contributors.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
+
+from unittest import TestCase, TestSuite, makeSuite
+from Shared.DC.ZRDB.TM import TM
+
+class TestTM(TestCase):
+
+    def test_sortKey(self):
+        tm = TM()
+        # the default Transaction Manager should have .sortKey() of 1 for
+        # backward compatibility
+        self.assertEquals(tm.sortKey(), 1)
+        # but the sortKey() should be adjustable
+        tm.setSortKey(())
+        self.assertEquals(tm.sortKey(), ())
+
+def test_suite():
+    return TestSuite((makeSuite(TestTM),))



More information about the checkins mailing list