You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Markus Reich <ma...@markusreich.at> on 2013/04/19 21:49:40 UTC
Webapplication with 2 ObjectContexts
Hi,
is it possible to create a second context to make an atomic update to an
object not disturbing the main context?
e.g.
in the application you can change data in a fom, there are two buttons
"save" and "revert"
by the way the user can add comments to the form, when he clicks add
comment a popup opens he can enter a text and this text should be saved,
but when I do a commit, the data changes in the form are also commited :-(
regards
Meex
Re: Webapplication with 2 ObjectContexts
Posted by Andrus Adamchik <an...@objectstyle.org>.
Yeah, you are free to create as many ObjectContexts as you need. That's what they are for - to provide you an isolated "area" for editing your objects without messing up anything else.
When modifying objects I often use contexts that are request-scoped, or even limited in scope to a single method that gets the objects, changes them, commits (and then the context goes out of scope and is garbage collected).
And like Mike said, in your case you need a regular top-level context, not a nested context.
Andrus
On Apr 19, 2013, at 4:20 PM, Mike Kienenberger <mk...@gmail.com> wrote:
> If you create a second non-child data context, then it should work
> just as you desire.
> Both contexts commit to the database independent of each other.
>
> On Fri, Apr 19, 2013 at 4:14 PM, Markus Reich
> <ma...@markusreich.at> wrote:
>> I tried, but it is not possible to commit data locally in a child context!
>> I just can commitToParent :-(
>>
>>
>> 2013/4/19 Marc A. Donis <ma...@runbox.com>
>>
>>> I think what you need is a child context. See CayenneRuntime.getContext(*
>>> *DataChannel <http://cayenne.apache.org/**docs/3.1/api/org/apache/**
>>> cayenne/DataChannel.html<http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/DataChannel.html>>
>>> parentChannel)
>>>
>>>
>>>
>>> On 19/4/2013 21:49, Markus Reich wrote:
>>>
>>>> Hi,
>>>>
>>>> is it possible to create a second context to make an atomic update to an
>>>> object not disturbing the main context?
>>>>
>>>> e.g.
>>>> in the application you can change data in a fom, there are two buttons
>>>> "save" and "revert"
>>>> by the way the user can add comments to the form, when he clicks add
>>>> comment a popup opens he can enter a text and this text should be saved,
>>>> but when I do a commit, the data changes in the form are also commited :-(
>>>>
>>>> regards
>>>> Meex
>>>>
>>>>
>>>
>>
>>
>> --
>> *Markus Reich*
>> Moosbach 28/2
>> 6392 St. Jakob i.H.
>> www.markusreich.at / www.meeximum.at
>> markus.reich@markusreich.at
>
Re: Webapplication with 2 ObjectContexts
Posted by Andrus Adamchik <an...@objectstyle.org>.
// since you have Cayenne running, you already have an instance of ServerRuntime somewhere..
// if you are using CayenneFilter, obtaining it might look like this:
ServletContext sc = ...
CayenneRuntime r = WebUtil.getCayenneRuntime(sc);
// this creates a new context on every call
ObjectContext c = r.getContext();
Andrus
On Apr 19, 2013, at 5:08 PM, Markus Reich <ma...@markusreich.at> wrote:
> I tried this too, but DataContext.createDataContext() isn't available in
> 3.1? how can I create a context
>
>
> 2013/4/19 Mike Kienenberger <mk...@gmail.com>
>
>> If you create a second non-child data context, then it should work
>> just as you desire.
>> Both contexts commit to the database independent of each other.
>>
>> On Fri, Apr 19, 2013 at 4:14 PM, Markus Reich
>> <ma...@markusreich.at> wrote:
>>> I tried, but it is not possible to commit data locally in a child
>> context!
>>> I just can commitToParent :-(
>>>
>>>
>>> 2013/4/19 Marc A. Donis <ma...@runbox.com>
>>>
>>>> I think what you need is a child context. See
>> CayenneRuntime.getContext(*
>>>> *DataChannel <http://cayenne.apache.org/**docs/3.1/api/org/apache/**
>>>> cayenne/DataChannel.html<
>> http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/DataChannel.html
>>>>
>>>> parentChannel)
>>>>
>>>>
>>>>
>>>> On 19/4/2013 21:49, Markus Reich wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> is it possible to create a second context to make an atomic update to
>> an
>>>>> object not disturbing the main context?
>>>>>
>>>>> e.g.
>>>>> in the application you can change data in a fom, there are two buttons
>>>>> "save" and "revert"
>>>>> by the way the user can add comments to the form, when he clicks add
>>>>> comment a popup opens he can enter a text and this text should be
>> saved,
>>>>> but when I do a commit, the data changes in the form are also commited
>> :-(
>>>>>
>>>>> regards
>>>>> Meex
>>>>>
>>>>>
>>>>
>>>
>>>
>>> --
>>> *Markus Reich*
>>> Moosbach 28/2
>>> 6392 St. Jakob i.H.
>>> www.markusreich.at / www.meeximum.at
>>> markus.reich@markusreich.at
>>
>
>
>
> --
> *Markus Reich*
> Moosbach 28/2
> 6392 St. Jakob i.H.
> www.markusreich.at / www.meeximum.at
> markus.reich@markusreich.at
Re: Webapplication with 2 ObjectContexts
Posted by Markus Reich <ma...@markusreich.at>.
I tried this too, but DataContext.createDataContext() isn't available in
3.1? how can I create a context
2013/4/19 Mike Kienenberger <mk...@gmail.com>
> If you create a second non-child data context, then it should work
> just as you desire.
> Both contexts commit to the database independent of each other.
>
> On Fri, Apr 19, 2013 at 4:14 PM, Markus Reich
> <ma...@markusreich.at> wrote:
> > I tried, but it is not possible to commit data locally in a child
> context!
> > I just can commitToParent :-(
> >
> >
> > 2013/4/19 Marc A. Donis <ma...@runbox.com>
> >
> >> I think what you need is a child context. See
> CayenneRuntime.getContext(*
> >> *DataChannel <http://cayenne.apache.org/**docs/3.1/api/org/apache/**
> >> cayenne/DataChannel.html<
> http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/DataChannel.html
> >>
> >> parentChannel)
> >>
> >>
> >>
> >> On 19/4/2013 21:49, Markus Reich wrote:
> >>
> >>> Hi,
> >>>
> >>> is it possible to create a second context to make an atomic update to
> an
> >>> object not disturbing the main context?
> >>>
> >>> e.g.
> >>> in the application you can change data in a fom, there are two buttons
> >>> "save" and "revert"
> >>> by the way the user can add comments to the form, when he clicks add
> >>> comment a popup opens he can enter a text and this text should be
> saved,
> >>> but when I do a commit, the data changes in the form are also commited
> :-(
> >>>
> >>> regards
> >>> Meex
> >>>
> >>>
> >>
> >
> >
> > --
> > *Markus Reich*
> > Moosbach 28/2
> > 6392 St. Jakob i.H.
> > www.markusreich.at / www.meeximum.at
> > markus.reich@markusreich.at
>
--
*Markus Reich*
Moosbach 28/2
6392 St. Jakob i.H.
www.markusreich.at / www.meeximum.at
markus.reich@markusreich.at
Re: Webapplication with 2 ObjectContexts
Posted by Mike Kienenberger <mk...@gmail.com>.
If you create a second non-child data context, then it should work
just as you desire.
Both contexts commit to the database independent of each other.
On Fri, Apr 19, 2013 at 4:14 PM, Markus Reich
<ma...@markusreich.at> wrote:
> I tried, but it is not possible to commit data locally in a child context!
> I just can commitToParent :-(
>
>
> 2013/4/19 Marc A. Donis <ma...@runbox.com>
>
>> I think what you need is a child context. See CayenneRuntime.getContext(*
>> *DataChannel <http://cayenne.apache.org/**docs/3.1/api/org/apache/**
>> cayenne/DataChannel.html<http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/DataChannel.html>>
>> parentChannel)
>>
>>
>>
>> On 19/4/2013 21:49, Markus Reich wrote:
>>
>>> Hi,
>>>
>>> is it possible to create a second context to make an atomic update to an
>>> object not disturbing the main context?
>>>
>>> e.g.
>>> in the application you can change data in a fom, there are two buttons
>>> "save" and "revert"
>>> by the way the user can add comments to the form, when he clicks add
>>> comment a popup opens he can enter a text and this text should be saved,
>>> but when I do a commit, the data changes in the form are also commited :-(
>>>
>>> regards
>>> Meex
>>>
>>>
>>
>
>
> --
> *Markus Reich*
> Moosbach 28/2
> 6392 St. Jakob i.H.
> www.markusreich.at / www.meeximum.at
> markus.reich@markusreich.at
Re: Webapplication with 2 ObjectContexts
Posted by Markus Reich <ma...@markusreich.at>.
I tried, but it is not possible to commit data locally in a child context!
I just can commitToParent :-(
2013/4/19 Marc A. Donis <ma...@runbox.com>
> I think what you need is a child context. See CayenneRuntime.getContext(*
> *DataChannel <http://cayenne.apache.org/**docs/3.1/api/org/apache/**
> cayenne/DataChannel.html<http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/DataChannel.html>>
> parentChannel)
>
>
>
> On 19/4/2013 21:49, Markus Reich wrote:
>
>> Hi,
>>
>> is it possible to create a second context to make an atomic update to an
>> object not disturbing the main context?
>>
>> e.g.
>> in the application you can change data in a fom, there are two buttons
>> "save" and "revert"
>> by the way the user can add comments to the form, when he clicks add
>> comment a popup opens he can enter a text and this text should be saved,
>> but when I do a commit, the data changes in the form are also commited :-(
>>
>> regards
>> Meex
>>
>>
>
--
*Markus Reich*
Moosbach 28/2
6392 St. Jakob i.H.
www.markusreich.at / www.meeximum.at
markus.reich@markusreich.at
Re: Webapplication with 2 ObjectContexts
Posted by "Marc A. Donis" <ma...@runbox.com>.
I think what you need is a child context. See
CayenneRuntime.getContext(DataChannel
<http://cayenne.apache.org/docs/3.1/api/org/apache/cayenne/DataChannel.html> parentChannel)
On 19/4/2013 21:49, Markus Reich wrote:
> Hi,
>
> is it possible to create a second context to make an atomic update to an
> object not disturbing the main context?
>
> e.g.
> in the application you can change data in a fom, there are two buttons
> "save" and "revert"
> by the way the user can add comments to the form, when he clicks add
> comment a popup opens he can enter a text and this text should be saved,
> but when I do a commit, the data changes in the form are also commited :-(
>
> regards
> Meex
>