[Zope-Checkins] CVS: Zope/lib/python/OFS - Image.py:1.150
Jeremy Hylton
jeremy at zope.com
Wed Feb 25 10:45:48 EST 2004
Update of /cvs-repository/Zope/lib/python/OFS
In directory cvs.zope.org:/tmp/cvs-serv7285
Modified Files:
Image.py
Log Message:
Use new Connection add() method instead of assigning _p_jar.
We'd like to deprecate explanation manipulation of a Persistent
object's _p_jar attribute. Also use less obscure _p_deactivate()
call.
Revise comments and add assertions that object is stored and ghosted.
=== Zope/lib/python/OFS/Image.py 1.149 => 1.150 ===
--- Zope/lib/python/OFS/Image.py:1.149 Mon Jan 19 11:51:58 2004
+++ Zope/lib/python/OFS/Image.py Wed Feb 25 10:45:48 2004
@@ -480,9 +480,7 @@
# doing a sub-transaction commit.
get_transaction().commit(1)
- jar=self._p_jar
-
- if jar is None:
+ if self._p_jar is None:
# Ugh
seek(0)
return Pdata(read(size)), size
@@ -491,31 +489,29 @@
# to front to minimize the number of database updates
# and to allow us to get things out of memory as soon as
# possible.
- next=None
+ next = None
while end > 0:
- pos=end-n
- if pos < n: pos=0 # we always want at least n bytes
+ pos = end-n
+ if pos < n:
+ pos = 0 # we always want at least n bytes
seek(pos)
- data=Pdata(read(end-pos))
-
- # Woooop Woooop Woooop! This is a trick.
- # We stuff the data directly into our jar to reduce the
- # number of updates necessary.
- data._p_jar=jar
+
+ # Create the object and assign it a next pointer
+ # in the same transaction, so that there is only
+ # a single database update for it.
+ data = Pdata(read(end-pos))
+ self._p_jar.add(data)
+ data.next = next
- # This is needed and has side benefit of getting
- # the thing registered:
- data.next=next
-
- # Now make it get saved in a sub-transaction!
+ # Save the object so that we can release its memory.
get_transaction().commit(1)
+ data._p_deactivate()
+ # The object should be assigned an oid and be a ghost.
+ assert data._p_oid is not None
+ assert data._p_state == -1
- # Now make it a ghost to free the memory. We
- # don't need it anymore!
- data._p_changed=None
-
- next=data
- end=pos
+ next = data
+ end = pos
return next, size
More information about the Zope-Checkins
mailing list