You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Christian Grobmeier <gr...@gmail.com> on 2011/07/25 16:50:57 UTC

Configuration Class?

Hi

what is the correct approach here?
http://cayenne.apache.org/doc/understanding-transactions.html

DataDomain domain = Configuration.getSharedConfiguration().getDomain();
Transaction tx = domain.createTransaction();

The Configuration class is not in my jar anymore (3.1M2) so I guess it
has changed recently

Cheers,
Christian

Re: Configuration Class?

Posted by Christian Grobmeier <gr...@gmail.com>.
nice to compare it with SVN ;-)
Thanks!

On Mon, Jul 25, 2011 at 6:09 PM, Robert Zeigler
<ro...@roxanemy.com> wrote:
> Transactions start at "commitChanges".  Cayenne's feel is much more like svn to me than hibernate.  You "check out" objects (fetch them from the db) to your working "directory" (the object context).  You modify them, delete them, add new ones, etc.  Then a call to "commitChanges" sends everything back to the db in a single transaction, very much analogous to svn commit.  And rollbackChanges is very much analogous to svn -R revert .
>
> Robert
>
> On Jul 25, 2011, at 7/2511:01 AM , Christian Grobmeier wrote:
>
>>> Since ObjectContext (server or ROP client) is a "disconnected" object in Cayenne transactions are something different compared to say Hibernate (that's my guess anyways, I don't know much about Hibernate). Cayenne server transactions are a "bridge" to JDBC transactions (there's not Cayenne specific transactional behavior, other than locking a JDBC connection for the operation duration, and allowing users to delineate a custom JDBC tx scope).
>>
>> Very interesting for me, as I write about transaction for the article
>> at the moment.
>>
>> You wrote, ObjectContext is some kind of a "disconnected" object. If I
>> create two new objects in the ObjectContext, when does the transaction
>> start exactly? Is it when I call "registerNew" on the first object or
>> is it when I commit my changes (it then would create a transaction,
>> commit both new objects, close transaction)?
>>
>>>
>>> Since there's no JDBC on the ROP client, there are no Cayenne transaction there. Potentially we can extend this abstraction to the client, but it was thought originally that this will break a simple request/response webservice'y feel of ROP.
>>
>> Makes perfect sense
>> Cheers
>>
>>
>>>
>>> Andrus
>>>
>>>
>>> On Jul 25, 2011, at 6:18 PM, Christian Grobmeier wrote:
>>>
>>>>>> I was just surprise that getDataDomain() is not in CayenneRuntime. It
>>>>>> seemed to me that would be the logical place. I can see getChannel and
>>>>>> getContext is in CayenneRuntime too. So, why not getDataDomain?
>>>>>
>>>>> The answer is ROP. DataDomain is a "server" configuration object, and is not available in the "client" (ROP) configuration.
>>>>
>>>> Ah understood
>>>>
>>>> Does that mean a "ROP client" is not meant to work with transactions,
>>>> only the "ROP server" is? (not knowing to much about ROP at the
>>>> moment)
>>>>
>>>> Cheers
>>>> Christian
>>>>
>>>>>
>>>>> Andrus
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> http://www.grobmeier.de
>>>>
>>>
>>>
>>
>>
>>
>> --
>> http://www.grobmeier.de
>
>



-- 
http://www.grobmeier.de

Re: Configuration Class?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Very nice comparison! And if you add nested contexts to the picture, it turns into a certain subset of Git :-)


On Jul 25, 2011, at 7:09 PM, Robert Zeigler wrote:

> Transactions start at "commitChanges".  Cayenne's feel is much more like svn to me than hibernate.  You "check out" objects (fetch them from the db) to your working "directory" (the object context).  You modify them, delete them, add new ones, etc.  Then a call to "commitChanges" sends everything back to the db in a single transaction, very much analogous to svn commit.  And rollbackChanges is very much analogous to svn -R revert .
> 
> Robert
> 
> On Jul 25, 2011, at 7/2511:01 AM , Christian Grobmeier wrote:
> 
>>> Since ObjectContext (server or ROP client) is a "disconnected" object in Cayenne transactions are something different compared to say Hibernate (that's my guess anyways, I don't know much about Hibernate). Cayenne server transactions are a "bridge" to JDBC transactions (there's not Cayenne specific transactional behavior, other than locking a JDBC connection for the operation duration, and allowing users to delineate a custom JDBC tx scope).
>> 
>> Very interesting for me, as I write about transaction for the article
>> at the moment.
>> 
>> You wrote, ObjectContext is some kind of a "disconnected" object. If I
>> create two new objects in the ObjectContext, when does the transaction
>> start exactly? Is it when I call "registerNew" on the first object or
>> is it when I commit my changes (it then would create a transaction,
>> commit both new objects, close transaction)?
>> 
>>> 
>>> Since there's no JDBC on the ROP client, there are no Cayenne transaction there. Potentially we can extend this abstraction to the client, but it was thought originally that this will break a simple request/response webservice'y feel of ROP.
>> 
>> Makes perfect sense
>> Cheers
>> 
>> 
>>> 
>>> Andrus
>>> 
>>> 
>>> On Jul 25, 2011, at 6:18 PM, Christian Grobmeier wrote:
>>> 
>>>>>> I was just surprise that getDataDomain() is not in CayenneRuntime. It
>>>>>> seemed to me that would be the logical place. I can see getChannel and
>>>>>> getContext is in CayenneRuntime too. So, why not getDataDomain?
>>>>> 
>>>>> The answer is ROP. DataDomain is a "server" configuration object, and is not available in the "client" (ROP) configuration.
>>>> 
>>>> Ah understood
>>>> 
>>>> Does that mean a "ROP client" is not meant to work with transactions,
>>>> only the "ROP server" is? (not knowing to much about ROP at the
>>>> moment)
>>>> 
>>>> Cheers
>>>> Christian
>>>> 
>>>>> 
>>>>> Andrus
>>>>> 
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> http://www.grobmeier.de
>>>> 
>>> 
>>> 
>> 
>> 
>> 
>> -- 
>> http://www.grobmeier.de
> 
> 


Re: Configuration Class?

Posted by Robert Zeigler <ro...@roxanemy.com>.
Transactions start at "commitChanges".  Cayenne's feel is much more like svn to me than hibernate.  You "check out" objects (fetch them from the db) to your working "directory" (the object context).  You modify them, delete them, add new ones, etc.  Then a call to "commitChanges" sends everything back to the db in a single transaction, very much analogous to svn commit.  And rollbackChanges is very much analogous to svn -R revert .

Robert

On Jul 25, 2011, at 7/2511:01 AM , Christian Grobmeier wrote:

>> Since ObjectContext (server or ROP client) is a "disconnected" object in Cayenne transactions are something different compared to say Hibernate (that's my guess anyways, I don't know much about Hibernate). Cayenne server transactions are a "bridge" to JDBC transactions (there's not Cayenne specific transactional behavior, other than locking a JDBC connection for the operation duration, and allowing users to delineate a custom JDBC tx scope).
> 
> Very interesting for me, as I write about transaction for the article
> at the moment.
> 
> You wrote, ObjectContext is some kind of a "disconnected" object. If I
> create two new objects in the ObjectContext, when does the transaction
> start exactly? Is it when I call "registerNew" on the first object or
> is it when I commit my changes (it then would create a transaction,
> commit both new objects, close transaction)?
> 
>> 
>> Since there's no JDBC on the ROP client, there are no Cayenne transaction there. Potentially we can extend this abstraction to the client, but it was thought originally that this will break a simple request/response webservice'y feel of ROP.
> 
> Makes perfect sense
> Cheers
> 
> 
>> 
>> Andrus
>> 
>> 
>> On Jul 25, 2011, at 6:18 PM, Christian Grobmeier wrote:
>> 
>>>>> I was just surprise that getDataDomain() is not in CayenneRuntime. It
>>>>> seemed to me that would be the logical place. I can see getChannel and
>>>>> getContext is in CayenneRuntime too. So, why not getDataDomain?
>>>> 
>>>> The answer is ROP. DataDomain is a "server" configuration object, and is not available in the "client" (ROP) configuration.
>>> 
>>> Ah understood
>>> 
>>> Does that mean a "ROP client" is not meant to work with transactions,
>>> only the "ROP server" is? (not knowing to much about ROP at the
>>> moment)
>>> 
>>> Cheers
>>> Christian
>>> 
>>>> 
>>>> Andrus
>>>> 
>>>> 
>>> 
>>> 
>>> 
>>> --
>>> http://www.grobmeier.de
>>> 
>> 
>> 
> 
> 
> 
> -- 
> http://www.grobmeier.de


Re: Configuration Class?

Posted by Christian Grobmeier <gr...@gmail.com>.
>> You wrote, ObjectContext is some kind of a "disconnected" object. If I
>> create two new objects in the ObjectContext, when does the transaction
>> start exactly?
>
> When you call ObjectContext.commitChanges() (or performQuery() for that matter). Tx is started when an operation reaches DataDomain. Check uses of non-public DataDomain.runInTransaction() - this is the method that does tx wrapping.
>
>> Is it when I call "registerNew" on the first object or
>> is it when I commit my changes (it then would create a transaction,
>> commit both new objects, close transaction)?
>
> The later. Any changes to objects within a context are not wrapped in a transaction, can span multiple requests, etc., etc.

Cool, makes all sense - thanks!

Re: Configuration Class?

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jul 25, 2011, at 7:01 PM, Christian Grobmeier wrote:

> You wrote, ObjectContext is some kind of a "disconnected" object. If I
> create two new objects in the ObjectContext, when does the transaction
> start exactly?

When you call ObjectContext.commitChanges() (or performQuery() for that matter). Tx is started when an operation reaches DataDomain. Check uses of non-public DataDomain.runInTransaction() - this is the method that does tx wrapping.

> Is it when I call "registerNew" on the first object or
> is it when I commit my changes (it then would create a transaction,
> commit both new objects, close transaction)?

The later. Any changes to objects within a context are not wrapped in a transaction, can span multiple requests, etc., etc.

Andrus


Re: Configuration Class?

Posted by Christian Grobmeier <gr...@gmail.com>.
> Since ObjectContext (server or ROP client) is a "disconnected" object in Cayenne transactions are something different compared to say Hibernate (that's my guess anyways, I don't know much about Hibernate). Cayenne server transactions are a "bridge" to JDBC transactions (there's not Cayenne specific transactional behavior, other than locking a JDBC connection for the operation duration, and allowing users to delineate a custom JDBC tx scope).

Very interesting for me, as I write about transaction for the article
at the moment.

You wrote, ObjectContext is some kind of a "disconnected" object. If I
create two new objects in the ObjectContext, when does the transaction
start exactly? Is it when I call "registerNew" on the first object or
is it when I commit my changes (it then would create a transaction,
commit both new objects, close transaction)?

>
> Since there's no JDBC on the ROP client, there are no Cayenne transaction there. Potentially we can extend this abstraction to the client, but it was thought originally that this will break a simple request/response webservice'y feel of ROP.

Makes perfect sense
Cheers


>
> Andrus
>
>
> On Jul 25, 2011, at 6:18 PM, Christian Grobmeier wrote:
>
>>>> I was just surprise that getDataDomain() is not in CayenneRuntime. It
>>>> seemed to me that would be the logical place. I can see getChannel and
>>>> getContext is in CayenneRuntime too. So, why not getDataDomain?
>>>
>>> The answer is ROP. DataDomain is a "server" configuration object, and is not available in the "client" (ROP) configuration.
>>
>> Ah understood
>>
>> Does that mean a "ROP client" is not meant to work with transactions,
>> only the "ROP server" is? (not knowing to much about ROP at the
>> moment)
>>
>> Cheers
>> Christian
>>
>>>
>>> Andrus
>>>
>>>
>>
>>
>>
>> --
>> http://www.grobmeier.de
>>
>
>



-- 
http://www.grobmeier.de

Re: Configuration Class?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Correct. 

Since ObjectContext (server or ROP client) is a "disconnected" object in Cayenne transactions are something different compared to say Hibernate (that's my guess anyways, I don't know much about Hibernate). Cayenne server transactions are a "bridge" to JDBC transactions (there's not Cayenne specific transactional behavior, other than locking a JDBC connection for the operation duration, and allowing users to delineate a custom JDBC tx scope). 

Since there's no JDBC on the ROP client, there are no Cayenne transaction there. Potentially we can extend this abstraction to the client, but it was thought originally that this will break a simple request/response webservice'y feel of ROP.

Andrus


On Jul 25, 2011, at 6:18 PM, Christian Grobmeier wrote:

>>> I was just surprise that getDataDomain() is not in CayenneRuntime. It
>>> seemed to me that would be the logical place. I can see getChannel and
>>> getContext is in CayenneRuntime too. So, why not getDataDomain?
>> 
>> The answer is ROP. DataDomain is a "server" configuration object, and is not available in the "client" (ROP) configuration.
> 
> Ah understood
> 
> Does that mean a "ROP client" is not meant to work with transactions,
> only the "ROP server" is? (not knowing to much about ROP at the
> moment)
> 
> Cheers
> Christian
> 
>> 
>> Andrus
>> 
>> 
> 
> 
> 
> -- 
> http://www.grobmeier.de
> 


Re: Configuration Class?

Posted by Christian Grobmeier <gr...@gmail.com>.
>> I was just surprise that getDataDomain() is not in CayenneRuntime. It
>> seemed to me that would be the logical place. I can see getChannel and
>> getContext is in CayenneRuntime too. So, why not getDataDomain?
>
> The answer is ROP. DataDomain is a "server" configuration object, and is not available in the "client" (ROP) configuration.

Ah understood

Does that mean a "ROP client" is not meant to work with transactions,
only the "ROP server" is? (not knowing to much about ROP at the
moment)

Cheers
Christian

>
> Andrus
>
>



-- 
http://www.grobmeier.de

Re: Configuration Class?

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jul 25, 2011, at 6:10 PM, Christian Grobmeier wrote:

> I was just surprise that getDataDomain() is not in CayenneRuntime. It
> seemed to me that would be the logical place. I can see getChannel and
> getContext is in CayenneRuntime too. So, why not getDataDomain?

The answer is ROP. DataDomain is a "server" configuration object, and is not available in the "client" (ROP) configuration.

Andrus


Re: Configuration Class?

Posted by Christian Grobmeier <gr...@gmail.com>.
Hi Andrus,

thanks, that helped already. But one more question. I use the
CayenneFilter which uses WebUtil to put my ServerRuntime. If I want to
get it again, I use that bunch of code (this refers to Struts 2 Action
ServletContextAware).

CayenneRuntime cayenneRuntime =
WebUtil.getCayenneRuntime(this.getServletContext());
ServerRuntime serverRuntime = ((ServerRuntime)cayenneRuntime);
serverRuntime.getDataDomain();

I was just surprise that getDataDomain() is not in CayenneRuntime. It
seemed to me that would be the logical place. I can see getChannel and
getContext is in CayenneRuntime too. So, why not getDataDomain?

Cheers,
Christian



On Mon, Jul 25, 2011 at 4:54 PM, Andrus Adamchik <an...@objectstyle.org> wrote:
> Hi Christian,
>
> the approach is essentially the same (until we switch transaction factory to DI that is) - you need a hold of DataDomain instance, and use it to create transactions. In 3.1 You'd get DataDomain from ServerRuntime:
>
> ServerRuntime r = ...
> DataDomain d = r.getDataDomain();
>
> Of course how you get a hold of ServerRuntime is application-specific.
>
> Cheers,
> Andrus
>
> On Jul 25, 2011, at 5:50 PM, Christian Grobmeier wrote:
>
>> Hi
>>
>> what is the correct approach here?
>> http://cayenne.apache.org/doc/understanding-transactions.html
>>
>> DataDomain domain = Configuration.getSharedConfiguration().getDomain();
>> Transaction tx = domain.createTransaction();
>>
>> The Configuration class is not in my jar anymore (3.1M2) so I guess it
>> has changed recently
>>
>> Cheers,
>> Christian
>>
>
>



-- 
http://www.grobmeier.de

Re: Configuration Class?

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Christian,

the approach is essentially the same (until we switch transaction factory to DI that is) - you need a hold of DataDomain instance, and use it to create transactions. In 3.1 You'd get DataDomain from ServerRuntime:

ServerRuntime r = ...
DataDomain d = r.getDataDomain();

Of course how you get a hold of ServerRuntime is application-specific.

Cheers,
Andrus

On Jul 25, 2011, at 5:50 PM, Christian Grobmeier wrote:

> Hi
> 
> what is the correct approach here?
> http://cayenne.apache.org/doc/understanding-transactions.html
> 
> DataDomain domain = Configuration.getSharedConfiguration().getDomain();
> Transaction tx = domain.createTransaction();
> 
> The Configuration class is not in my jar anymore (3.1M2) so I guess it
> has changed recently
> 
> Cheers,
> Christian
>