ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject Statements being closed when they shouldn't be
Date Fri, 27 Oct 2006 18:08:43 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.2963" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=618143117-27102006><FONT size=2>Hi Clinton,</FONT></SPAN></DIV>
<DIV><SPAN class=618143117-27102006><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 class=618143117-27102006><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=618143117-27102006><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 class=618143117-27102006><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 class=618143117-27102006><FONT size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=618143117-27102006><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 class=618143117-27102006>
<P><B><FONT color=#7f0055><FONT size=2>return</FONT></B></FONT><FONT
size=2> 
method.invoke(<FONT color=#0000c0>statement</FONT>, params);</FONT></P>
<P><SPAN class=618143117-27102006><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 class=618143117-27102006><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</B></FONT><FONT 
size=2>.isAssignableFrom(params[0].getClass()). </FONT></FONT></FONT></SPAN></P>
<P><SPAN class=618143117-27102006><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. 
</P></FONT></FONT></FONT></FONT></SPAN>
<P><SPAN class=618143117-27102006><FONT size=2>Should I open an JIRA on

this?</FONT></SPAN></P></DIV></SPAN>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV align=left><FONT size=2>Chris Mathrusse</FONT></DIV>
<DIV align=left><FONT size=2><A 
href="mailto:christopher.mathrusse@sybase.com">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></BODY></HTML>


Mime
View raw message