ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject RE: Statements being closed when they shouldn't be
Date Sun, 29 Oct 2006 05:43:36 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META boundary="----=_Part_92295_14336152.1162097605371" alternative; multipart 
Content-Type:>
<META http-equiv=Content-Type content="text/html; charset=us-ascii" 
Content-Type: ------="_Part_92295_14336152.1162097605371" inline 
Content-Disposition: html; text 7bit Content-Transfer-Encoding:>
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=903344205-29102006><FONT color=#0000ff

size=2>Fabulous! Then I won't bother opening a JIRA. Thanks for the prompt 
response to this one Clinton. It's greatly appreciated. I'll sync in the morning 
and rebuild.</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> "Clinton Begin" 
&lt;clinton.begin@gmail.com&gt; [mailto:"Clinton Begin" 
&lt;clinton.begin@gmail.com&gt;] <BR><B>Sent:</B> Saturday, October
28, 2006 
9:53 PM<BR><B>To:</B> user-java@ibatis.apache.org<BR><B>Subject:</B>
Re: 
Statements being closed when they shouldn't be<BR></FONT><BR></DIV>
<DIV></DIV>Just an FYI:&nbsp; This does NOT affect 2.2.0.&nbsp; The 
"hasPreparedStatement" code was added since then as part of the 
PreparedStatement caching.&nbsp; So I believe this is exactly the same issue 
Jeff posted a while back.&nbsp; <BR><BR>I've fixed the problem and I'll be

committing it within minutes.<BR><BR>Clinton<BR><BR>
<DIV><SPAN class=gmail_quote>On 10/27/06, <B class=gmail_sendername>Clinton

Begin</B> &lt;<A onclick="return top.js.OpenExtLink(window,event,this)" 
href="mailto:clinton.begin@gmail.com" target=_blank> 
clinton.begin@gmail.com</A>&gt; wrote:</SPAN> 
<BLOCKQUOTE class=gmail_quote 
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid"><BR>Thanks

  for all the debugging efforts. With this information, it should be a snap to 
  fix.&nbsp; 
  <DIV><SPAN><BR><BR>Cheers,<BR>Clinton<BR><BR>
  <DIV><SPAN class=gmail_quote>On 10/27/06, <B class=gmail_sendername><A

  onclick="return top.js.OpenExtLink(window,event,this)" 
  href="mailto:Christopher.Mathrusse@sybase.com" 
  target=_blank>Christopher.Mathrusse@sybase.com</A></B> &lt;<A 
  onclick="return top.js.OpenExtLink(window,event,this)" 
  href="mailto:Christopher.Mathrusse@sybase.com" 
  target=_blank>Christopher.Mathrusse@sybase.com</A>&gt; wrote:</SPAN>

  <BLOCKQUOTE class=gmail_quote 
  style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
    <DIV>
    <DIV dir=ltr align=left><SPAN><FONT color=#0000ff size=2>Yes, if I disable

    logging all together the error does not occur. I'm guessing that this is 
    something that you have seen before.</FONT></SPAN></DIV><BR>
    <DIV lang=en-us dir=ltr align=left>
    <HR>
    <FONT face=Tahoma size=2><B>From:</B> "Jeff Butler" &lt;<A 
    onclick="return top.js.OpenExtLink(window,event,this)" 
    href="mailto:jeffgbutler@gmail.com" 
    target=_blank>jeffgbutler@gmail.com</A>&gt; [mailto:"Jeff Butler" &lt;<A

    onclick="return top.js.OpenExtLink(window,event,this)" 
    href="mailto:jeffgbutler@gmail.com" 
    target=_blank>jeffgbutler@gmail.com</A>&gt;] <BR><B>Sent:</B>
Friday, 
    October 27, 2006 12:40 PM<BR><B>To:</B> <A 
    onclick="return top.js.OpenExtLink(window,event,this)" 
    href="mailto:user-java@ibatis.apache.org" 
    target=_blank>user-java@ibatis.apache.org</A><BR><B>Subject:</B>
Re: 
    Statements being closed when they shouldn't be<BR></FONT><BR></DIV>
    <DIV><SPAN>
    <DIV></DIV>
    <DIV>Maybe.</DIV>
    <DIV>&nbsp;</DIV>
    <DIV>Chris - can you verify whether the behavior changes if you disable 
    logging?</DIV>
    <DIV>&nbsp;</DIV>
    <DIV>Also, you can disable caching completely by altering the methods 
    in&nbsp;com.ibatis.sqlmap.engine.scope.SessionScope to always return 
    false.</DIV>
    <DIV>&nbsp;</DIV>
    <DIV>Jeff Butler</DIV>
    <DIV><BR>&nbsp;</DIV>
    <DIV><SPAN class=gmail_quote>On 10/27/06, <B class=gmail_sendername>Clinton

    Begin</B> &lt;<A onclick="return top.js.OpenExtLink(window,event,this)" 
    href="mailto:clinton.begin@gmail.com" 
    target=_blank>clinton.begin@gmail.com</A>&gt; wrote:</SPAN> 
    <BLOCKQUOTE class=gmail_quote 
    style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px
