[Zodb-checkins] CVS: Zope3/src/zodb - connection.py:1.20

Jeremy Hylton jeremy@zope.com
Thu, 20 Mar 2003 13:01:44 -0500


Update of /cvs-repository/Zope3/src/zodb
In directory cvs.zope.org:/tmp/cvs-serv19355

Modified Files:
	connection.py 
Log Message:
Remove some unnecessary code in _objcommit() to handle new objects.

register() is only called by an existing persistent object, so add
asserts to verify this invariant.  As a result, new objects will never
be found in _objcommit(); they'll always be found by the
ObjectWriter.  

Also rename variables to obj from object and pobject.

Noted during code review with Rys McCusker.


=== Zope3/src/zodb/connection.py 1.19 => 1.20 ===
--- Zope3/src/zodb/connection.py:1.19	Mon Mar 17 12:09:41 2003
+++ Zope3/src/zodb/connection.py	Thu Mar 20 13:01:44 2003
@@ -231,6 +231,7 @@
             raise ReadConflictError(object=obj)
 
     def register(self, obj):
+        assert obj._p_jar is self and obj._p_oid is not None
         if not self._registered:
             self._get_transaction().join(self)
         self._registered.add(obj)
@@ -437,47 +438,44 @@
                         obj._p_changed = 0
                     obj._p_serial = serial
 
-    def _objcommit(self, object, transaction):
-        oid = object._p_oid
+    def _objcommit(self, obj, transaction):
+        oid = obj._p_oid
         self._log.debug("commit object %s", u64(oid))
 
-        if oid is None or object._p_jar is not self:
-            oid = self._storage.newObjectId()
-            object._p_jar = self
-            object._p_oid = oid
-            self._created.add(oid)
-        elif object._p_changed:
+        if obj._p_changed:
             self._modified.add(oid)
         else:
-            return # Nothing to do
+            # The object reverted to the up-to-date state after
+            # registering.
+            return
 
         writer = ObjectWriter(self)
-        for obj in writer.newObjects(object):
+        for obj in writer.newObjects(obj):
             self._commit_store(writer, obj, transaction)
         writer.close()
 
-    def _commit_store(self, writer, pobject, transaction):
-        oid = pobject._p_oid
-        serial = getattr(pobject, '_p_serial', None)
+    def _commit_store(self, writer, obj, transaction):
+        oid = obj._p_oid
+        serial = getattr(obj, '_p_serial', None)
         if serial is None:
             self._created.add(oid)
         else:
             self._inv_lock.acquire()
             try:
                 if (oid in self._invalidated and
-                    not hasattr(pobject, '_p_resolveConflict')):
+                    not hasattr(obj, '_p_resolveConflict')):
                     raise ConflictError(oid=oid)
             finally:
                 self._inv_lock.release()
             self._modified.add(oid)
 
-        data, refs = writer.getState(pobject)
+        data, refs = writer.getState(obj)
         s = self._storage.store(oid, serial, data, refs, self._version,
                                 transaction)
         # Put the object in the cache before handling the
         # response, just in case the response contains the
         # serial number for a newly created object
-        self._cache[oid] = pobject
+        self._cache[oid] = obj
         self._handle_serial(s, oid)
 
     def _commit_sub(self, txn):