You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Bryan Field-Elliot <br...@netmeme.org> on 2002/06/09 06:39:06 UTC

DBCP validation query: how to use?

I'm using the latest DBCP release to create a Datasource as follows,
against a PostgreSQL database:

			Class.forName("org.postgresql.Driver");
			ObjectPool connectionPool = new GenericObjectPool(null);
			ConnectionFactory connectionFactory = new
DriverManagerConnectionFactory("jdbc:postgresql://localhost/mydb",
"bryan", "nopw");
			String validationQuery = "select 1 as test";
			PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory, connectionPool, null,
validationQuery, false, true);
			dataSource = new PoolingDataSource(connectionPool);

I'm chasing down a different bug which is hosing my postgres connections
- trying to insert strings into TEXT fields, which contain nulls.
Evidently Postgres doesn't like that, and hoses the connection.

But, according to how I've initialized the pool (above), should DBCP be
testing my connections with my validation query, noticing my hosed
connections, and creating new ones for me? Observed behavior indicates
otherwise... It keeps resuing the hosed connection to future calls of
dataSource.getConnection(), throwing off future executing code.

Am I doing something wrong?

Thank you,
Bryan



Re: DBCP validation query: how to use?

Posted by Bryan Field-Elliot <br...@netmeme.org>.
That's the missing link, thank you! On my GenericObjectPool I have to
call setTestOnBorrow(true) right after creating it.

I assumed (obviously incorrectly) that if my PoolableConnectionFactory
had a validationQuery, then it would complete the plumbing in the other
parts of the system as necessary to make it work. But evidently not.
This was tricky and should be documented better.

Thank you!

Bryan

