Handling Multiple Databases

View: New views
7 Messages — Rating Filter:   Alert me  

Handling Multiple Databases

by Norman Elton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've got an application that connects to one of a series of database
servers. I need to programmatically say, "drop all your connections
and change to server X". So far, I see two methods to accomplish this:

- Somehow make a ConnectionFactory-esque class that generates
connections to the "active" server. I'm not entirely sure how this
would integrate into c3p0. From there, I could call a softReset
whenever the "active" server changes. Some sort of ConnectionChecker
could reinforce this.

- Use multiple, stand-alone instances of ComboPooledDataSource, each
connecting to a single server. My application would draw a connection
from whichever pool was "active".

The first implementation seems the cleanest, since there wouldn't be
redundancy in the helper threads, etc. But I'm a little foggy on where
to start. Would I generate multiple DriverManagerDataSources, then a
single WrapperConnectionPoolDataSource, and using setNestedDataSource
to swap out the "active" datasource?

The second implementation is more straight-forward. But how much
penalty am I incurring by managing two to four concurrent
ComboPoolDataSources?

Thanks!

Norman

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
c3p0-users mailing list
c3p0-users@...
https://lists.sourceforge.net/lists/listinfo/c3p0-users

Re: Handling Multiple Databases

by Steve Waldman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why not just destroy DataSources to the old DB and create a DataSource  
on the new DB as needed? [ You could easily wrap the logic of this  
into a factory method, MyDataSourceFactory.switchTo(String jdcUrl,  
Properties props), something like that. ]

        smiles,
           Steve


On Jun 11, 2009, at 8:06 PM, Norman Elton wrote:

> I've got an application that connects to one of a series of database
> servers. I need to programmatically say, "drop all your connections
> and change to server X". So far, I see two methods to accomplish this:
>
> - Somehow make a ConnectionFactory-esque class that generates
> connections to the "active" server. I'm not entirely sure how this
> would integrate into c3p0. From there, I could call a softReset
> whenever the "active" server changes. Some sort of ConnectionChecker
> could reinforce this.
>
> - Use multiple, stand-alone instances of ComboPooledDataSource, each
> connecting to a single server. My application would draw a connection
> from whichever pool was "active".
>
> The first implementation seems the cleanest, since there wouldn't be
> redundancy in the helper threads, etc. But I'm a little foggy on where
> to start. Would I generate multiple DriverManagerDataSources, then a
> single WrapperConnectionPoolDataSource, and using setNestedDataSource
> to swap out the "active" datasource?
>
> The second implementation is more straight-forward. But how much
> penalty am I incurring by managing two to four concurrent
> ComboPoolDataSources?
>
> Thanks!
>
> Norman
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> c3p0-users mailing list
> c3p0-users@...
> https://lists.sourceforge.net/lists/listinfo/c3p0-users

~oo~
Steve Waldman
swaldman@...




------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
c3p0-users mailing list
c3p0-users@...
https://lists.sourceforge.net/lists/listinfo/c3p0-users

Re: Handling Multiple Databases

by Norman Elton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Do you mean completely tear down and recreate the
ComboPooledDataSource? This seems a little drastic, although I guess
it would work. Ideally, I'd like the connection pool to keep going,
but empty itself and start creating connections to the new database. I
suppose, functionally, they're the same thing. But the latter would
allow me to do a softReset so that existing connections continue to
work until they're returned.

Admittedly, I'm still wrapping my head around the terminology here
(just started with c3p0 today!), maybe I'm missing something obvious?

Thanks for your help,

Norman

On Thu, Jun 11, 2009 at 1:49 PM, Steve Waldman<swaldman@...> wrote:

