db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattba...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/util/sequence SequenceManagerMySQLImpl.java
Date Sun, 02 Feb 2003 03:40:30 GMT
mattbaird    2003/02/01 19:40:30

  Modified:    src/java/org/apache/ojb/broker/util/sequence
                        SequenceManagerMySQLImpl.java
  Log:
  Found a leaked resource in the MySQL sequence manager, we weren't closing the statement
and the resultset. Uses the new platform-aware close method in a finally block now.
  
  Revision  Changes    Path
  1.6       +15 -7     jakarta-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerMySQLImpl.java
  
  Index: SequenceManagerMySQLImpl.java
  ===================================================================
  RCS file: /home/cvs//jakarta-ojb/src/java/org/apache/ojb/broker/util/sequence/SequenceManagerMySQLImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SequenceManagerMySQLImpl.java	22 Nov 2002 01:19:40 -0000	1.5
  +++ SequenceManagerMySQLImpl.java	2 Feb 2003 03:40:30 -0000	1.6
  @@ -16,7 +16,9 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.accesslayer.JdbcAccess;
  +import org.apache.ojb.broker.accesslayer.ResultSetAndStatement;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
  @@ -108,17 +110,18 @@
       {
   
           FieldDescriptor fd = cld.getAutoIncrementField();
  -        if(fd != null){ // an autoinc column exists
  +        if(fd != null)
  +		{ // an autoinc column exists
  +			ResultSetAndStatement rsStmt = null;
               try
               {
  -                ResultSet rs = dbAccess.executeSQL("SELECT LAST_INSERT_ID() as newid FROM
" + cld.getFullTableName(), cld).m_rs;
  +				rsStmt = dbAccess.executeSQL("SELECT LAST_INSERT_ID() as newid FROM " + cld.getFullTableName(),
cld, Query.NOT_SCROLLABLE);
                   int newid = 0;
  -                if (rs.next())
  +                if (rsStmt.m_rs.next())
                   {
  -                    newid = rs.getInt("newid");
  -
  +                    newid = rsStmt.m_rs.getInt("newid");
                   }
  -                rs.close();
  +                rsStmt.m_rs.close();
                   if(log.isDebugEnabled()) log.debug("After store - newid=" + newid);
   
                   PersistentField pf = fd.getPersistentField();
  @@ -126,11 +129,16 @@
               }
               catch (PersistenceBrokerException e)
               {
  +				throw new SequenceManagerException(e);
               }
               catch (SQLException e)
               {
                   throw new SequenceManagerException(e);
               }
  +			finally
  +			{
  +				rsStmt.close();
  +			}
           }
   
       }
  
  
  

Mime
View raw message