You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Marcin Skladaniec <ma...@ish.com.au> on 2006/04/28 09:55:18 UTC

re-fething object from the database

Hello

I have two contexts containing the same entity.
- one contains the list of all entities of this type - ListContext
- second contains only one entity for editing - EditContext

I would like to notify the relevant context(s) when the object  
changes, so it needs to be refreshed. How can I do it ? I thought  
there was a notification mechanism in 3t-cayenne, but I cant find a  
word about it anymore.

What is the best way to force object to be re-faulted from database ?  
I tried to set persistence state to hollow but it does not work.

Regards
Marcin


-------------------------->
ish
http://www.ish.com.au
Level 1, 30 Wilson Street Newtown 2042 Australia
phone +61 2 9550 5001   fax +61 2 9550 4001



Re: re-fething object from the database

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Apr 28, 2006, at 3:55 AM, Marcin Skladaniec wrote:

> Hello
>
> I have two contexts containing the same entity.
> - one contains the list of all entities of this type - ListContext
> - second contains only one entity for editing - EditContext
>
> I would like to notify the relevant context(s) when the object  
> changes, so it needs to be refreshed.

Hmm... If those two contexts use the same ClientChannel,  
synchronization should be automatic. Of course it only happens on  
commit.

> How can I do it ? I thought there was a notification mechanism in  
> 3t-cayenne, but I cant find a word about it anymore.

The even mechanism was simplified (you may say downgraded) compared  
to the earlier version. I need to updated the docs. You can listen to  
the ClientChannel events. To register a listener implement  
DataChannelListener and use EventUtil class to register it.

If you need to receive ongoing object events (i.e. property changes  
that by themselves do not result in commit), you can subclass  
CayenneContext and override 'propertyChanged'


> What is the best way to force object to be re-faulted from  
> database ? I tried to set persistence state to hollow but it does  
> not work.

Yeah, unfortunately client invalidate functionality didn't make it to  
1.2. One way to work around this is an explicit refresh query:

Query q = new ObjectIdQuery(oid, false, ObjectIdQuery.CACHE_REFRESH)

Andrus