Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 45192 invoked from network); 24 Jan 2008 20:20:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Jan 2008 20:20:28 -0000 Received: (qmail 55075 invoked by uid 500); 24 Jan 2008 20:20:16 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 55058 invoked by uid 500); 24 Jan 2008 20:20:16 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 55047 invoked by uid 99); 24 Jan 2008 20:20:15 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Jan 2008 12:20:15 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of hh4ross@gmail.com designates 64.233.184.231 as permitted sender) Received: from [64.233.184.231] (HELO wr-out-0506.google.com) (64.233.184.231) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Jan 2008 20:19:47 +0000 Received: by wr-out-0506.google.com with SMTP id c30so224639wra.24 for ; Thu, 24 Jan 2008 12:19:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=q/eSvM65E5XNqPw5V2lPDaGrUfV1J/wV3v/MmMqUJF4=; b=omHkSusDTJbfmoiYgp/fsHPqjrqvvYbUY8EDR00hV/euuAAOfg6zZbDBJ+o8VyvM2CcJzbS5pWJEehvcBdv4Y8sBmcklu7PVYpJWaoH8dWzwTIowk5Te+8XWmTI9UJiO/jOXB8eZNtNX+rpHVQY9B+DhjuNHAGo2Hz/B9lJsHw4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=JUv2ACcT/bRhQkRRLk8ZethVvEfPopRi8ikUT3XXz6m+VOpfZQkgWXwV6Pzz+1Keh92z/5+iW2z+UHpyeb7p1I0NzTuUwJJW+Amqwsd1etOYvrHFUo4sF8unhu+bV1lYnAc70nucf4WUpcOnSAMc24/q7yJUjgoHRPScDaVR+E8= Received: by 10.142.77.11 with SMTP id z11mr716734wfa.23.1201205991341; Thu, 24 Jan 2008 12:19:51 -0800 (PST) Received: by 10.142.143.11 with HTTP; Thu, 24 Jan 2008 12:19:51 -0800 (PST) Message-ID: Date: Thu, 24 Jan 2008 15:19:51 -0500 From: "Hugh Ross" To: user-java@ibatis.apache.org Subject: Re: How get DB2Connection object from SqlMapClient? In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_28397_24005920.1201205991327" References: X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_28397_24005920.1201205991327 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Unfortunately, the InvocationHandler for SimplePooledConnection is a private nested class. Yes, we can set properties at the DataSource level, but we want to change it at run time based on the data access "service" being invoked (e.g., for finer-grain performance reporting). On 1/24/08, Jeff Butler wrote: > > I see. Then you'll need to do the "isProxy" method and check for > SimplePooledConnection as the invocation handler. Then you can call the > getRealConnection() method - which may return a further proxied object if > logging is enabled. Proxy upon proxy - it can get complex to unwind these > things. > > I have to wonder - is this really necessary? You can probably set the > value you mentioned as a driver property and not have to write all this > untangling code. > > Jeff Butler > > > > > On Jan 24, 2008 12:33 PM, Hugh Ross wrote: > > > In my debugger, it looks like my Proxy is > > actually SimpleDataSource-related, not logging. And, SimpleDataSource seems > > to have a method to unrwrapConnection(). Still digging... > > > > > > On 1/24/08, Jeff Butler wrote: > > > > > > I just checked SVN and that method was indeed added in 2.3. I'll add > > > that information to the WIKI page. > > > > > > There's no other way to the underlying Connection object unless you > > > disable logging in all circumstances, or you write some custom reflection > > > code that gives you access to the private field. Upgrading to 2.3 is > > > much easier (I would say that 2.3 is quite stable - it's been out over > > > a year). > > > > > > Jeff Butler > > > > > > > > > On Jan 24, 2008 11:56 AM, Hugh Ross wrote: > > > > > > > > > > > Thanks, Jeff. I'm not finding a getConnection method in the > > > > ConnectionLogProxy class. Is that because I'm using iBATIS 2.2.0? > > > > If so, is there another way to get the underlying Connection object? > > > > > > > > > > > > On 1/24/08, Jeff Butler wrote: > > > > > > > > > > This comes up a lot! I just added a WIKI page describing the > > > > > process: > > > > > > > > > > http://opensource.atlassian.com/confluence/oss/pages/viewpage.action?pageId=15597591 > > > > > > > > > > > > > > > Jeff Butler > > > > > > > > > > > > > > > > > > > > On Jan 24, 2008 10:03 AM, Hugh Ross wrote: > > > > > > > > > > > Can anyone provide some sample code for this? > > > > > > > > > > > > I tried, but seemed to be blocked by $proxy objects or odd > > > > > > looking com.ibm.db2.jcc.b.b objects... > > > > > > > > > > > > For example, this did not work for me: > > > > > > > > > > > > java.sql.Connection conn = > > > > > > sqlMapClient.getCurrentConnection(); > > > > > > > > > > > > if (conn instanceof com.ibm.db2.jcc.DB2Connection ) > > > > > > { > > > > > > com.ibm.db2.jcc.DB2Connection db2conn = ( > > > > > > com.ibm.db2.jcc.DB2Connection)conn; > > > > > > db2conn.setDB2ClientApplicationInformation > > > > > > ("SomethingUsefulHere"); > > > > > > } > > > > > > > > > > > > I also tried getting the DataSource 1st. > > > > > > > > > > > > Thanks! > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > ------=_Part_28397_24005920.1201205991327 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline
Unfortunately, the InvocationHandler for SimplePooledConnection is a private nested class.
 