On Sun, 2002-06-09 at 08:12, Juozas Baliuka wrote:

    It is code in GenericObjectPool. "_testOnBorrow"  must be set to true.
    Sorry, but I dont know how to set it in DBCP, I believe somebody more
    competent will respond to your message.
    ..........................
    if( _testOnBorrow && !_factory.validateObject(pair.value)) {
                    try {
                        _factory.passivateObject(pair.value);
                    } catch(Exception e) {
                        ; // ignored, we're throwing it out anyway
                    }
                    _factory.destroyObject(pair.value);
                } else {
    .............................................



Re: [betwixt] beanutils dependency and other stuff

Posted by Martin van den Bemt <ml...@mvdb.net>.
A patch is still coming.. Now finishing up the testcases for it and you
will receive the patches soon. It will fix a lot of issues I had/found
in betwixt (not necessarily bugs btw..)

Mvgr,
Martin

On Sun, 2002-06-09 at 23:29, robert burrell donkin wrote:
> hi james
> 
> the new mavenized build is very cool.
> 
> at the moment we're listed as depending on a nightly build for beanutils. 
> any objections if i see if we can replace this with the latest beanutils 
> release?
> 
> i should have time this week to look at adding some more documentation etc.
>   but i'll probably wait until betwixt has been promoted. is this still 
> happening tomorrow?
> 
> - robert
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [betwixt] beanutils dependency and other stuff

Posted by James Strachan <ja...@yahoo.co.uk>.
From: "robert burrell donkin" <ro...@mac.com>
> hi james
>
> the new mavenized build is very cool.
>
> at the moment we're listed as depending on a nightly build for beanutils.
> any objections if i see if we can replace this with the latest beanutils
> release?

I can't remember if it'll work or not.

> i should have time this week to look at adding some more documentation
etc.
>   but i'll probably wait until betwixt has been promoted. is this still
> happening tomorrow?

Yes. I'll move betwixt and cli over to commons proper at 6pm GMT, unless
anyone hollas before then.

James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


[betwixt] beanutils dependency and other stuff

Posted by robert burrell donkin <ro...@mac.com>.
hi james

the new mavenized build is very cool.

at the moment we're listed as depending on a nightly build for beanutils. 
any objections if i see if we can replace this with the latest beanutils 
release?

i should have time this week to look at adding some more documentation etc.
  but i'll probably wait until betwixt has been promoted. is this still 
happening tomorrow?

- robert


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DBCP validation query: how to use?

Posted by Juozas Baliuka <ba...@centras.lt>.
It is code in GenericObjectPool. "_testOnBorrow"  must be set to true.
Sorry, but I dont know how to set it in DBCP, I believe somebody more
competent will respond to your message.
..........................
if( _testOnBorrow && !_factory.validateObject(pair.value)) {
                try {
                    _factory.passivateObject(pair.value);
                } catch(Exception e) {
                    ; // ignored, we're throwing it out anyway
                }
                _factory.destroyObject(pair.value);
            } else {
.............................................

> Thanks,
>
> Actually the problem is in my code, there should not be any nulls at all
> in the String I'm trying to insert. It's supposed to be a normal
> human-readable string.
>
> But talking about DBCP again -- how do I enable "ping" in configuration
> of DBCP?
>
> I'm looking at the source code for DBCP, and the "validateObject" method
> in PoolableConnectionFactory is where the test occurs (on your
> validation query). But either the code doesn't work, or validateObject
> is never called in the first place.
>
> Again, help would be appreciated!
>
> Bryan
>
> On Sun, 2002-06-09 at 01:34, Juozas Baliuka wrote:
>
>     Hi,
>      I think you need to enable "ping" in configuration.
>     But you can solve this in postgres :
>     1. use BYTEA type for bynary strings.
>     2. check the last driver version, I am not sure it is fixed in the
last
>     versoin, but it
>     is no problems to fix it, driver is open source. Current "STABLE"
version
>     has this bug.
>     Escape table you can find in user's guide.
>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: DBCP validation query: how to use?

Posted by Bryan Field-Elliot <br...@netmeme.org>.
Thanks,

Actually the problem is in my code, there should not be any nulls at all
in the String I'm trying to insert. It's supposed to be a normal
human-readable string.

But talking about DBCP again -- how do I enable "ping" in configuration
of DBCP?

I'm looking at the source code for DBCP, and the "validateObject" method
in PoolableConnectionFactory is where the test occurs (on your
validation query). But either the code doesn't work, or validateObject
is never called in the first place. 

Again, help would be appreciated!

Bryan

On Sun, 2002-06-09 at 01:34, Juozas Baliuka wrote:

    Hi,
     I think you need to enable "ping" in configuration.
    But you can solve this in postgres :
    1. use BYTEA type for bynary strings.
    2. check the last driver version, I am not sure it is fixed in the last
    versoin, but it
    is no problems to fix it, driver is open source. Current "STABLE" version
    has this bug.
    Escape table you can find in user's guide.



Re: DBCP validation query: how to use?

Posted by Juozas Baliuka <ba...@centras.lt>.
Hi,
 I think you need to enable "ping" in configuration.
But you can solve this in postgres :
1. use BYTEA type for bynary strings.
2. check the last driver version, I am not sure it is fixed in the last
versoin, but it
is no problems to fix it, driver is open source. Current "STABLE" version
has this bug.
Escape table you can find in user's guide.


> I'm using the latest DBCP release to create a Datasource as follows,
> against a PostgreSQL database:
>
> Class.forName("org.postgresql.Driver");
> ObjectPool connectionPool = new GenericObjectPool(null);
> ConnectionFactory connectionFactory = new
> DriverManagerConnectionFactory("jdbc:postgresql://localhost/mydb",
> "bryan", "nopw");
> String validationQuery = "select 1 as test";
> PoolableConnectionFactory poolableConnectionFactory = new
> PoolableConnectionFactory(connectionFactory, connectionPool, null,
> validationQuery, false, true);
> dataSource = new PoolingDataSource(connectionPool);
>
> I'm chasing down a different bug which is hosing my postgres connections
> - trying to insert strings into TEXT fields, which contain nulls.
> Evidently Postgres doesn't like that, and hoses the connection.
>
> But, according to how I've initialized the pool (above), should DBCP be
> testing my connections with my validation query, noticing my hosed
> connections, and creating new ones for me? Observed behavior indicates
> otherwise... It keeps resuing the hosed connection to future calls of
> dataSource.getConnection(), throwing off future executing code.
>
> Am I doing something wrong?
>
> Thank you,
> Bryan
>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>