Commit 994d58b0 authored by Jeremy Hylton's avatar Jeremy Hylton

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.
parent 51f41f0e
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
############################################################################## ##############################################################################
"""Image object""" """Image object"""
__version__='$Revision: 1.149 $'[11:-2] __version__='$Revision: 1.150 $'[11:-2]
import Globals, struct import Globals, struct
from OFS.content_types import guess_content_type from OFS.content_types import guess_content_type
...@@ -480,9 +480,7 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -480,9 +480,7 @@ class File(Persistent, Implicit, PropertyManager,
# doing a sub-transaction commit. # doing a sub-transaction commit.
get_transaction().commit(1) get_transaction().commit(1)
jar=self._p_jar if self._p_jar is None:
if jar is None:
# Ugh # Ugh
seek(0) seek(0)
return Pdata(read(size)), size return Pdata(read(size)), size
...@@ -491,31 +489,29 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -491,31 +489,29 @@ class File(Persistent, Implicit, PropertyManager,
# to front to minimize the number of database updates # to front to minimize the number of database updates
# and to allow us to get things out of memory as soon as # and to allow us to get things out of memory as soon as
# possible. # possible.
next=None next = None
while end > 0: while end > 0:
pos=end-n pos = end-n
if pos < n: pos=0 # we always want at least n bytes if pos < n:
pos = 0 # we always want at least n bytes
seek(pos) seek(pos)
data=Pdata(read(end-pos))
# Create the object and assign it a next pointer
# Woooop Woooop Woooop! This is a trick. # in the same transaction, so that there is only
# We stuff the data directly into our jar to reduce the # a single database update for it.
# number of updates necessary. data = Pdata(read(end-pos))
data._p_jar=jar self._p_jar.add(data)
data.next = next
# This is needed and has side benefit of getting
# the thing registered: # Save the object so that we can release its memory.
data.next=next
# Now make it get saved in a sub-transaction!
get_transaction().commit(1) 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 next = data
# don't need it anymore! end = pos
data._p_changed=None
next=data
end=pos
return next, size return next, size
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment