SimpleDataSource.unwrapConnection a.k.a. What am I missing?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

SimpleDataSource.unwrapConnection a.k.a. What am I missing?

Rick.Wellman

The short, quick question here is: 

Does anyone have an example where they have successfully used this method to get to the “real connection”?

 

The background/research is:

* My understanding of the use of java.lang.Proxy is realistically zero.

* FWIW, upgrading to myBatis 3.x is unfeasible at this time.

* I was originally trying this method with version 2.3.0.677. 

* After “brief” internet research, I upgraded to 2.3.4.726; assume that version for the rest of this question:

 

When using SimpleDataSource.getConnection() it seems that the proxy is *always* returned.

 

Since the proxy is always returned, use of this implementation of unwrapConnection will *always* return the proxy, and *never* the underlying real connection:

public static Connection unwrapConnection(Connection conn) {

    if (conn instanceof SimplePooledConnection) {

      return ((SimplePooledConnection) conn).getRealConnection();

    } else {

      return conn;

    }

  }

 

Stated maybe one more alternate way, there seems to be no way to get a reference to the actual SimplePooledConnection so that unwrapConnection() will work.  Maybe the proxy object has a way of letting me do this?

 

Reply | Threaded
Open this post in threaded view
|

RE: SimpleDataSource.unwrapConnection a.k.a. What am I missing?

Rick.Wellman

Hmmmm, I’ll assume from the deafening silence that not many have tread this path (or have with the same results).  Back to the drawing board

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Rick.Wellman
Sent: Thursday, September 09, 2010 4:17 PM
To: [hidden email]
Subject: SimpleDataSource.unwrapConnection a.k.a. What am I missing?

 

The short, quick question here is: 

Does anyone have an example where they have successfully used this method to get to the “real connection”?

 

The background/research is:

* My understanding of the use of java.lang.Proxy is realistically zero.

* FWIW, upgrading to myBatis 3.x is unfeasible at this time.

* I was originally trying this method with version 2.3.0.677. 

* After “brief” internet research, I upgraded to 2.3.4.726; assume that version for the rest of this question:

 

When using SimpleDataSource.getConnection() it seems that the proxy is *always* returned.

 

Since the proxy is always returned, use of this implementation of unwrapConnection will *always* return the proxy, and *never* the underlying real connection:

public static Connection unwrapConnection(Connection conn) {

    if (conn instanceof SimplePooledConnection) {

      return ((SimplePooledConnection) conn).getRealConnection();

    } else {

      return conn;

    }

  }

 

Stated maybe one more alternate way, there seems to be no way to get a reference to the actual SimplePooledConnection so that unwrapConnection() will work.  Maybe the proxy object has a way of letting me do this?

 

Reply | Threaded
Open this post in threaded view
|

Re: SimpleDataSource.unwrapConnection a.k.a. What am I missing?

Clinton Begin
Administrator
You might want to give messages more than a few business hours... :-)


If you have logging enabled in MyBatis, you might be getting the logging proxy.  Try disabling logging, and have a look at what the actual type is being returned. 

Cheers,
Clinton

On Fri, Sep 10, 2010 at 9:50 AM, Rick.Wellman <[hidden email]> wrote:

Hmmmm, I’ll assume from the deafening silence that not many have tread this path (or have with the same results).  Back to the drawing board

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Rick.Wellman
Sent: Thursday, September 09, 2010 4:17 PM
To: [hidden email]
Subject: SimpleDataSource.unwrapConnection a.k.a. What am I missing?

 

The short, quick question here is: 

Does anyone have an example where they have successfully used this method to get to the “real connection”?

 

The background/research is:

* My understanding of the use of java.lang.Proxy is realistically zero.

* FWIW, upgrading to myBatis 3.x is unfeasible at this time.

* I was originally trying this method with version 2.3.0.677. 

* After “brief” internet research, I upgraded to 2.3.4.726; assume that version for the rest of this question:

 

When using SimpleDataSource.getConnection() it seems that the proxy is *always* returned.

 

Since the proxy is always returned, use of this implementation of unwrapConnection will *always* return the proxy, and *never* the underlying real connection:

public static Connection unwrapConnection(Connection conn) {

    if (conn instanceof SimplePooledConnection) {

      return ((SimplePooledConnection) conn).getRealConnection();

    } else {

      return conn;

    }

  }

 

Stated maybe one more alternate way, there seems to be no way to get a reference to the actual SimplePooledConnection so that unwrapConnection() will work.  Maybe the proxy object has a way of letting me do this?

 


Reply | Threaded
Open this post in threaded view
|

RE: SimpleDataSource.unwrapConnection a.k.a. What am I missing?

Rick.Wellman

You might want to give messages more than a few business hours... :-)

>> Point well taken.  There was just some “chatter” on other subjects while this one sat lonely in the corner. ;-)

 

If you have logging enabled in MyBatis, you might be getting the logging proxy.  Try disabling logging, and have a look at what the actual type is being returned. 

>> I will try that but am fairly certain (through use of the debugger) that I am getting the proxy class defined in SimplePooledConnection.  Looking at the source code, it is unclear how a different proxy could be returned but maybe that’s through an architecture mechanism of iBatis that I am not familiar with.  Thanks for your suggestion and help.  FWIW, this is ‘high priority’ to help me isolate a bug in my own code/architecture that is adversely affecting our user base but, due to other work commitments, I will not be getting back to this for a few days. 

 

p.s.  Also, in case it might jog some ideas… my underlying problem is that sometimes my connection object is going “invalid” (which I’m trying to figure out why).  So, I’m trying to at least detect that via isValid() but can’t because of the proxy object.  I just include this for background info. in the odd chance that it might actually give someone a clue.

 

Respectfully,

Rick Wellman

Reply | Threaded
Open this post in threaded view
|

Re: SimpleDataSource.unwrapConnection a.k.a. What am I missing?

Clinton Begin
Administrator
There's no magic to it.  It keeps a reference to the original connection passed in.  It's only set in one place and getRealConnection() returns that value.  

If it's a bug, you should be able to reproduce it with an HSQLDB unit test and submit it when you return to this issue.  

Cheers,
Clinton

On Fri, Sep 10, 2010 at 10:19 AM, Rick.Wellman <[hidden email]> wrote:

You might want to give messages more than a few business hours... :-)

>> Point well taken.  There was just some “chatter” on other subjects while this one sat lonely in the corner. ;-)

 

If you have logging enabled in MyBatis, you might be getting the logging proxy.  Try disabling logging, and have a look at what the actual type is being returned. 

>> I will try that but am fairly certain (through use of the debugger) that I am getting the proxy class defined in SimplePooledConnection.  Looking at the source code, it is unclear how a different proxy could be returned but maybe that’s through an architecture mechanism of iBatis that I am not familiar with.  Thanks for your suggestion and help.  FWIW, this is ‘high priority’ to help me isolate a bug in my own code/architecture that is adversely affecting our user base but, due to other work commitments, I will not be getting back to this for a few days. 

 

p.s.  Also, in case it might jog some ideas… my underlying problem is that sometimes my connection object is going “invalid” (which I’m trying to figure out why).  So, I’m trying to at least detect that via isValid() but can’t because of the proxy object.  I just include this for background info. in the odd chance that it might actually give someone a clue.

 

Respectfully,

Rick Wellman