[Zope3-checkins] SVN: Zope3/trunk/src/ZODB/ Added an IConnection interface declaration on ZODB Connection.

Albertas Agejevas alga at pov.lt
Thu Jun 10 10:07:45 EDT 2004


Log message for revision 25330:
Added an IConnection interface declaration on ZODB Connection.

Jim says Tim Peters will be mad at him, but that's the right way to go.



-=-
Modified: Zope3/trunk/src/ZODB/Connection.py
===================================================================
--- Zope3/trunk/src/ZODB/Connection.py	2004-06-10 13:42:39 UTC (rev 25329)
+++ Zope3/trunk/src/ZODB/Connection.py	2004-06-10 14:07:45 UTC (rev 25330)
@@ -35,6 +35,8 @@
 from ZODB.TmpStore import TmpStore
 from ZODB.utils import oid_repr, z64, positive_id
 from ZODB.serialize import ObjectWriter, ConnectionObjectReader, myhasattr
+from ZODB.interfaces import IConnection
+from zope.interface import implements
 
 global_reset_counter = 0
 
@@ -147,6 +149,7 @@
         getTransferCounts
 
     """
+    implements(IConnection)
 
     _tmp = None
     _code_timestamp = 0

Modified: Zope3/trunk/src/ZODB/interfaces.py
===================================================================
--- Zope3/trunk/src/ZODB/interfaces.py	2004-06-10 13:42:39 UTC (rev 25329)
+++ Zope3/trunk/src/ZODB/interfaces.py	2004-06-10 14:07:45 UTC (rev 25330)
@@ -224,3 +224,26 @@
         """
         # XXX is this this allowed to cause an exception here, during
         # the two-phase commit, or can it toss data silently?
+
+
+class IConnection(Interface):
+    """ZODB connection.
+
+    XXX: This interface is incomplete.
+    """
+
+    def add(ob):
+        """Add a new object 'obj' to the database and assign it an oid.
+
+        A persistent object is normally added to the database and
+        assigned an oid when it becomes reachable to an object already in
+        the database.  In some cases, it is useful to create a new
+        object and use its oid (_p_oid) in a single transaction.
+
+        This method assigns a new oid regardless of whether the object
+        is reachable.
+
+        The object is added when the transaction commits.  The object
+        must implement the IPersistent interface and must not
+        already be associated with a Connection.
+        """

Modified: Zope3/trunk/src/ZODB/tests/testConnection.py
===================================================================
--- Zope3/trunk/src/ZODB/tests/testConnection.py	2004-06-10 13:42:39 UTC (rev 25329)
+++ Zope3/trunk/src/ZODB/tests/testConnection.py	2004-06-10 14:07:45 UTC (rev 25330)
@@ -22,6 +22,7 @@
 from ZODB.config import databaseFromString
 from ZODB.utils import p64, u64
 from ZODB.tests.warnhook import WarningsHook
+from zope.interface.verify import verifyObject
 
 class ConnectionDotAdd(unittest.TestCase):
 
@@ -595,6 +596,15 @@
         return None
 
 
+class TestConnectionInterface(unittest.TestCase):
+
+    def test(self):
+        from ZODB.interfaces import IConnection
+        db = databaseFromString("<zodb>\n<mappingstorage/>\n</zodb>")
+        cn = db.open()
+        verifyObject(IConnection, cn)
+
+
 class StubDatabase:
 
     def __init__(self):
@@ -608,4 +618,5 @@
 def test_suite():
     s = unittest.makeSuite(ConnectionDotAdd, 'check')
     s.addTest(doctest.DocTestSuite())
+    s.addTest(unittest.makeSuite(TestConnectionInterface))
     return s




More information about the Zope3-Checkins mailing list