Claudio Rosati <claudio.rosat..csys.it> wrote:
> Hi all,
>
> I've two different classes with the following code:
>
>
> private static DataContext dataContext;
> private static DataContextDelegate dataContextDelegate;
>
> static
> {
>
> dataContext = DataContext.createDataContext();
> dataContextDelegate = new DataContextDelegate() {
> public void finishedMergeChanges ( DataObject object ) {
> System.out.println("Class 1(or
> 2):finishedMergeChanges");
> dataContext.refetchObject(object.getObjectId());
> // ...GUI synch code here...
> }
> public void finishedProcessDelete ( DataObject object ) {
> ; // Nothing to do.
> }
> public boolean shouldMergeChanges ( DataObject object,
> DataRow snapshotInStore ) {
> return true;
> }
> public boolean shouldProcessDelete ( DataObject object ) {
> return true;
> }
> public GenericSelectQuery willPerformSelect ( DataContext
> context, GenericSelectQuery query ) {
> return query;
> }
> };
>
> dataContext.setDelegate(dataContextDelegate);
>
> }
>
>
> Inside these two classes I load the same DataObject from my DB (a
Microsoft
> SQL Server).
> When I modyfy the loaded object and commit the changes from one
DataContext
> I expect a message from the delegate of the other, but this doesn't occurs
> (and my GUI remains not synchronized...).
>
> Where is the problem?
[Note: I am no expert on the following, but here's my best guesses.]
First off, it looks as though you want to have any changes made in other
contexts automatically show up in your current context. That's the default
behavior of Cayenne 1.1. Calling
"dataContext.refetchObject(object.getObjectId());" should be unnecessary.
It might be a bug that DataContextDelegate doesn't generate
finishedMergeChanges when such changes are merged in from other
DataContexts. I do see finishedMergeChanges() calls for
processUpdatedSnapshots (which should happen when snapshot update events are
received from other DataContexts) for COMMITTED, MODIFIED, and DELETED
objects.
If it's the case of a bug....
A dataContextDelegate is set per DataContext.
Thus, DataContextA will not trigger the delegated methods for
DataContextDelegateB, nor vice-versa.
You'd need to capture all of those events and resend them to every other
data context delegate.
Another possibility is to listen for SnapshotEvent messages, which will
appear no matter what data context the event is generated in.
Unfortunately, I'm not sure if this will tell you AFTER the event; more
likely it'll tell you before or during the event. Also, I can't remember
exactly what event subject you need to listen for.
EventManager.getDefaultManager().addNonBlockingListener(
this,
"onLocalEvent",
SnapshotEvent.class,
eventSubject,
eventsSource);
If I were doing this today, I'd probably have each DataContextDelegate
register to listen for a "customFinishedMergeChanges" event, then I'd send
out "customFinishedMergeChanges" events to the EventManager each time the
finishedMergeChanges() method was called.
Again, my understanding of the whole process is imperfect.
-Mike
This archive was generated by hypermail 2.0.0 : Wed Jan 05 2005 - 12:27:17 EST