> Why not just destroy DataSources to the old DB and create a DataSource on
> the new DB as needed? [ You could easily wrap the logic of this into a
> factory method, MyDataSourceFactory.switchTo(String jdcUrl, Properties
> props), something like that. ]
>
>       smiles,
>          Steve
>
>
> On Jun 11, 2009, at 8:06 PM, Norman Elton wrote:
>
>> I've got an application that connects to one of a series of database
>> servers. I need to programmatically say, "drop all your connections
>> and change to server X". So far, I see two methods to accomplish this:
>>
>> - Somehow make a ConnectionFactory-esque class that generates
>> connections to the "active" server. I'm not entirely sure how this
>> would integrate into c3p0. From there, I could call a softReset
>> whenever the "active" server changes. Some sort of ConnectionChecker
>> could reinforce this.
>>
>> - Use multiple, stand-alone instances of ComboPooledDataSource, each
>> connecting to a single server. My application would draw a connection
>> from whichever pool was "active".
>>
>> The first implementation seems the cleanest, since there wouldn't be
>> redundancy in the helper threads, etc. But I'm a little foggy on where
>> to start. Would I generate multiple DriverManagerDataSources, then a
>> single WrapperConnectionPoolDataSource, and using setNestedDataSource
>> to swap out the "active" datasource?
>>
>> The second implementation is more straight-forward. But how much
>> penalty am I incurring by managing two to four concurrent
>> ComboPoolDataSources?
>>
>> Thanks!
>>
>> Norman
>>
>>
>> ------------------------------------------------------------------------------
>> Crystal Reports - New Free Runtime and 30 Day Trial
>> Check out the new simplified licensing option that enables unlimited
>> royalty-free distribution of the report engine for externally facing
>> server and web deployment.
>> http://p.sf.net/sfu/businessobjects
>> _______________________________________________
>> c3p0-users mailing list
>> c3p0-users@...
>> https://lists.sourceforge.net/lists/listinfo/c3p0-users
>
> ~oo~
> Steve Waldman
> swaldman@...
>
>
>
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
c3p0-users mailing list
c3p0-users@...
https://lists.sourceforge.net/lists/listinfo/c3p0-users

Parent Message unknown Re: Handling Multiple Databases

by Norman Elton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Call me crazy, but I may have found an even simpler way. It looks like
if I just call .setJdbcUrl() on my ComboPooledDataSource, it calls a
softReset (technically, this.resetPoolManager(false)) and
reinitializes the pool.

Do you see any problems just changing the URL and marching on?

Thanks,

Norman

On Thu, Jun 11, 2009 at 2:08 PM, Steve Waldman<swaldman@...> wrote:

> In terms of overhead, I'd think that next to tearing down the Connections,
> tearing down the DataSource is pretty much negligible. And you want to tear
> down the Connection -- you said you'd prefer not to maintain the overhead of
> several unused pools (that would be the fastest approach, but would use a
> bit more memory and network resources). Alternatively you could keep several
> DataSources open, and just set minPoolSize=1, letting the pool grow when you
> shift from one DB to the next.
>
> But my guess is the simplest solution, tear down and recreate, will be best
> unless you are switching databases with great frequency. If minPoolSize
> isn't huge and you don't switch more often than say once in 10 mins, I think
> the benefits of simplicity are likely to overwhelm any small gains in
> efficiency. (If you are switching frequently, don't softReset() either, cuz
> you'll incur the overhead of all the Cxn destruction and recreation. If you
> need to shift constantly, then you do need to keep a set of DataSources live
> and active.)
>
>       smiles,
>          Steve
>
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
c3p0-users mailing list
c3p0-users@...
https://lists.sourceforge.net/lists/listinfo/c3p0-users

Re: Handling Multiple Databases

by Steve Waldman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Call me crazy, but I may have found an even simpler way. It looks like
> if I just call .setJdbcUrl() on my ComboPooledDataSource, it calls a
> softReset (technically, this.resetPoolManager(false)) and
> reinitializes the pool.
>
> Do you see any problems just changing the URL and marching on?


No, that's true. If you change any of the core config params, it soft  
resets to ensure the change takes uniformly. That's a perfectly fine  
idea, elegant and simple.

     smiles,
        Steve


On Jun 11, 2009, at 11:01 PM, Norman Elton wrote:

