Bugs item #796585, was opened at 2003-08-28 02:42
Message generated for change (Comment added) made by starksm
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=796585&group_id=22866

Category: JBossServer
Group: v4.0
>Status: Closed
Resolution: None
Priority: 5
Submitted By: Craig Munday (cmunday)
Assigned to: Nobody/Anonymous (nobody)
Summary: PreparedStatement leak in HiLoKeyGenerator.java

Initial Comment:
Hi,

There is a Statement that does not get closed and is 
left to be finialized within the following method (included 
below) from the HiLoKeyGenerator class.

The statement create by:
stmt = con.prepareStatement(nextKeyQuery);

leaks because the variable "stmt" is re-assigned with:
stmt = con.prepareStatement(updateStmt);

This second statement is closed within the finally clause 
but the first one is never closed and should be

Cheers,
Craig.

 

public synchronized Object generateKey()
   {
      if(lo < hi)
        return new Integer(lo++);

      Connection con = null;
      PreparedStatement stmt = null;
      ResultSet rs = null;
      Transaction currentTx = null;
      try
      {
         currentTx = tm.suspend();
         tm.begin();

         con = datasource.getConnection();
         int rowsUpdated;
         do
         {
            if(isDebugEnabled) log.debug("Executing SQL: " 
+ nextKeyQuery);
            stmt = con.prepareStatement(nextKeyQuery);
            rs = stmt.executeQuery();
            if(!rs.next())
               throw new Exception("Couldn't read next key: 
ResultSet is empty.");

            lo = rs.getInt(1);
            hi = lo + blockSize;

            if(isDebugEnabled)
               log.debug("Executing SQL: " + updateStmt 
+ " [p1=" + hi + ",p2=" + lo + "]");
            stmt = con.prepareStatement(updateStmt);
            stmt.setInt(1, hi);
            stmt.setInt(2, lo);
            rowsUpdated = stmt.executeUpdate();
         }
         while(rowsUpdated == 0);

         tm.commit();
      }
      catch(Exception e)
      {
         log.error("Error fetching next key:", e);
         try
         {
            tm.rollback();
         }
         catch(SystemException se)
         {
            log.error("Couldn't rollback transaction: ", se);
         }
      }
      finally
      {
         JDBCUtil.safeClose(rs);
         JDBCUtil.safeClose(stmt);
         JDBCUtil.safeClose(con);

         if(currentTx != null)
         {
            try
            {
               tm.resume(currentTx);
            }
            catch(InvalidTransactionException ite)
            {
               log.error("Invalid transaction: ", ite);
            }
            catch(SystemException se)
            {
               log.error("Unexpected error: ", se);
            }
         }
      }
      return new Integer(lo++);
   }



----------------------------------------------------------------------

Comment By: Scott M Stark (starksm)
Date: 2004-12-29 12:51

Message:
Logged In: YES 
user_id=175228

All issues have been moved to http://jira.jboss.com. Existing
issues have been moved. New issues will be closed with this
canned reponse.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=796585&group_id=22866


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
JBoss-Development mailing list
JBoss-Development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to