Antonio Dias created OPENEJB-2133:
-------------------------------------

             Summary: Closing connection returned from ManagedDataSource 
creantes new connection
                 Key: OPENEJB-2133
                 URL: https://issues.apache.org/jira/browse/OPENEJB-2133
             Project: OpenEJB
          Issue Type: Bug
            Reporter: Antonio Dias
            Priority: Minor


I'm doing a small component to health check a Datasource registered in Tomee. I 
was expecting that when you get a connection if the database was unavailable it 
would throw a SqlException. Of cource with database pooling things are not so 
'easy', so let's ignore that.
The issue I found is that when you call getConnection in a ManagedDataSource it 
always created a new ManagedConnection passing a delegate. 
{code}
 private Connection managed(final String u, final String p) {
        return (Connection) 
Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), 
CONNECTION_CLASS,
                new ManagedConnection(delegate, transactionManager, registry, 
u, p));
    }

{code}
This delegate (DataSource) is then used to create a Key. This DataSource is not 
assigned to the ManagedConnection delegate field in the ctor, so when invoking 
the "close" method, without executing any other statement after getting the 
connection, the ManagedConnection has to first create one connection to then 
close it. (line 101). 
If the dabase is down this meas i get an exceptionwhen closing the connection 
and not when getting it from the pool.





--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to