Stefan,
This has come up before on the list. There's no automatic way to do this
yet.
You'd have to iterate through your entities and recreate a copy, one entity
at a time.
I've done this in the past under WebObjects, and it was also ackward.
Here's some now-obsolete cayenne code I used to iterate through an object
graph. It was used to manually reconnect a dataContext to each object, but
you could modify it to copy an object instead.
Maybe this will help.
public void reconnect(Object object)
{
if (null == object) return;
if (false == (object instanceof DataObject))
throw new
IllegalArgumentException(object.getClass().getName() + " is not a
DataObject.");
DataObject dataObject = (DataObject)object;
if (null != dataObject.getDataContext()) return;
dataObject.setDataContext(currentDataContext);
EntityResolver entityResolver = currentDataContext.getEntityRe solver();
ObjEntity objEntity = entityResolver.lookupObjEntity(dataObject);
// initialize to-many relationships with a fault
Iterator it = objEntity.getRelationships().iterator();
while (it.hasNext()) {
ObjRelationship rel = (ObjRelationship) it.next();
if (rel.isToMany()) {
dataObject.writePropertyDirectly(rel.getName(),
Fault.getToManyFault());
Object relObject =
dataObject.readPropertyDirectly(rel.getName());
if (relObject instanceof List)
{
List relList = (List)relObject;
Iterator relObjectIterator = relList.iterator();
while (relObjectIterator.hasNext())
{
DataObject relDataObject = (DataObject)
relObjectIterator.next();
reconnect(relDataObject);
}
}
}
else
{
Object relObject =
dataObject.readPropertyDirectly(rel.getName());
if (relObject instanceof DataObject) reconnect(relObject);
}
}
}
On 11/14/05, stefan.leidne..udor.lu <stefan.leidner@tudor.lu> wrote:
>
>
> in fact I badly expressed myself
> I have an object root "Project" referred in my current DataContext.
> This object has references towards other objects also referred in this
> DataContext.
> here's my problem: in fact I would simply like to record a copy of this
> Projet object (and of all these objects dependent) in my Database like a
> typical functionality of "Save As"
> to be clear, with a comitChanges() i work on the original "Project"
> object. But how can i work on duplicate copies of this Project object and
> all its linked objects to save a duplicate "Project" in my DB in fact
>
> thank you for your help
>
>
>
> *Cris Daniluk <cris.danilu..mail.com>*
>
> 11.11.05 18:32 Please respond to
> cayenne-use..bjectstyle.org
>
> To
> cayenne-use..bjectstyle.org cc
>
> Subject
> Re: save As
>
>
>
>
>
>
> Just copy the cayenne.xml and other xml files (*Connection.xml and
> *Map.xml files) that Cayenne makes..
>
> Cayenne doesn't build this into the GUI because its not something you
> would normally do, but its still very easy to do on the filesystem
> directly.
>
> Note that because the master file is "cayenne.xml", it really isn't
> possible to have two totally separate projects in the same directory
> (it sort of is, but... not really)
>
> On 11/11/05, stefan.leidne..udor.lu <stefan.leidner@tudor.lu> wrote:
> >
> > hello,
> >
> > perhaps you will find my question very ridiculous but I am a new user of
> > Cayenne and I try to understand its mechanisms
> >
> > My question is as follows:
> > I defined a Cayenne DataContext which registers the whole of the objects
> of
> > my DB. No problem int the saving/loading of datas. it works fine.
> > But which would be the simplest way with Cayenne to be able to
> implements a
> > "Save As" fonctionnality (to make a duplication of my project in fact)
> >
> > thank you in advance
> >
>
>
This archive was generated by hypermail 2.0.0 : Tue Nov 22 2005 - 10:53:31 EST