solid">Yeah, 
      let's open a JIRA issue....<BR><BR>JEFF:&nbsp; Could this be the same

      problem with the prepared statement caching when logging is enabled? 
      <BR><BR>Cheers,<BR><SPAN>Clinton</SPAN> 
      <DIV><SPAN><BR><BR>
      <DIV><SPAN class=gmail_quote>On 10/27/06, <B class=gmail_sendername><A

      onclick="return top.js.OpenExtLink(window,event,this)" 
      href="mailto:Christopher.Mathrusse@sybase.com" 
      target=_blank>Christopher.Mathrusse@sybase.com </A></B>&lt;<A

      onclick="return top.js.OpenExtLink(window,event,this)" 
      href="mailto:Christopher.Mathrusse@sybase.com" 
      target=_blank>Christopher.Mathrusse@sybase.com</A>&gt; wrote:</SPAN>

      <BLOCKQUOTE class=gmail_quote 
      style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px
solid">
        <DIV>
        <DIV><SPAN><FONT size=2>Hi Clinton,</FONT></SPAN></DIV>
        <DIV><SPAN><FONT size=2>I've run into a bit of a snag in the SqlExecutor

        class, closeStatement method. (Line 501) It seems that this class caches 
        statements within the session object. In the closeStatement method there 
        is an evaluation: </FONT></SPAN></DIV>
        <DIV><SPAN><FONT size=2></FONT></SPAN>&nbsp;</DIV>
        <DIV><SPAN><FONT size=2>&nbsp;&nbsp;&nbsp; if 
        (!session.hasPreparedStatement(ps)) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        if (ps != null) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
try 
        {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        ps.close();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
} catch 
        (SQLException e) 
        {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// 
        ignore<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

        }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <BR>&nbsp;&nbsp;&nbsp;

        }<BR></FONT></SPAN></DIV>
        <DIV><SPAN><FONT size=2>The problem that I'm seeing is that the

        PreparedStatement is being closed every time. This is due to the fact 
        that the actual PreparedStatement is wrapped within a <FONT 
        size=2>PreparedStatementLogProxy object. When the evaluation is made 
        above, session.hasPreparedStatement(ps), the session is asking the 
        preparedStatements HashMap if it contains a value, namely the 
        PreparedStatementLogProxy. When the map iterates through the objects it 
        contains the equals() method is invoked on each object. This is where 
        the problem lies. </FONT></FONT></SPAN></DIV>
        <DIV><SPAN><FONT size=2></FONT></SPAN>&nbsp;</DIV>
        <DIV><SPAN><FONT size=2>Invoking equals() causes the invoke method
of 
        the <FONT size=2>PreparedStatementLogProxy to intercept the call. 
        Evaluations are made within this method until the following method is 
        invoked, allowing the underlying equals method on the PreparedStatement 
        to be invoked. </FONT></FONT></SPAN></DIV>
        <DIV><SPAN>
        <P><B><FONT color=#7f0055><FONT size=2>return</FONT></FONT></B><FONT

        size=2> method.invoke(<FONT color=#0000c0>statement</FONT>, 
        params);</FONT></P>
        <P><SPAN><FONT size=2>The problem here is that the actual 
        PreparedStatement is being passed in for comparison with an instance of 
        PreparedStatementLogProxy. This always results in evaluating to false. 
        Even if you were to compare an instance of the Proxy with itself, 
        ps.equals(ps), the result will be false. I verified this by setting a 
        breakpoint in the SqlExecutor class and ran this evaluation which 
        resulted in false. </FONT></SPAN></P>
        <P><SPAN><FONT size=2>I don't have a solution to this unfortunately.
I 
        first thought a simple comparison of the parameter object being an 
        instanceof <FONT size=2>PreparedStatementLogProxy, but that also returns 
        false, as does <FONT size=2>PreparedStatementLogProxy.</FONT><B><FONT

        color=#7f0055 size=2>class</FONT></B></FONT><FONT 
        size=2>.isAssignableFrom(params[0].getClass()). 
</FONT></FONT></SPAN></P>
        <P><SPAN><FONT size=2><FONT size=2><FONT size=2>My problem
is that the 
        Statements are always being close when they should not be and this is 
        resulting in errors being raised from the JDBC layer because the 
        Statement is being closed more than once. This is because when 
        SqlMapSessionImpl.close() is called the delegate, <FONT 
        size=2>SqlMapExecutorDelegate pushSession method is called. In here 
        session.reset() is called which closes any PreparedStatements that it 
        contains. Effectively closing the PreparedStatement twice. 
        </FONT></FONT></FONT></FONT></SPAN></P></SPAN>
        <P><SPAN><FONT size=2>Should I open an JIRA on 
        this?</FONT></SPAN></P></DIV>
        <DIV><FONT size=2></FONT>&nbsp;</DIV>
        <DIV align=left><FONT size=2>Chris Mathrusse</FONT></DIV>
        <DIV align=left><FONT size=2><A 
        onclick="return top.js.OpenExtLink(window,event,this)" 
        href="mailto:christopher.mathrusse@sybase.com" 
        target=_blank>christopher.mathrusse@sybase.com</A></FONT></DIV>
        <DIV align=left><FONT size=2>(925) 236-5553</FONT></DIV>
        <DIV><FONT size=2></FONT><FONT 
      size=2></FONT>&nbsp;</DIV></DIV></BLOCKQUOTE></DIV><BR></SPAN></DIV></BLOCKQUOTE></DIV><BR></SPAN></DIV></DIV></BLOCKQUOTE></DIV><BR></SPAN></DIV></BLOCKQUOTE></DIV><BR></BODY></HTML>


Mime
View raw message