FAQ
Hi,

Is there a easy way to migrate created objects from one DataDomain to other DataDomain.

Thank you...

Search Discussions

  • Andrus Adamchik at Apr 10, 2006 at 8:54 am

    On Apr 10, 2006, at 11:48 AM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Is there a easy way to migrate created objects from one DataDomain
    to other DataDomain.

    Thank you...

    Technically DataObject belongs to a DataContext, so we should be
    speaking about moving objects between DataContexts (that in turn can
    belong to different DataDomains). This is done with
    DataContext.localObject(..)

    http://objectstyle.org/confluence/display/CAYDOC/Moving+Objects
    +Between+Contexts

    Of course object mappings have to be compatible in both domains
    involved.

    Andrus
  • Emre Yilmaz at Apr 11, 2006 at 1:50 pm
    Hi,

    Thank you for help. I make the changes as you say but I observe the DataContext.localObject(..) not set the relations (forign key id's).Can you help me for migrating
    objects with its relations through DataDomains.

    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik <andrus@objectstyle.org>
    Tarih: Monday, April 10, 2006 11:55
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    On Apr 10, 2006, at 11:48 AM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Is there a easy way to migrate created objects from one
    DataDomain
    to other DataDomain.

    Thank you...

    Technically DataObject belongs to a DataContext, so we should be
    speaking about moving objects between DataContexts (that in turn
    can
    belong to different DataDomains). This is done with
    DataContext.localObject(..)

    http://objectstyle.org/confluence/display/CAYDOC/Moving+Objects
    +Between+Contexts

    Of course object mappings have to be compatible in both domains
    involved.

    Andrus
  • Andrus Adamchik at Apr 11, 2006 at 2:53 pm
    Yeah, default mechanism is "lazy" in that it assumes that related
    objects can be resolved from the database on demand. Copying a
    subgraph of new objects is a bit more tricky. In 1.2 you can try
    using org.objectstyle.cayenne.util.DeepMergeOperation for your
    purpose. Something like this:

    DataContext srcContext, targetContext;
    DataObject object;

    ClassDescriptor descriptor =
    targetContext.getEntityResolver().getClassDescriptor("MyEntity");

    DataObject anotherObject = new DeepMergeOperation(targetContext).merge
    (object, descriptor);

    DeepMergeOperation merges everything that is attached to a given
    object and is already resolved in memory. If you need to implement
    different logic, you can write your own version using
    DeepMergeOperation as a template. An example of a different graph
    traversal termination logic is ObjectDetachOperation that is based on
    a preset tree of relationships.

    Andrus
    On Apr 11, 2006, at 5:50 PM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Thank you for help. I make the changes as you say but I observe the
    DataContext.localObject(..) not set the relations (forign key
    id's).Can you help me for migrating
    objects with its relations through DataDomains.

    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik <andrus@objectstyle.org>
    Tarih: Monday, April 10, 2006 11:55
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    On Apr 10, 2006, at 11:48 AM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Is there a easy way to migrate created objects from one
    DataDomain
    to other DataDomain.

    Thank you...

    Technically DataObject belongs to a DataContext, so we should be
    speaking about moving objects between DataContexts (that in turn
    can
    belong to different DataDomains). This is done with
    DataContext.localObject(..)

    http://objectstyle.org/confluence/display/CAYDOC/Moving+Objects
    +Between+Contexts

    Of course object mappings have to be compatible in both domains
    involved.

    Andrus
  • Emre Yilmaz at Apr 12, 2006 at 8:01 am
    Hi Andrus ,

    I tested DeepMergeOperation. Merged object on targetContext (anotherObject) is created as I desired with its relations but I observe actually anotherObject is not created physically on database .I used the targetContext.commitChanges() to create on database but not create it.What is the reason of this or how can commit created anotherObject on targetContext.


    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik
    Tarih: Tuesday, April 11, 2006 17:53
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    Yeah, default mechanism is "lazy" in that it assumes that
    related
    objects can be resolved from the database on demand. Copying
    a
    subgraph of new objects is a bit more tricky. In 1.2 you can
    try
    using org.objectstyle.cayenne.util.DeepMergeOperation for
    your
    purpose. Something like this:

    DataContext srcContext, targetContext;
    DataObject object;

    ClassDescriptor descriptor =

    targetContext.getEntityResolver().getClassDescriptor("MyEntity");
    DataObject anotherObject = new
    DeepMergeOperation(targetContext).merge
    (object, descriptor);

    DeepMergeOperation merges everything that is attached to a
    given
    object and is already resolved in memory. If you need to
    implement
    different logic, you can write your own version using
    DeepMergeOperation as a template. An example of a different
    graph
    traversal termination logic is ObjectDetachOperation that is
    based on
    a preset tree of relationships.

    Andrus
    On Apr 11, 2006, at 5:50 PM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Thank you for help. I make the changes as you say but I
    observe the
    DataContext.localObject(..) not set the relations (forign key
    id's).Can you help me for migrating
    objects with its relations through DataDomains.

    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik <andrus@objectstyle.org>
    Tarih: Monday, April 10, 2006 11:55
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    On Apr 10, 2006, at 11:48 AM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Is there a easy way to migrate created objects from one
    DataDomain
    to other DataDomain.

    Thank you...

    Technically DataObject belongs to a DataContext, so we should be
    speaking about moving objects between DataContexts (that in turn
    can
    belong to different DataDomains). This is done with
    DataContext.localObject(..)

    http://objectstyle.org/confluence/display/CAYDOC/Moving+Objects
    +Between+Contexts

    Of course object mappings have to be compatible in both domains
    involved.

    Andrus
  • Andrus Adamchik at Apr 12, 2006 at 8:10 am
    Can you explain what are you trying to achieve in general (i.e.
    scenario details)? I may be able to help then.

    Andrus
    On Apr 12, 2006, at 12:01 PM, emre.yilmaz@htr.com.tr wrote:

    Hi Andrus ,

    I tested DeepMergeOperation. Merged object on targetContext
    (anotherObject) is created as I desired with its relations but I
    observe actually anotherObject is not created physically on
    database .I used the targetContext.commitChanges() to create on
    database but not create it.What is the reason of this or how can
    commit created anotherObject on targetContext.


    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik
    Tarih: Tuesday, April 11, 2006 17:53
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    Yeah, default mechanism is "lazy" in that it assumes that
    related
    objects can be resolved from the database on demand. Copying
    a
    subgraph of new objects is a bit more tricky. In 1.2 you can
    try
    using org.objectstyle.cayenne.util.DeepMergeOperation for
    your
    purpose. Something like this:

    DataContext srcContext, targetContext;
    DataObject object;

    ClassDescriptor descriptor =

    targetContext.getEntityResolver().getClassDescriptor("MyEntity");
    DataObject anotherObject = new
    DeepMergeOperation(targetContext).merge
    (object, descriptor);

    DeepMergeOperation merges everything that is attached to a
    given
    object and is already resolved in memory. If you need to
    implement
    different logic, you can write your own version using
    DeepMergeOperation as a template. An example of a different
    graph
    traversal termination logic is ObjectDetachOperation that is
    based on
    a preset tree of relationships.

    Andrus
    On Apr 11, 2006, at 5:50 PM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Thank you for help. I make the changes as you say but I
    observe the
    DataContext.localObject(..) not set the relations (forign key
    id's).Can you help me for migrating
    objects with its relations through DataDomains.

    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik <andrus@objectstyle.org>
    Tarih: Monday, April 10, 2006 11:55
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    On Apr 10, 2006, at 11:48 AM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Is there a easy way to migrate created objects from one
    DataDomain
    to other DataDomain.

    Thank you...

    Technically DataObject belongs to a DataContext, so we should be
    speaking about moving objects between DataContexts (that in turn
    can
    belong to different DataDomains). This is done with
    DataContext.localObject(..)

    http://objectstyle.org/confluence/display/CAYDOC/Moving+Objects
    +Between+Contexts

    Of course object mappings have to be compatible in both domains
    involved.

    Andrus
  • Emre Yilmaz at Apr 12, 2006 at 8:32 am
    I want to distribute some entities from one dataDomain to another actually one database to identical other databases when a user insert,delete and update operations on these entities.To achieve this I create a superclass of object entities and I enforce the commit operation from this superclass to distribute the changes other contexts.Also I want to set this objects with relations and same primary keys on databases.
    ----------
    For insert : runs correctly without setting relations
    DataContext ctx = controllerContexts.get(domainName);
    DataObject dataObj = ctx.createAndRegisterNewObject(obj.getClass());
    ctx.localObject(dataObj.getObjectId(),obj);
    dataObj.setObjectId(obj.getObjectId());
    ctx.commitChanges();
    ----------
    For delete: runs correctly
    DataContext ctx = controllerContexts.get(domainName);
    DataObject dataObj = DataObjectUtils.objectForPK(ctx,obj.getObjectId());
    ctx.deleteObject(dataObj);
    ctx.commitChanges();
    --------
    For update:???
    ClassDescriptor descriptor =
    localContext.getEntityResolver().getClassDescriptor(obj.getClass().getSimpleName());
    System.err.println(new DeepMergeOperation(ctx).merge(obj, descriptor));
    ctx.commitChanges();
    --------



    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik
    Tarih: Wednesday, April 12, 2006 11:10
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    Can you explain what are you trying to achieve in general
    (i.e.
    scenario details)? I may be able to help then.

    Andrus
    On Apr 12, 2006, at 12:01 PM, emre.yilmaz@htr.com.tr wrote:

    Hi Andrus ,

    I tested DeepMergeOperation. Merged object on
    targetContext
    (anotherObject) is created as I desired with its relations but I
    observe actually anotherObject is not created physically on
    database .I used the targetContext.commitChanges() to create on
    database but not create it.What is the reason of this or how can
    commit created anotherObject on targetContext.


    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik
    Tarih: Tuesday, April 11, 2006 17:53
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    Yeah, default mechanism is "lazy" in that it assumes that
    related
    objects can be resolved from the database on demand. Copying
    a
    subgraph of new objects is a bit more tricky. In 1.2 you can
    try
    using org.objectstyle.cayenne.util.DeepMergeOperation for
    your
    purpose. Something like this:

    DataContext srcContext, targetContext;
    DataObject object;

    ClassDescriptor descriptor =

    targetContext.getEntityResolver().getClassDescriptor("MyEntity");
    DataObject anotherObject = new
    DeepMergeOperation(targetContext).merge
    (object, descriptor);

    DeepMergeOperation merges everything that is attached to a
    given
    object and is already resolved in memory. If you need to
    implement
    different logic, you can write your own version using
    DeepMergeOperation as a template. An example of a different
    graph
    traversal termination logic is ObjectDetachOperation that is
    based on
    a preset tree of relationships.

    Andrus
    On Apr 11, 2006, at 5:50 PM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Thank you for help. I make the changes as you say but I
    observe the
    DataContext.localObject(..) not set the relations (forign key
    id's).Can you help me for migrating
    objects with its relations through DataDomains.

    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik <andrus@objectstyle.org>
    Tarih: Monday, April 10, 2006 11:55
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    On Apr 10, 2006, at 11:48 AM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    Is there a easy way to migrate created objects from one
    DataDomain
    to other DataDomain.

    Thank you...

    Technically DataObject belongs to a DataContext, so we
    should be
    speaking about moving objects between DataContexts (that in turn
    can
    belong to different DataDomains). This is done with
    DataContext.localObject(..)

    http://objectstyle.org/confluence/display/CAYDOC/Moving+Objects
    +Between+Contexts

    Of course object mappings have to be compatible in both domains
    involved.

    Andrus
  • Andrus Adamchik at Apr 12, 2006 at 10:22 am

    On Apr 12, 2006, at 12:33 PM, emre.yilmaz@htr.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
  • Emre Yilmaz at Apr 13, 2006 at 10:37 am
    Hi,

    I have some problems. I download the cayenne-1.2-dev-2006-4-12.tar as you said. I use the your definitions but targetContext.onSync throws below exception when localContext.commitChanges().
    org.objectstyle.cayenne.access.ObjectStoreGraphDiff@3e97cd
    org.objectstyle.cayenne.property.PropertyAccessException: [v.1.2-dev-2006-4-12 April 12 2006] Error reading DataObject property: name
    at org.objectstyle.cayenne.property.DataObjectAccessor.readPropertyDirectly(DataObjectAccessor.java:98)
    at org.objectstyle.cayenne.property.SimpleProperty.readPropertyDirectly(SimpleProperty.java:110)
    at org.objectstyle.cayenne.property.SimpleProperty.readProperty(SimpleProperty.java:81)
    at org.objectstyle.cayenne.access.ObjectDiff$4.visitProperty(ObjectDiff.java:210)
    at org.objectstyle.cayenne.property.SimpleProperty.visit(SimpleProperty.java:94)
    at org.objectstyle.cayenne.property.BaseClassDescriptor.visitProperties(BaseClassDescriptor.java:247)
    at org.objectstyle.cayenne.access.ObjectDiff.applySimplePropertyChanges(ObjectDiff.java:206)
    at org.objectstyle.cayenne.access.ObjectDiff.access$100(ObjectDiff.java:28)
    at org.objectstyle.cayenne.access.ObjectDiff$2.apply(ObjectDiff.java:105)
    at org.objectstyle.cayenne.graph.CompoundDiff.apply(CompoundDiff.java:133)
    at org.objectstyle.cayenne.access.ObjectStoreGraphDiff.apply(ObjectStoreGraphDiff.java:151)
    at org.objectstyle.cayenne.access.DataContext.onContextFlush(DataContext.java:1171)
    at org.objectstyle.cayenne.access.DataContext.onSync(DataContext.java:1148)
    at tr.com.htr.hgys.db.base.DataListener.graphFlushed(DataListener.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.objectstyle.cayenne.util.Invocation.fire(Invocation.java:240)
    at org.objectstyle.cayenne.event.EventManager$Dispatch.fire(EventManager.java:433)
    at org.objectstyle.cayenne.event.DispatchQueue.dispatchEvent(DispatchQueue.java:182)
    at org.objectstyle.cayenne.event.DispatchQueue.dispatchEvent(DispatchQueue.java:94)
    at org.objectstyle.cayenne.event.EventManager.dispatchEvent(EventManager.java:372)
    at org.objectstyle.cayenne.event.EventManager.postEvent(EventManager.java:343)
    at org.objectstyle.cayenne.access.DataContext.fireDataChannelCommitted(DataContext.java:1616)
    at org.objectstyle.cayenne.access.DataContext.flushToParent(DataContext.java:1225)
    at org.objectstyle.cayenne.access.DataContext.commitChanges(DataContext.java:1121)
    at tr.com.htr.hgys.db.base.DbObject.commitChanges(DbObject.java:246)
    at tr.com.htr.hgys.db.Title.setTitle(Title.java:101)


    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik
    Tarih: Wednesday, April 12, 2006 13:23
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    On Apr 12, 2006, at 12:33 PM, emre.yilmaz@htr.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
  • Andrus Adamchik at Apr 13, 2006 at 11:05 am
    At this point to be able to help you I'd have to actually write a
    test app that does what you are doing, and perform some debugging.
    Unfortunately I can't do it right now, as this functionality is kind
    of a byproduct of other features (so it doesn't yet look like a
    Cayenne bug to me), and I have to work on other things.

    I guess you'll have to poke around on your own. If you find more
    specific problems in the process, please let us know - maybe we can
    fix them, but I can't investigate this right now, sorry.

    Andrus

    On Apr 13, 2006, at 2:37 PM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    I have some problems. I download the cayenne-1.2-dev-2006-4-12.tar
    as you said. I use the your definitions but targetContext.onSync
    throws below exception when localContext.commitChanges().
    org.objectstyle.cayenne.access.ObjectStoreGraphDiff@3e97cd
    org.objectstyle.cayenne.property.PropertyAccessException: [v.1.2-
    dev-2006-4-12 April 12 2006] Error reading DataObject property: name
    at
    org.objectstyle.cayenne.property.DataObjectAccessor.readPropertyDirect
    ly(DataObjectAccessor.java:98)
    at
    org.objectstyle.cayenne.property.SimpleProperty.readPropertyDirectly
    (SimpleProperty.java:110)
    at org.objectstyle.cayenne.property.SimpleProperty.readProperty
    (SimpleProperty.java:81)
    at org.objectstyle.cayenne.access.ObjectDiff$4.visitProperty
    (ObjectDiff.java:210)
    at org.objectstyle.cayenne.property.SimpleProperty.visit
    (SimpleProperty.java:94)
    at
    org.objectstyle.cayenne.property.BaseClassDescriptor.visitProperties
    (BaseClassDescriptor.java:247)
    at
    org.objectstyle.cayenne.access.ObjectDiff.applySimplePropertyChanges
    (ObjectDiff.java:206)
    at org.objectstyle.cayenne.access.ObjectDiff.access$100
    (ObjectDiff.java:28)
    at org.objectstyle.cayenne.access.ObjectDiff$2.apply
    (ObjectDiff.java:105)
    at org.objectstyle.cayenne.graph.CompoundDiff.apply
    (CompoundDiff.java:133)
    at org.objectstyle.cayenne.access.ObjectStoreGraphDiff.apply
    (ObjectStoreGraphDiff.java:151)
    at org.objectstyle.cayenne.access.DataContext.onContextFlush
    (DataContext.java:1171)
    at org.objectstyle.cayenne.access.DataContext.onSync
    (DataContext.java:1148)
    at tr.com.htr.hgys.db.base.DataListener.graphFlushed
    (DataListener.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.objectstyle.cayenne.util.Invocation.fire(Invocation.java:240)
    at org.objectstyle.cayenne.event.EventManager$Dispatch.fire
    (EventManager.java:433)
    at org.objectstyle.cayenne.event.DispatchQueue.dispatchEvent
    (DispatchQueue.java:182)
    at org.objectstyle.cayenne.event.DispatchQueue.dispatchEvent
    (DispatchQueue.java:94)
    at org.objectstyle.cayenne.event.EventManager.dispatchEvent
    (EventManager.java:372)
    at org.objectstyle.cayenne.event.EventManager.postEvent
    (EventManager.java:343)
    at
    org.objectstyle.cayenne.access.DataContext.fireDataChannelCommitted
    (DataContext.java:1616)
    at org.objectstyle.cayenne.access.DataContext.flushToParent
    (DataContext.java:1225)
    at org.objectstyle.cayenne.access.DataContext.commitChanges
    (DataContext.java:1121)
    at tr.com.htr.hgys.db.base.DbObject.commitChanges(DbObject.java:246)
    at tr.com.htr.hgys.db.Title.setTitle(Title.java:101)


    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik
    Tarih: Wednesday, April 12, 2006 13:23
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    On Apr 12, 2006, at 12:33 PM, emre.yilmaz@htr.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
  • Emre Yilmaz at Apr 13, 2006 at 11:54 am
    Thank you Andrus, I let you know If I find more specific problems in the process

    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik
    Tarih: Thursday, April 13, 2006 14:05
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    At this point to be able to help you I'd have to actually write
    a
    test app that does what you are doing, and perform some
    debugging.
    Unfortunately I can't do it right now, as this functionality is
    kind
    of a byproduct of other features (so it doesn't yet look like
    a
    Cayenne bug to me), and I have to work on other things.

    I guess you'll have to poke around on your own. If you find
    more
    specific problems in the process, please let us know - maybe we
    can
    fix them, but I can't investigate this right now, sorry.

    Andrus

    On Apr 13, 2006, at 2:37 PM, emre.yilmaz@htr.com.tr wrote:

    Hi,

    I have some problems. I download the cayenne-1.2-dev-2006-4- 12.tar
    as you said. I use the your definitions but
    targetContext.onSync
    throws below exception when localContext.commitChanges().
    org.objectstyle.cayenne.access.ObjectStoreGraphDiff@3e97cd
    org.objectstyle.cayenne.property.PropertyAccessException: [v.1.2-
    dev-2006-4-12 April 12 2006] Error reading DataObject
    property: name
    at
    org.objectstyle.cayenne.property.DataObjectAccessor.readPropertyDirect
    ly(DataObjectAccessor.java:98)
    at
    org.objectstyle.cayenne.property.SimpleProperty.readPropertyDirectly
    (SimpleProperty.java:110)
    at
    org.objectstyle.cayenne.property.SimpleProperty.readProperty
    (SimpleProperty.java:81)
    at org.objectstyle.cayenne.access.ObjectDiff$4.visitProperty
    (ObjectDiff.java:210)
    at org.objectstyle.cayenne.property.SimpleProperty.visit
    (SimpleProperty.java:94)
    at
    org.objectstyle.cayenne.property.BaseClassDescriptor.visitProperties
    (BaseClassDescriptor.java:247)
    at
    org.objectstyle.cayenne.access.ObjectDiff.applySimplePropertyChanges
    (ObjectDiff.java:206)
    at org.objectstyle.cayenne.access.ObjectDiff.access$100
    (ObjectDiff.java:28)
    at org.objectstyle.cayenne.access.ObjectDiff$2.apply
    (ObjectDiff.java:105)
    at org.objectstyle.cayenne.graph.CompoundDiff.apply
    (CompoundDiff.java:133)
    at org.objectstyle.cayenne.access.ObjectStoreGraphDiff.apply
    (ObjectStoreGraphDiff.java:151)
    at org.objectstyle.cayenne.access.DataContext.onContextFlush
    (DataContext.java:1171)
    at org.objectstyle.cayenne.access.DataContext.onSync
    (DataContext.java:1148)
    at tr.com.htr.hgys.db.base.DataListener.graphFlushed
    (DataListener.java:66)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.objectstyle.cayenne.util.Invocation.fire(Invocation.java:240)
    at org.objectstyle.cayenne.event.EventManager$Dispatch.fire
    (EventManager.java:433)
    at org.objectstyle.cayenne.event.DispatchQueue.dispatchEvent
    (DispatchQueue.java:182)
    at org.objectstyle.cayenne.event.DispatchQueue.dispatchEvent
    (DispatchQueue.java:94)
    at org.objectstyle.cayenne.event.EventManager.dispatchEvent
    (EventManager.java:372)
    at org.objectstyle.cayenne.event.EventManager.postEvent
    (EventManager.java:343)
    at
    org.objectstyle.cayenne.access.DataContext.fireDataChannelCommitted
    (DataContext.java:1616)
    at org.objectstyle.cayenne.access.DataContext.flushToParent
    (DataContext.java:1225)
    at org.objectstyle.cayenne.access.DataContext.commitChanges
    (DataContext.java:1121)
    at tr.com.htr.hgys.db.base.DbObject.commitChanges(DbObject.java:246)
    at tr.com.htr.hgys.db.Title.setTitle(Title.java:101)


    ----- Orjinal Mesaj -----
    Kimden: Andrus Adamchik
    Tarih: Wednesday, April 12, 2006 13:23
    Konu: Re: Object migrates between DataDomains
    Kime: cayenne-user@incubator.apache.org
    On Apr 12, 2006, at 12:33 PM, emre.yilmaz@htr.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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedApr 10, '06 at 7:48a
activeApr 13, '06 at 11:54a
posts11
users2
websitecayenne.apache.org

2 users in discussion

Emre Yilmaz: 6 posts Andrus Adamchik: 5 posts

People

Translate

site design / logo © 2022 Grokbase