Re: Object migrates between DataDomains

From: emre.yilma..tr.com.tr
Date: Wed Apr 12 2006 - 04:33:01 EDT

  • Next message: Andrus Adamchik: "Re: Object migrates between DataDomains"

    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-use..ncubator.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.yilma..tr.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-use..ncubator.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.yilma..tr.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 <andru..bjectstyle.org>
    > >>> Tarih: Monday, April 10, 2006 11:55
    > >>> Konu: Re: Object migrates between DataDomains
    > >>> Kime: cayenne-use..ncubator.apache.org
    > >>>
    > >>>>
    > >>>> On Apr 10, 2006, at 11:48 AM, emre.yilma..tr.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
    > >>>>
    > >>>>
    > >>>
    > >>
    > >>
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Apr 12 2006 - 04:32:56 EDT