[Zope3-checkins] CVS: Zope3/src/zope/app/rdb - __init__.py:1.22.2.1

Jim Fulton jim at zope.com
Fri Jan 23 11:41:57 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/rdb
In directory cvs.zope.org:/tmp/cvs-serv21547/src/zope/app/rdb

Modified Files:
      Tag: zope3-zodb3-devel-branch
	__init__.py 
Log Message:
The savepoint method returned None. This is inconsistent with
IDataManager.  It must return a rollback object. Added a rollback
object that raises an exception if it's used.


=== Zope3/src/zope/app/rdb/__init__.py 1.22 => 1.22.2.1 ===
--- Zope3/src/zope/app/rdb/__init__.py:1.22	Fri Dec 19 11:53:17 2003
+++ Zope3/src/zope/app/rdb/__init__.py	Fri Jan 23 11:41:26 2004
@@ -27,7 +27,7 @@
 from persistence import Persistent
 
 from transaction import get_transaction
-from transaction.interfaces import IDataManager
+from transaction.interfaces import IDataManager, IRollback
 
 from zope.security.checker import NamesChecker
 
@@ -365,12 +365,45 @@
     def commit(self, txn):
         self._dbconn.commit()
 
-    # XXX Do any of the Python DB-API implementations support
-    # two-phase commit?
-
     def savepoint(self, txn):
-        return None
+        """Create a savepoint that can not be rolled back
+
+        Savepoint implementation for data managers that do not
+        support savepoints. We don't raise an error here, because
+        there's no harm in ignoring a call if no one ever tries to
+        rollback a savepoint.  By ignoring the call, the data
+        manager can be used with data managers that so support
+        savepoints.
+
+        We return a rollback that raises an error if we call it.
+
+        >>> dm = ZopeDBTransactionManager(None)
+        >>> rb = dm.savepoint(None)
+        >>> rb.rollback()
+        Traceback (most recent call last):
+        ...
+        NotImplementedError: """ \
+           """ZopeDBTransactionManager data managers do not support """ \
+           """savepoints (aka subtransactions
+        """
+        
+        
+        return NoSavepointSupportRollback(self)
+
+class NoSavepointSupportRollback:
+    """Rollback for data managers that don't support savepoints
+    """
 
+    implements(IRollback)
+
+    def __init__(self, dm):
+        self.dm = dm.__class__.__name__
+
+    def rollback(self):
+        raise NotImplementedError(
+            "%s data managers do not support savepoints (aka subtransactions"
+            % self.dm)
+    
 
 class Row(object):
     """Represents a row in a ResultSet"""




More information about the Zope3-Checkins mailing list