You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Mike Starkie <sk...@yahoo.com> on 2005/03/13 20:59:40 UTC

Re: GenericKeyedObjectPoolFactory - failover question

this makes sense now.  thank you.

If I want to create a system where my java code can
failover to a redundant database on connection errors
do I need to set up two distinct PoolingDataSources
and  
logically switch between them when an connection error
occurs or is there some built in classes which handle
failovers of this type?


--- Vikram Goyal <te...@craftbits.com> wrote:

> Hi Mike,
> 
> Yes, it can seem very confusing to use these
> libraries.
> 
> The best way for me to explain it would be with some
> code snippet.
> 
> // create your connection pool
> GenericObjectPool pool = new GenericObjectPool();
> 
> // and set its properties
> // ..
> 
> // then your connection factory
> ConnectionFactory cf = new
> DriverManagerConnectionFactory(.....);
> 
> // then a factory for your prepared statements
> KeyedObjectPoolFactory kpf = new
> GenericKeyedObjectPoolFactory(null, 8);
> 
> // finally, your overall connection factory
> PoolableConnectionFactory pcf = new
> PoolableConnectionFactory(cf, pool, kpf, 
> null, false, true);
> 
> This poolable connection factory will now be set to
> pool connections and 
> prepared statements around those connections. The
> key here is to understand 
> that in this case, you don't use the
> PoolingConnection class directly, but 
> let the PoolableConnectionFactory to manage it
> internally (It uses 
> PoolingConnection internally to pool prepared
> statements around connections, 
> using the kpf; so you don't need to match
> connections with statements and so 
> on). I perhaps misled you initially when I said that
> you can use 
> PoolingConnection, but at that point I did not know
> your exact requirements.
> 
> I hope this clears it up more.
> 
> Vikram
>
---------------------------------------------------------------------------------------
> Jakarta Commons Online Bookshelf
> Module 9: Pool and DBCP:
> http://www.manning.com/catalog/view.php?book=goyal9
> All Modules: http://www.manning.com/goyal
>
---------------------------------------------------------------------------------------
> 
> ----- Original Message ----- 
> From: "Mike Starbuck" <sk...@yahoo.com>
> To: "Jakarta Commons Users List"
> <co...@jakarta.apache.org>
> Sent: Sunday, March 13, 2005 8:09 AM
> Subject: Re: GenericKeyedObjectPoolFactory
> 
> 
> > Vikram,
> > I'm confused. I want to create a pool of
> connections
> > and for each connection, pool the statements used
> on
> > the connection.
> >
> > The problem is the PoolableConnectionFactory will
> only
> > create a PoolingConnection if it was initialized
> with
> > an implementation of keyedObjectPoolFactory
> otherwise
> > it will just return the connection created by the
> > ConnectionFactory it was initialized with. In my
> case
> > that is a DriverManagerConnectionFactory.
> >
> > The most basic implementation of
> > keyedObjectPoolFactory is
> > GenericKeyedObjectPoolFactory which requires an
> > instance of KeyedPoolableObjectFactory.  There are
> no
> > concrete implementations of
> KeyedPoolableObjectFactory
> > in commons-pool and the only other suitable
> > implementation seems to be PoolingConnection in
> > commons-dbcp.  But that implementation requires a
> > Connection in order to initialize!
> >
> > It seems to me like a chicken and egg problem:  In
> > order to create the factory to make connections
> that
> > pool statements I need to specify the factory that
> I
> > want to pool the statements but the only
> > implementation available requires a connection.
> >
> > This is my second day with this package so please
> feel
> > free to fill me in on the right way to set this
> up.
> >
> > thank you,
> >
> >
> > --- Vikram Goyal <te...@craftbits.com> wrote:
> >> Hi Mike,
> >>
> >> You need to use the PoolingConnection class. It
> >> implements
> >> KeyedPoolableObjectFactory. For some reason, the
> >> Javadocs for
> >> KeyedPoolableObjectFactory don't reflect this.
> >>
> >> HTH,
> >> Vikram
> >>
> >>
> >
>
---------------------------------------------------------------------------------------
> >> Jakarta Commons Online Bookshelf
> >> Module 9: Pool and DBCP:
> >>
> http://www.manning.com/catalog/view.php?book=goyal9
> >> All Modules: http://www.manning.com/goyal
> >>
> >
>
---------------------------------------------------------------------------------------
> >>
> >> ----- Original Message ----- 
> >> From: "Mike Starbuck" <sk...@yahoo.com>
> >> To: <co...@jakarta.apache.org>
> >> Sent: Saturday, March 12, 2005 9:08 AM
> >> Subject: GenericKeyedObjectPoolFactory
> >>
> >>
> >> > Is there a way to create an instance of
> >> > GenericKeyedObjectPoolFactory using an
> >> implementation
> >> > of BasekeyedPoolableObjectFactory.   I can't
> find
> >> a
> >> > concrete  class that impelments
> >> > KeyedPoolableObjectFactory in the
> commons-pool-1.2
> >> package.
> >> >
> >> > -- 
> >> >
> >> > The information contained in this email along
> with
> >> all attachments is
> >> > confidential and is not to be shared without my
> >> permission and prior
> >> > knowledge of who will be viewing it's contents
> >> including all attachments.
> >> >
> >> >
> __________________________________________________
> >> > Do You Yahoo!?
> >> > Tired of spam?  Yahoo! Mail has the best spam
> >> protection around
> >> > http://mail.yahoo.com
> >> >
> >> >
> >>
> >
>
---------------------------------------------------------------------
> >> > To unsubscribe, e-mail:
> >> commons-user-unsubscribe@jakarta.apache.org
> >> > For additional commands, e-mail:
> >> commons-user-help@jakarta.apache.org
> >> >
> >> >
> >> >
> >> >
> >>
> >>
> >>
> >>
> >
>
---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> >> commons-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail:
> >> commons-user-help@jakarta.apache.org
> >>
> >>
> >
> > -- 
> >
> > The information contained in this email along with
> all attachments is 
> > confidential and is not to be shared without my
> permission and prior 
> > knowledge of who will be viewing it's contents
> including all attachments.
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around
> > http://mail.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> >
> >
> >
> > 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-user-help@jakarta.apache.org
> 
> 


-- 

The information contained in this email along with all attachments is confidential and is not to be shared without my permission and prior knowledge of who will be viewing it's contents including all attachments.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org