ZODB.FileStorage -- copy? save as?
Mitch Chapman
Mitch.Chapman at bioreason.com
Wed Feb 6 14:50:10 EST 2002
Jeremy Hylton wrote:
>
> Mitch Chapman <Mitch.Chapman at bioreason.com> wrote in message news:<3C606CCE.ACA1472D at bioreason.com>...
> > I'd like to be able to do something like "save as" with
> > ZODB.FileStorage.FileStorage or a derivative thereof. I'm having a
> > hard time even identifying alternatives, mostly because I don't yet
> > understand the FileStorage implementation.
>
> I hope you don't need to understand the implementation in order to use
> it. I'll grant that there's a lot of folklore about how to manage a
> FileStorage that isn't documented anywhere.
That was my hope, too. The problem is, I'm dealing with very large
object graphs, and am trying to find a way to implement "Save As..."
without tying up the application for several minutes at a time.
So I was looking for a way to do a (fast) file copy rather than
a (slow) copy-and-save of a large Python object graph.
> [...] It's more
> likely that you'd want to copy objects at the ZODB level; load an
> object graph out of one storage and create copies of all the objects
> in a new storage.
Yes, that's basically it: I want to load an object graph out of
one storage, make changes to the graph, commit the changes to
a new storage, and henceforth use the new storage. Ideally I'd
like to be able to do this *without* having to copy all of the
objects in the graph or -- worse yet -- having to create new copies
of an associated host of "wrapper" objects.
(Never mind what those wrapper objects suggest about the
application architecture :)
Just to be sure I understand, are you suggesting something like
this?
------------------------------------------------------------------------
oldGraph = oldConnection.root()["graph"]
...
newGraph = Graph()
newConnection.root()["graph"] = newGraph
# Create copies of all objects from oldGraph, in newGraph:
newGraph.assign(oldGraph)
# Don't commit any pending changes to the old store.
oldConnection.close()
# *Do* commit all changes to the new store.
get_transaction().commit()
------------------------------------------------------------------------
> Hope this was helpful.
Yes, it was. Obviously, I still have questions (feel free to
answer :), but you've already helped a lot. Thanks.
--
Mitch
More information about the Python-list
mailing list