Re: Object migrates between DataDomains

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Apr 12 2006 - 06:22:06 EDT

  • Next message: Bryan Lewis: "cvs up to date?"

    On Apr 12, 2006, at 12:33 PM, emre.yilma..tr.com.tr wrote:

    > For update:???
    > ClassDescriptor descriptor =
    > localContext.getEntityResolver().getClassDescriptor(obj.getClass
    > ().getSimpleName());
    > System.err.println(new DeepMergeOperation(ctx).merge(obj,
    > descriptor));
    > ctx.commitChanges();

    Ok, so you have something akin to a replication mechanism. Let's try
    putting the new 1.2 DataChannel API to work. This is an unforeseen
    use of such API, but looks like it might work and actually allow you
    to synchronize all changes of the entire context at once (instead of
    object by object). I have no time right now to test a fully working
    example (and the API is new so there is no docs yet), but let me
    outline the possible approach.

    * Get the latest Cayenne nightly build (it fixes some DataChannel
    event bugs).

    * On commit DataContext (which is itself a DataChannel) broadcasts
    two GraphEvents - one that contains committed context changes and
    another one with generated PK (all changes are represented as
    GraphDiff instances). See 'DataContext.flushToParent(..)' for details
    on how the events are sent.

    * You can register your own listener for the *source* DataContext
    (look at DataContext.setChannel(..) on how to register a listener)
    and apply the first group of changes to the *target* DataContext via
    DataContext.onSync(..):

    GraphEvent e;

    // first type of event
    if(e.getSource() == sourceContext && e.getPostedBy() == sourceContext) {
        targetContext.onSync(sourceContext, e.getDiff(),
    DataChannel.FLUSH_NOCASCADE_SYNC);
    }

    * Applying PK changes is less trivial, as onSync won't work...
    Probably you'll have to repost this event on behalf of
    targetContext's channel so that target context catches it and updates
    itself accordingly.

    // second type of event with PKs
    else if(e.getSource() == sourceContext && e.getPostedBy() ==
    sourceContext.getChannel()) {
        ???
    }

    Andrus



    This archive was generated by hypermail 2.0.0 : Wed Apr 12 2006 - 06:22:31 EDT