> Call me crazy, but I may have found an even simpler way. It looks like
> if I just call .setJdbcUrl() on my ComboPooledDataSource, it calls a
> softReset (technically, this.resetPoolManager(false)) and
> reinitializes the pool.
>
> Do you see any problems just changing the URL and marching on?
>
> Thanks,
>
> Norman
>
> On Thu, Jun 11, 2009 at 2:08 PM, Steve Waldman<swaldman@...>  
> wrote:
>> In terms of overhead, I'd think that next to tearing down the  
>> Connections,
>> tearing down the DataSource is pretty much negligible. And you want  
>> to tear
>> down the Connection -- you said you'd prefer not to maintain the  
>> overhead of
>> several unused pools (that would be the fastest approach, but would  
>> use a
>> bit more memory and network resources). Alternatively you could  
>> keep several
>> DataSources open, and just set minPoolSize=1, letting the pool grow  
>> when you
>> shift from one DB to the next.
>>
>> But my guess is the simplest solution, tear down and recreate, will  
>> be best
>> unless you are switching databases with great frequency. If  
>> minPoolSize
>> isn't huge and you don't switch more often than say once in 10  
>> mins, I think
>> the benefits of simplicity are likely to overwhelm any small gains in
>> efficiency. (If you are switching frequently, don't softReset()  
>> either, cuz
>> you'll incur the overhead of all the Cxn destruction and  
>> recreation. If you
>> need to shift constantly, then you do need to keep a set of  
>> DataSources live
>> and active.)
>>
>>       smiles,
>>          Steve
>>
>>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> c3p0-users mailing list
> c3p0-users@...
> https://lists.sourceforge.net/lists/listinfo/c3p0-users

~oo~
Steve Waldman
swaldman@...




------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
c3p0-users mailing list
c3p0-users@...
https://lists.sourceforge.net/lists/listinfo/c3p0-users

Re: Handling Multiple Databases

by Norman Elton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Steve,

I'm beginning to dabble in Hibernate, and this may be a question for
the hibernate mailing list... I see that Hibernate has native support
for c3p0. But can I access the DataSource to twiddle settings like
JdbcUrl when it's all wrapped up inside Hibernate?

Thanks!

Norman



On Thu, Jun 11, 2009 at 4:08 PM, Steve Waldman<swaldman@...> wrote:

>> Call me crazy, but I may have found an even simpler way. It looks like
>> if I just call .setJdbcUrl() on my ComboPooledDataSource, it calls a
>> softReset (technically, this.resetPoolManager(false)) and
>> reinitializes the pool.
>>
>> Do you see any problems just changing the URL and marching on?
>
>
> No, that's true. If you change any of the core config params, it soft resets
> to ensure the change takes uniformly. That's a perfectly fine idea, elegant
> and simple.
>
>    smiles,
>       Steve
>
>
> On Jun 11, 2009, at 11:01 PM, Norman Elton wrote:
>
>> Call me crazy, but I may have found an even simpler way. It looks like
>> if I just call .setJdbcUrl() on my ComboPooledDataSource, it calls a
>> softReset (technically, this.resetPoolManager(false)) and
>> reinitializes the pool.
>>
>> Do you see any problems just changing the URL and marching on?
>>
>> Thanks,
>>
>> Norman
>>
>> On Thu, Jun 11, 2009 at 2:08 PM, Steve Waldman<swaldman@...>
>> wrote:
>>>
>>> In terms of overhead, I'd think that next to tearing down the
>>> Connections,
>>> tearing down the DataSource is pretty much negligible. And you want to
>>> tear
>>> down the Connection -- you said you'd prefer not to maintain the overhead
>>> of
>>> several unused pools (that would be the fastest approach, but would use a
>>> bit more memory and network resources). Alternatively you could keep
>>> several
>>> DataSources open, and just set minPoolSize=1, letting the pool grow when
>>> you
>>> shift from one DB to the next.
>>>
>>> But my guess is the simplest solution, tear down and recreate, will be
>>> best
>>> unless you are switching databases with great frequency. If minPoolSize
>>> isn't huge and you don't switch more often than say once in 10 mins, I
>>> think
>>> the benefits of simplicity are likely to overwhelm any small gains in
>>> efficiency. (If you are switching frequently, don't softReset() either,
>>> cuz
>>> you'll incur the overhead of all the Cxn destruction and recreation. If
>>> you
>>> need to shift constantly, then you do need to keep a set of DataSources
>>> live
>>> and active.)
>>>
>>>      smiles,
>>>         Steve
>>>
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> Crystal Reports - New Free Runtime and 30 Day Trial
>> Check out the new simplified licensing option that enables unlimited
>> royalty-free distribution of the report engine for externally facing
>> server and web deployment.
>> http://p.sf.net/sfu/businessobjects
>> _______________________________________________
>> c3p0-users mailing list
>> c3p0-users@...
>> https://lists.sourceforge.net/lists/listinfo/c3p0-users
>
> ~oo~
> Steve Waldman
> swaldman@...
>
>
>
>

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
c3p0-users mailing list
c3p0-users@...
https://lists.sourceforge.net/lists/listinfo/c3p0-users

Re: Handling Multiple Databases