Yes, we can set properties at the DataSource level, but we want to change it at run time based on the data access "service" being invoked (e.g., for finer-grain performance reporting).

 
On 1/24/08, Jeff Butler <jeffgbutler@gmail.com> wrote:
I see.  Then you'll need to do the "isProxy" method and check for SimplePooledConnection as the invocation handler.  Then you can call the getRealConnection() method - which may return a further proxied object if logging is enabled.  Proxy upon proxy - it can get complex to unwind these things.
 
I have to wonder - is this really necessary?  You can probably set the value you mentioned as a driver property and not have to write all this untangling code.
 
Jeff Butler
 


 
On Jan 24, 2008 12:33 PM, Hugh Ross <hh4ross@gmail.com> wrote:
In my debugger, it looks like my Proxy is actually SimpleDataSource-related, not logging.  And, SimpleDataSource seems to have a method to unrwrapConnection().  Still digging...


On 1/24/08, Jeff Butler <jeffgbutler@gmail.com > wrote:
I just checked SVN and that method was indeed added in 2.3.  I'll add that information to the WIKI page.
 
There's no other way to the underlying Connection object unless you disable logging in all circumstances, or you write some custom reflection code that gives you access to the private field.  Upgrading to 2.3 is much easier (I would say that 2.3 is quite stable - it's been out over a year).
 
Jeff Butler

 
On Jan 24, 2008 11:56 AM, Hugh Ross <hh4ross@gmail.com> wrote:
 
Thanks, Jeff.  I'm not finding a getConnection method in the ConnectionLogProxy class.  Is that because I'm using iBATIS 2.2.0?  If so, is there another way to get the underlying Connection object?

 
On 1/24/08, Jeff Butler <jeffgbutler@gmail.com > wrote:
This comes up a lot!  I just added a WIKI page describing the process:
 
 
Jeff Butler


 
On Jan 24, 2008 10:03 AM, Hugh Ross <hh4ross@gmail.com> wrote:

Can anyone provide some sample code for this? 

I tried, but seemed to be blocked by $proxy objects or odd looking com.ibm.db2.jcc.b.b objects...

For example, this did not work for me:

        java.sql.Connection conn = sqlMapClient.getCurrentConnection();
       
        if (conn instanceof com.ibm.db2.jcc.DB2Connection )
        {
            com.ibm.db2.jcc.DB2Connection db2conn = (com.ibm.db2.jcc.DB2Connection)conn;
            db2conn.setDB2ClientApplicationInformation("SomethingUsefulHere");
        }

I also tried getting the DataSource 1st.

Thanks!



 


 


------=_Part_28397_24005920.1201205991327--