Cool, and we are now discussing on the dev list how to make the API more straightforward by removing the need to cast.
Andrus On Sep 6, 2013, at 8:20 AM, Markus Reich <[email protected]> wrote: > Hi, > > works perfect!! API docu was just a bit confusing concerning the new method > for creating a child context :-( > > Thank you > Meex > > > 2013/9/5 Andrus Adamchik <[email protected]> > >> Here is how you create a child context in 3.2 (in 3.1 'newContext' was >> called 'getContext', otherwise it is similar) : >> >> ObjectContext context = runtime.newContext(); >> ObjectContext childContext = runtime.newContext((DataChannel) context); >> >> I.e. the parent context is a channel of the child. The cast above is >> possible since DataContext implements DataChannel. >> >> Andrus >> >> >> On Sep 5, 2013, at 5:04 PM, John Huss <[email protected]> wrote: >> >>> You aren't creating the child context correctly. I don't recall the >> proper >>> way to do it in 3.1+ >>> >>> >>> On Thu, Sep 5, 2013 at 8:11 AM, Markus Reich < >> [email protected]>wrote: >>> >>>> ah ok, thx! >>>> >>>> But I still don't understand the whole thing :-( >>>> >>>> No the test reacts like this >>>> >>>> @Test >>>> public void testChildContext() { >>>> // create test instance >>>> MiiPickingcontainer container = >>>> MiiPickingcontainer.createInstance(context, "9999", "9999", "JUNIT"); >>>> context.commitChanges(); >>>> >>>> Assert.assertEquals(0, context.modifiedObjects().size()); >>>> ObjectContext childContext = >> runtime.newContext(context.getChannel()); >>>> // move object to child context >>>> container = childContext.localObject(container); >>>> container.setStatusid(330); >>>> Assert.assertEquals(0, context.modifiedObjects().size()); >>>> Assert.assertEquals(1, childContext.modifiedObjects().size()); >>>> // commit childcontext >>>> childContext.commitChangesToParent(); >>>> Assert.assertEquals(0, context.modifiedObjects().size()); >>>> Assert.assertEquals(0, childContext.modifiedObjects().size()); >>>> } >>>> >>>> and I thought the commitChangesToParent() moves the object from child to >>>> parent context? So after the commitToParent() the data is written and >>>> committed to db? >>>> >>>> regards >>>> Meex >>>> >>>> >>>> >>>> 2013/9/5 John Huss <[email protected]> >>>> >>>>> You have to assign the result of localObject. >>>>> >>>>> John >>>>> On Sep 5, 2013 12:59 AM, "Markus Reich" <[email protected]> >>>>> wrote: >>>>> >>>>>> Hi, >>>>>> >>>>>> I've a question concering child contexts, when I add an object to a >>>> child >>>>>> context with method localObject, I thought the object is really from >>>>> parent >>>>>> to child context? >>>>>> >>>>>> But when I run the following JUnit Test, it doesn't fail, although it >>>>>> should? >>>>>> >>>>>> @Test >>>>>> public void testChildContext() { >>>>>> // create test instance >>>>>> MiiPickingcontainer container = >>>>>> MiiPickingcontainer.createInstance(context, "9999", "9999", "JUNIT"); >>>>>> context.commitChanges(); >>>>>> >>>>>> Assert.assertEquals(0, context.modifiedObjects().size()); >>>>>> ObjectContext childContext = >>>>> runtime.newContext(context.getChannel()); >>>>>> // move object to child context >>>>>> childContext.localObject(container); >>>>>> container.setStatusid(330); >>>>>> Assert.assertEquals(1, context.modifiedObjects().size()); >>>>>> Assert.assertEquals(0, childContext.modifiedObjects().size()); >>>>>> // commit childcontext >>>>>> childContext.commitChangesToParent(); >>>>>> Assert.assertEquals(1, context.modifiedObjects().size()); >>>>>> Assert.assertEquals(0, childContext.modifiedObjects().size()); >>>>>> >>>>>> // clean up >>>>>> context.deleteObjects(container); >>>>>> context.commitChanges(); >>>>>> } >>>>>> >>>>>> I'm using Cayenne 3.2M1 >>>>>> >>>>>> kind regards >>>>>> >>>>>> Meex >>>>>> >>>>> >>>> >>>> >>>> >>>> -- >>>> *Markus Reich* >>>> Moosbach 28/2 >>>> 6392 St. Jakob i.H. >>>> www.markusreich.at / www.meeximum.at >>>> [email protected] >>>> >> >> > > > -- > *Markus Reich* > Moosbach 28/2 > 6392 St. Jakob i.H. > www.markusreich.at / www.meeximum.at > [email protected]
