[
https://issues.apache.org/jira/browse/OPENEJB-2133?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Antonio Dias updated OPENEJB-2133:
----------------------------------
Description:
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).
{code}
if (transaction == null) {
if (delegate == null) {
newConnection();
}
return invoke(method, delegate, args);
}
{code}
If the dabase is down this means I get an exception when closing the connection
and not when getting it from the pool.
was:
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.
> 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).
> {code}
> if (transaction == null) {
> if (delegate == null) {
> newConnection();
> }
> return invoke(method, delegate, args);
> }
> {code}
> If the dabase is down this means I get an exception when closing the
> connection and not when getting it from the pool.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)