by Steve Waldman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Norman,

In newer versions of hibernate, you should be able to set arbitrary  
c3p0 params in hibernate's config (it used to be that you could only  
set five params that hibernate specifically exposed). however, the  
datasource itself is buried, so harder to get at programmatically.

Fortunately, you can always find c3p0 DataSources using the  
C3P0Registry class. See the API docs.

     smiles,
        Steve


On Jun 17, 2009, at 6:15 AM, Norman Elton wrote:

> Steve,
>
> I'm beginning to dabble in Hibernate, and this may be a question for
> the hibernate mailing list... I see that Hibernate has native support
> for c3p0. But can I access the DataSource to twiddle settings like
> JdbcUrl when it's all wrapped up inside Hibernate?
>
> Thanks!
>
> Norman
>
>
>
> On Thu, Jun 11, 2009 at 4:08 PM, Steve Waldman<swaldman@...>  
> wrote:
>>> Call me crazy, but I may have found an even simpler way. It looks  
>>> like
>>> if I just call .setJdbcUrl() on my ComboPooledDataSource, it calls a
>>> softReset (technically, this.resetPoolManager(false)) and
>>> reinitializes the pool.
>>>
>>> Do you see any problems just changing the URL and marching on?
>>
>>
>> No, that's true. If you change any of the core config params, it  
>> soft resets
>> to ensure the change takes uniformly. That's a perfectly fine idea,  
>> elegant
>> and simple.
>>
>>    smiles,
>>       Steve
>>
>>
>> On Jun 11, 2009, at 11:01 PM, Norman Elton wrote:
>>
>>> Call me crazy, but I may have found an even simpler way. It looks  
>>> like
>>> if I just call .setJdbcUrl() on my ComboPooledDataSource, it calls a
>>> softReset (technically, this.resetPoolManager(false)) and
>>> reinitializes the pool.
>>>
>>> Do you see any problems just changing the URL and marching on?
>>>
>>> Thanks,
>>>
>>> Norman
>>>
>>> On Thu, Jun 11, 2009 at 2:08 PM, Steve Waldman<swaldman@...>
>>> wrote:
>>>>
>>>> In terms of overhead, I'd think that next to tearing down the
>>>> Connections,
>>>> tearing down the DataSource is pretty much negligible. And you  
>>>> want to
>>>> tear
>>>> down the Connection -- you said you'd prefer not to maintain the  
>>>> overhead
>>>> of
>>>> several unused pools (that would be the fastest approach, but  
>>>> would use a
>>>> bit more memory and network resources). Alternatively you could  
>>>> keep
>>>> several
>>>> DataSources open, and just set minPoolSize=1, letting the pool  
>>>> grow when
>>>> you
>>>> shift from one DB to the next.
>>>>
>>>> But my guess is the simplest solution, tear down and recreate,  
>>>> will be
>>>> best
>>>> unless you are switching databases with great frequency. If  
>>>> minPoolSize
>>>> isn't huge and you don't switch more often than say once in 10  
>>>> mins, I
>>>> think
>>>> the benefits of simplicity are likely to overwhelm any small  
>>>> gains in
>>>> efficiency. (If you are switching frequently, don't softReset()  
>>>> either,
>>>> cuz
>>>> you'll incur the overhead of all the Cxn destruction and  
>>>> recreation. If
>>>> you
>>>> need to shift constantly, then you do need to keep a set of  
>>>> DataSources
>>>> live
>>>> and active.)
>>>>
>>>>      smiles,
>>>>         Steve
>>>>
>>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Crystal Reports - New Free Runtime and 30 Day Trial
>>> Check out the new simplified licensing option that enables unlimited
>>> royalty-free distribution of the report engine for externally facing
>>> server and web deployment.
>>> http://p.sf.net/sfu/businessobjects
>>> _______________________________________________
>>> c3p0-users mailing list
>>> c3p0-users@...
>>> https://lists.sourceforge.net/lists/listinfo/c3p0-users
>>
>> ~oo~
>> Steve Waldman
>> swaldman@...
>>
>>
>>
>>
>
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> c3p0-users mailing list
> c3p0-users@...
> https://lists.sourceforge.net/lists/listinfo/c3p0-users

~oo~
Steve Waldman
swaldman@...




------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
c3p0-users mailing list
c3p0-users@...
https://lists.sourceforge.net/lists/listinfo/c3p0-users