cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@gmail.com>
Subject Re: Making a copy of an object that is persisted by Cayenne
Date Thu, 12 Jan 2012 16:51:20 GMT
Andrus,

I find myself in the same situation and environment as Eric Lazarus
who originally posed this question.
Unfortunately, he never answered your questions, so now I have an
unrealistic hope that you can answer them for my situation despite it
being 5 1/2 years ago.  :-)

[Continued below your original response]

On Thu Jun 01 2006 - 11:46:10 EDT, Andrus Adamchik wrote,
=================================================
Cayenne 1.2 has some unadvertised object graph cloning facilities
centered around ClassDescriptor interface (that has a 'shallowMerge'
method). I've written a few specialized operations, such as
DeepMergeOperation and ObjectDetachOperation in Util package that are
doing smart deep copy for some internal use.

Could you explain a bit what is the purpose of the copy operation and
whether the original and cloned objects are (or should be) registered
with a DataContext and whether this is the same DataContext for the
original and the clone.
=================================================

In my situation, also on a Cayenne 1.2 project, I have a document
record with a number of to-many joins, and some of those to-many joins
also have other to-many joins.
I have been asked to provide a function that will copy the original
document (and all related records), changing only the primary keys and
the document_number field.

The original object is a committed object registered with a data context.
The cloned object eventually has to be in a data context, although I
can certainly fetch it manually afterward myself if need be.
It doesn't matter to me if the two objects are in the same data context.

I could certainly go through and create specific deepCopy() methods on
each of the related entities, but I'd rather not have to do so.
It is possible that some of the relationships will need to be excluded
from the deep copy, but I can always pre-break those beforehand and
then set them back.

Ideally, I would want to have a method like

Document copiedDoc = originalDocument.deepCopy(<List of path specs to
exclude in the deep copy>);

Like I said, it's pretty unreasonable to expect you to remember what
you were working on so long ago, so I'm going to try to see how you
used DeepMergeOperation and ObjectDetachOperation in hopes of figuring
it out myself as soon as I post this, but any hints would be
appreciated.

Before I found this message, I was going to do this on my own by
iterating through the relationships and attributes of the entity
recursively, excluding matching paths.

Mime
View raw message