You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Borut Bolčina <bo...@gmail.com> on 2008/04/14 15:52:36 UTC

Re: Replace Objects in a Database?

Andrus,

what is the "status" of this merge functionality? Any estimates?

Thanks,
Borut

2007/11/29 Andrus Adamchik <an...@objectstyle.org>:

> In the nearest future we'll be adding a "merge" method to the DataContext
> that would do exactly what you described here - reattach an already
> persistent and possibly modified object to the context. For now the closest
> analog is "localObject", but it will require some hacking. A reattach method
> may look like this:
>
> void reattach(Persistent object) {
>    // force "modified" on the object
>    object.setPersistenceState(PersistenceState.MODIFIED);
>    context.localObject(object.getObjectId(), object);
> }
>
> This will do the right thing for objects not changed, but WILL NOT do the
> right thing for the newly inserted objects.
>
> Andrus
>
>
>
> On Nov 29, 2007, at 1:33 PM, Detlef Burt wrote:
>
>  Hello,
> >
> > after being able to keep my Data after sending my Objects via JMS
> > (Thanks Andrus) I now have a problem when I try to write the Objects back
> > into the Database.
> >
> > After sending the Objects to the Client-Application, the Client changes
> > some data ( Just a timestamp in my Testcase ) and then sends an
> > Update-Request to the Server. Due to the fact, that the Client has no access
> > to the DataContext or the underlying ObjectStore, the changes made to the
> > Object won't be recorded.
> > After the Server receives the Object, it reconnects the Object to the
> > DataContext, thus being able to get a snapshot from the database or even
> > create an UpdateQuery.
> > But I can't go anywhere from here.
> > Executing the UpdateQuery won't have any effect because Cayenne doesn't
> > know what changed.
> >
> > I also tried to get a Snapshot from the DB, convert my DataObject to a
> > DataRow and then create and register the diff of those by myself. But I
> > couldn't find anything like that :/
> >
> > To sum it all up:
> > - Can I tell Cayenne to replace the Database Contents with the data from
> > my Object while retaining the ObjectId ?
> > - Can I tell Cayenne to "scan" an Object for changes and register the
> > differences, so that calling commitChanges will update the Object?
> > - Or is it possible to create a DataRow from a DataObject so I can
> > create and register an ObjectDiff ?
> >
> > NOTE:
> > When updating the Object, I don't know what class is being updated and
> > what properties it has, all I have is my CayennePersistableObject Baseclass,
> > which extends CayenneDataObject.
> >
> > Detlef
> >
> >
> >
>

Re: Replace Objects in a Database?

Posted by Andrus Adamchik <an...@objectstyle.org>.
no estimates... still "nearest future" ;-)

On Apr 14, 2008, at 4:52 PM, Borut Bolčina wrote:

> Andrus,
>
> what is the "status" of this merge functionality? Any estimates?
>
> Thanks,
> Borut
>
> 2007/11/29 Andrus Adamchik <an...@objectstyle.org>:
>
>> In the nearest future we'll be adding a "merge" method to the  
>> DataContext
>> that would do exactly what you described here - reattach an already
>> persistent and possibly modified object to the context. For now the  
>> closest
>> analog is "localObject", but it will require some hacking. A  
>> reattach method
>> may look like this:
>>
>> void reattach(Persistent object) {
>>  // force "modified" on the object
>>  object.setPersistenceState(PersistenceState.MODIFIED);
>>  context.localObject(object.getObjectId(), object);
>> }
>>
>> This will do the right thing for objects not changed, but WILL NOT  
>> do the
>> right thing for the newly inserted objects.
>>
>> Andrus
>>
>>
>>
>> On Nov 29, 2007, at 1:33 PM, Detlef Burt wrote:
>>
>> Hello,
>>>
>>> after being able to keep my Data after sending my Objects via JMS
>>> (Thanks Andrus) I now have a problem when I try to write the  
>>> Objects back
>>> into the Database.
>>>
>>> After sending the Objects to the Client-Application, the Client  
>>> changes
>>> some data ( Just a timestamp in my Testcase ) and then sends an
>>> Update-Request to the Server. Due to the fact, that the Client has  
>>> no access
>>> to the DataContext or the underlying ObjectStore, the changes made  
>>> to the
>>> Object won't be recorded.
>>> After the Server receives the Object, it reconnects the Object to  
>>> the
>>> DataContext, thus being able to get a snapshot from the database  
>>> or even
>>> create an UpdateQuery.
>>> But I can't go anywhere from here.
>>> Executing the UpdateQuery won't have any effect because Cayenne  
>>> doesn't
>>> know what changed.
>>>
>>> I also tried to get a Snapshot from the DB, convert my DataObject  
>>> to a
>>> DataRow and then create and register the diff of those by myself.  
>>> But I
>>> couldn't find anything like that :/
>>>
>>> To sum it all up:
>>> - Can I tell Cayenne to replace the Database Contents with the  
>>> data from
>>> my Object while retaining the ObjectId ?
>>> - Can I tell Cayenne to "scan" an Object for changes and register  
>>> the
>>> differences, so that calling commitChanges will update the Object?
>>> - Or is it possible to create a DataRow from a DataObject so I can
>>> create and register an ObjectDiff ?
>>>
>>> NOTE:
>>> When updating the Object, I don't know what class is being updated  
>>> and
>>> what properties it has, all I have is my CayennePersistableObject  
>>> Baseclass,
>>> which extends CayenneDataObject.
>>>
>>> Detlef
>>>
>>>
>>>
>>