cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Logasa Bogen II <...@tamu.edu>
Subject Re: Re: Cloning a CayenneDataObject
Date Tue, 10 Feb 2009 13:35:40 GMT
Sorry for the long time to respond, I realized this morning that I 
hadn't actually joined the list yet (which I have rectified) and didn't 
get your response when you sent it.

Do give a better picture of what I am doing, I have is multiple users 
each with multiple collections each of the collections have multiple 
entries. When I hit "Save As", I need to clone a working collection and 
all of its entries.

If I understand you correctly, then I should make a custom clone method 
that clones only what I want it to.

plb

Andrey Razumovsky wrote:
> Hi Paul,
>
> Do you need to clone only the object's attributes (i.e. fields from one DB
> table) or you need to clone related objects too? If first, I'd recommend to
> iterate through ObjEntity attributes and write their values to new object.
> Tell me if you need a snippet.
> If second, since you likely don't want to clone *all* relationships, because
> this might result in cloning all database, you should write a clone method
> which clones only rels specified in DataObject, e.g.
>
> interface CayenneCloneable {
>    public List<String> getClonedRelationships();
> }
>
> class Artist extends _Artist implements CayenneCloneable {
>   ...
> }
>
> //somewhere
> public static <T extends CayenneDataObject> T clone(T src) {
>   //iterate through obj attributes
>
>   if (T instance of CayenneCloneable) {
>      //recursively clone relationships
>   }
> }
>
> That's how I've done it, and I can search my projects for an example if you
> want it
>
> Regards,
> Andrey
>
> 2009/2/9 Paul Logasa Bogen II <plb@tamu.edu>
>
>   
>> I am writing a web application with Wicket on the front end and Cayenne on
>> the back end. When a user clicks "Save As" in my application I want to save
>> the current working object with a new key. My suspicion is if I just blank
>> out the key and do a context.commitChanges() I will just change the key and
>> any other information for the object instead of creating new rows in the
>> database. Is this correct? And what is the recommended way to clone or copy
>> an object to a new one?
>>
>> plb
>>
>>     
>
>   


Mime
View raw message