[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/RDB - IZopeConnection.py:1.4 ZopeConnection.py:1.3 ZopeDBTransactionManager.py:1.3

Jeremy Hylton jeremy@zope.com
Wed, 24 Jul 2002 19:17:05 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/RDB
In directory cvs.zope.org:/tmp/cvs-serv5275/Zope/App/RDB

Modified Files:
	IZopeConnection.py ZopeConnection.py 
	ZopeDBTransactionManager.py 
Log Message:
Implement new Transaction API for RDB.

There is still a fair amount of needless complexity here.
XXX Refactor to eliminate excess classes and interfaces.






=== Zope3/lib/python/Zope/App/RDB/IZopeConnection.py 1.3 => 1.4 ===
 """
 $Id$
 """
+
 from IDBIConnection import IDBIConnection
 from IDBITypeInfoProvider import IDBITypeInfoProvider
 
-
 class IZopeConnection(IDBIConnection, IDBITypeInfoProvider):
-    """An implementation of this object will be exposed to the user. Therefore
-    the Zope connection represents a conenction in the Zope sense, meaning
-    that the object might not be actually connected to a database.
-    """
+
+    # XXX What does the next paragraph mean?
+    
+    # An implementation of this object will be exposed to the
+    # user. Therefore the Zope connection represents a connection in
+    # the Zope sense, meaning that the object might not be actually
+    # connected to a database.
 
     def cursor():
-        """Return an IZopeCursor object"""
+        """Return an IZopeCursor object."""
         
     def registerForTxn():
-        """Registers the Connection with the Zope Transaction
-        framework.
-
-        This method should only be inovoked by the Zope/DB transaction
-        manager."""
-
-    def unregisterFromTxn():
-        """Unregister the connection from the Zope transaction.
+        """Join the current transaction.
 
         This method should only be inovoked by the Zope/DB transaction
-        manager!!!"""
-
-
-        
-
-
+        manager.
+        """


=== Zope3/lib/python/Zope/App/RDB/ZopeConnection.py 1.2 => 1.3 ===
 
     def __init__(self, conn):
         self.conn = conn
-        # flag for txn registration status
-        self._txn_registered = 0
+        self._txn_registered = False
 
     def __getattr__(self, key):
         # The IDBIConnection interface is hereby implemented
@@ -46,13 +45,8 @@
         'See Zope.App.RDB.IZopeConnection.IZopeConnection'
         if not self._txn_registered:
             tm = ZopeDBTransactionManager(self)
-            t = get_transaction()
-            t.register(tm)
-            self._txn_registered = 1
-
-    def unregisterFromTxn(self):
-        'See Zope.App.RDB.IZopeConnection.IZopeConnection'
-        self._txn_registered = 0
+            get_transaction().join(tm)
+            self._txn_registered = True
 
     ######################################
     # from: Zope.App.RDB.IDBITypeInfoProvider.IDBITypeInfoProvider


=== Zope3/lib/python/Zope/App/RDB/ZopeDBTransactionManager.py 1.2 => 1.3 ===
 """ Zope RDBMS Transaction Integration.
 
 Provides a proxy for interaction between the zope transaction
-framework and the db-api connection. Databases which
-want to support sub transactions need to implement their own
-proxy. 
+framework and the db-api connection. Databases which want to support
+sub transactions need to implement their own proxy.
 
 $Id$
 """
@@ -27,45 +26,19 @@
     __implements__ =  IDataManager
 
     def __init__(self, dbconn):
-        """Callback is a function invoked when the transaction is finished.
-        """
-        self.dbconn = dbconn
-        self._vote = 0
-
-    ############################################################
-    # Implementation methods for interface
-    # Zope.Transaction.IDataManager.
-
-    def abort(self, *ignored):
-        'See Transaction.IDataManager.IDataManager'
-        try:
-            self.dbconn.rollback()
-        finally:
-            self.dbconn.unregisterFromTxn()
-
-    def commit(self, *ignored):
-        'See Transaction.IDataManager.IDataManager'
-
-    def tpc_vote(self, *ignored):
-        'See Transaction.IDataManager.IDataManager'
-        self._vote = 1
-        
-    def tpc_begin(self, *ignored):
-        'See Transaction.IDataManager.IDataManager'
-
-    def tpc_finish(self, *ignored):
-        'See Transaction.IDataManager.IDataManager'
-        if self._vote:
-            try:
-                self.dbconn.commit()
-            finally:
-                self.dbconn.unregisterFromTxn()
-        
-    tpc_abort = abort
-    
-    #
-    ############################################################
+        self._dbconn = dbconn
 
+    # XXX Do any of the Python DB-API implementations support
+    # two-phase commit?
 
+    def prepare(self, txn):
+        return True
 
+    def abort(self, txn):
+        self._dbconn.rollback()
 
+    def commit(self, txn):
+        self._dbconn.commit()
+
+    def savepoint(self, txn):
+        pass