You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Daniel Bruegge <da...@googlemail.com> on 2012/01/11 15:37:41 UTC

Working with DataContext after manipulating datasource

Hi,

I am trying to change dynamically the database server and connection
in the application code. I am using the PoolManager and
DataSource-setting like described in
https://cwiki.apache.org/CAY/setting-database-connection.html.

What I was wondering:  if I change this connection things with the
code above, will the next created DataContext using the new server?
I am creating the context via

DataContext.createDataContext();

set to the new server?

Thanks & regards

Daniel

Re: Working with DataContext after manipulating datasource

Posted by Andrus Adamchik <an...@objectstyle.org>.
Yes, it is possible by implementing your own DataSource wrapper, so that it allocates the right connection for a given execution thread, with the DB server switching done in your code outside Cayenne. 

If you can describe the full scenario, I can comment on possible caveats related to switching the DB underneath Cayenne.

Andrus

On Jan 11, 2012, at 9:02 PM, Daniel Bruegge wrote:

> Oh. Good to know. But is there a way to change the server dynamically
> when executing one statement?
> 
> On Wed, Jan 11, 2012 at 3:53 PM, Andrus Adamchik <an...@objectstyle.org> wrote:
>> Hi Daniel,
>> 
>> Since DataSource is attached to the DataNode, which is one of the shared parts of Cayenne stack, not only new DataContexts, but all the existing ones will pick it up the moment you set it.
>> 
>> Andrus
>> 
>> On Jan 11, 2012, at 5:37 PM, Daniel Bruegge wrote:
>> 
>>> Hi,
>>> 
>>> I am trying to change dynamically the database server and connection
>>> in the application code. I am using the PoolManager and
>>> DataSource-setting like described in
>>> https://cwiki.apache.org/CAY/setting-database-connection.html.
>>> 
>>> What I was wondering:  if I change this connection things with the
>>> code above, will the next created DataContext using the new server?
>>> I am creating the context via
>>> 
>>> DataContext.createDataContext();
>>> 
>>> set to the new server?
>>> 
>>> Thanks & regards
>>> 
>>> Daniel
>>> 
>> 
> 


Re: Working with DataContext after manipulating datasource

Posted by Daniel Bruegge <da...@googlemail.com>.
Oh. Good to know. But is there a way to change the server dynamically
when executing one statement?

On Wed, Jan 11, 2012 at 3:53 PM, Andrus Adamchik <an...@objectstyle.org> wrote:
> Hi Daniel,
>
> Since DataSource is attached to the DataNode, which is one of the shared parts of Cayenne stack, not only new DataContexts, but all the existing ones will pick it up the moment you set it.
>
> Andrus
>
> On Jan 11, 2012, at 5:37 PM, Daniel Bruegge wrote:
>
>> Hi,
>>
>> I am trying to change dynamically the database server and connection
>> in the application code. I am using the PoolManager and
>> DataSource-setting like described in
>> https://cwiki.apache.org/CAY/setting-database-connection.html.
>>
>> What I was wondering:  if I change this connection things with the
>> code above, will the next created DataContext using the new server?
>> I am creating the context via
>>
>> DataContext.createDataContext();
>>
>> set to the new server?
>>
>> Thanks & regards
>>
>> Daniel
>>
>

Re: Working with DataContext after manipulating datasource

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

Since DataSource is attached to the DataNode, which is one of the shared parts of Cayenne stack, not only new DataContexts, but all the existing ones will pick it up the moment you set it.

Andrus

On Jan 11, 2012, at 5:37 PM, Daniel Bruegge wrote:

> Hi,
> 
> I am trying to change dynamically the database server and connection
> in the application code. I am using the PoolManager and
> DataSource-setting like described in
> https://cwiki.apache.org/CAY/setting-database-connection.html.
> 
> What I was wondering:  if I change this connection things with the
> code above, will the next created DataContext using the new server?
> I am creating the context via
> 
> DataContext.createDataContext();
> 
> set to the new server?
> 
> Thanks & regards
> 
> Daniel
> 


Re: Working with DataContext after manipulating datasource

Posted by Andrus Adamchik <an...@objectstyle.org>.
Although... take this back. CAY is a wiki, not a docs export. Sorry for the noise :-)


On Jan 11, 2012, at 5:52 PM, Andrus Adamchik wrote:

> Begin forwarded message:
> 
>> https://cwiki.apache.org/CAY/setting-database-connection.html.
> 
> This is the reason I wanted to delete all the temp publish directories - there's no pointed google search for Cayenne docs :-/
> 
> Andrus
> 
> 


Fwd: Working with DataContext after manipulating datasource

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

Begin forwarded message:

> https://cwiki.apache.org/CAY/setting-database-connection.html.

This is the reason I wanted to delete all the temp publish directories - there's no pointed google search for Cayenne docs :-/

Andrus