[Zope3-checkins] CVS: Zope3/src/zodb - connection.py:1.37
interfaces.py:1.19
Albertas Agejevas
alga at pov.lt
Wed Oct 8 04:21:00 EDT 2003
Update of /cvs-repository/Zope3/src/zodb
In directory cvs.zope.org:/tmp/cvs-serv9086
Modified Files:
connection.py interfaces.py
Log Message:
Connection.add() method with tests and interface changes.
=== Zope3/src/zodb/connection.py 1.36 => 1.37 ===
--- Zope3/src/zodb/connection.py:1.36 Sun Sep 21 13:29:58 2003
+++ Zope3/src/zodb/connection.py Wed Oct 8 04:20:28 2003
@@ -251,8 +251,8 @@
return None
######################################################################
- # IConnection requires the next five methods:
- # getVersion(), reset(), cacheGC(), invalidate(), close()
+ # IConnection requires the next six methods:
+ # getVersion(), reset(), cacheGC(), invalidate(), close(), add()
def getVersion(self):
return self._version
@@ -293,6 +293,22 @@
self._cache.shrink()
# Return the connection to the pool.
self._db._closeConnection(self)
+
+ def add(self, obj):
+ marker = object()
+ oid = getattr(obj, "_p_oid", marker)
+ if oid is marker:
+ raise TypeError("cannot add a non-persistent object %r "
+ "to a connection" % (obj, ))
+ if obj._p_jar is not None and obj._p_jar is not self:
+ raise InvalidObjectReference(obj, obj._p_jar)
+ if obj._p_jar is None:
+ # Setting _p_changed has a side-effect of adding obj to
+ # _p_jar._registered, so it must be set after _p_jar.
+ obj._p_jar = self
+ obj._p_oid = self.newObjectId()
+ obj._p_changed = True
+
######################################################################
# transaction.interfaces.IDataManager requires the next four methods
=== Zope3/src/zodb/interfaces.py 1.18 => 1.19 ===
--- Zope3/src/zodb/interfaces.py:1.18 Mon Jul 28 10:51:51 2003
+++ Zope3/src/zodb/interfaces.py Wed Oct 8 04:20:28 2003
@@ -344,6 +344,15 @@
def cacheGC():
pass
+ def add(obj):
+ """Add a persistent object to this connection.
+
+ Essentially, set _p_jar and assign _p_oid on the object.
+
+ Raises a TypeError if obj is not persistent. Does nothing if
+ obj is already added to this connection.
+ """
+
class ITransaction(_ITransaction):
"""Extends base ITransaction with with metadata.
More information about the Zope3-Checkins
mailing list