[dbcp] invalidation failure?!

2005-04-12 Thread Meikel Bisping
Hi,

I just realized that invalidation can fail if connection.close is
called afterwards.

e.g.

 String pooldrv=jdbc:apache:commons:dbcp:mypool;
PoolingDriver driver = (PoolingDriver) DriverManager
.getDriver(pooldrv);

 Connection con=DriverManager.getConnection(pooldrv);
try{
   //something goes wrong with con
 //in my case an sql script creates some temporary tables and
//something might go wrong in the middle of the scipt.
//The validation mechanism can't test if there are temp. tables
//left over, so principally the connection still works, but it's
//ruined for my sql scripts because some temp tables already exist
//Informix doesn't support create or replace temp table
 }
catch
{
driver.getConnectionPool(poolname).invalidateObject(con);
}
con.close();

The particular connection is put pack into the pool and reused,
inspite of the fact that it has been invalidated before.
I realized that I could solve my problem by moving the con.close()
into the try-block, but shouldn't closing invalidated connections
still keep them invalidated?

Regards,

Meikel Bisping





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[dbcp] invalidating Connection - fine

2005-01-31 Thread Meikel Bisping
Your patch is more elegant and works just fine

Thanks Dirk.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[dbcp] invalidating Connection - fine

2005-01-31 Thread Meikel Bisping
Your patch is more elegant and works just fine

Thanks Dirk.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[dbcp] patch suggestion for invalidate Connection

2005-01-27 Thread Meikel Bisping
I had some problems with the invalidateObject function and suggest a
patch.

When I use
PoolingDriver driver = (PoolingDriver)
DriverManager.getDriver(jdbc:apache:commons:dbcp:);
driver.getConnectionPool(mypool).invalidateObject(con);

The connection isn't really closed because internally
PoolableConnectionFactory.destroyObject only closes
PoolableConnections.
The connection I got, however, is a
PoolDriver.PoolGuardConnectionWrapper which extends
DelegatingConnection (but not PoolableConnection).

You can test this with code like this:

String poolname=example;
int maxConn=10;
Connection
con=DriverManager.getConnection(jdbc:apache:commons:dbcp:   +
poolname);
  Statement stm=con.createStatement();
stm.execute(create temp table tmp_dummy(col1 integer));
stm.close();
System.out.println( con :+con);
//something goes wrong so we have to invalidate the Connection

 PoolingDriver driver = (PoolingDriver) DriverManager
.getDriver(jdbc:apache:commons:dbcp:);
   driver.getConnectionPool(poolname).invalidateObject(con);

for(int i=0;imaxConn;i++)
{
   Connection
con2=DriverManager.getConnection(jdbc:apache:commons:dbcp:   +
poolname);
  System.out.println(trying con +i+ :+con2);
Statement stm2=con2.createStatement();
stm2.execute(create temp table tmp_dummy(col1 integer));
stm2.close();
}

The invalidated connection wasn't really closed and a validation
query might still work. The problem becomes clear when the temp table
already exists.

By adding the following patch to
PoolableConnectionFactory I got invalidateObject to work properly.

   public void destroyObject(Object obj) throws Exception {
if(obj instanceof PoolableConnection) {
((PoolableConnection)obj).reallyClose();
}
//begin patch invalidateConnections
 else
if (obj instanceof DelegatingConnection)
{
DelegatingConnection con=(DelegatingConnection)obj;
boolean
rememberState=PoolingDriver.isAccessToUnderlyingConnectionAllowed();
PoolingDriver.setAccessToUnderlyingConnectionAllowed(true);
 if (con.getDelegate()!=nullcon.getDelegate() instanceof
PoolableConnection)
 {
((PoolableConnection)con.getDelegate()).reallyClose();
 }

PoolingDriver.setAccessToUnderlyingConnectionAllowed(rememberState);
}
//end patch invalidateConnections
}

Regards,

Meikel Bisping


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[DBCP] request for improved Exception nesting in ConnectionPool

2005-01-26 Thread Meikel Bisping
Hi,

I tried to establish a ConnectionPool with DBCP to an Informix
Database using your examples.
I always got the exeception pool exhausted when trying to open the
first connection.
I eventually found out during debugging that the problem was an older
Informix driver (that is generally still in use, though).
It didn't support read-only mode and threw an SQLException even when
calling setReadOnly(false).
It would be helpful for users if in cases like that the actual
exception would be thrown, pool exhausted didn't help much.

Cheers,

Meikel Bisping


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]