[PATCH] Fixed open cursor leaks in Oracle by closing all ResultSets and PreparedStatements

Michael Jaszczyk <[email protected]>
Newsgroups gmane.comp.java.openjms.devel
Message-ID <[email protected]>
-- 
PIRONET NDH
Michael Jaszczyk - Director Software
Maarweg 149 - 161, 50825 Cologne - Germany 
Phone: +49 (0)221 770 1720 - Fax: +49 (0)221 770 1005 
<mailto:[email protected]> - <http://www.pironet-ndh.com/>
MessageHandles.patch (text/plain, 4.2 KB)
Index: MessageHandles.java
===================================================================
RCS file: /cvsroot/openjms/openjms/src/main/org/exolab/jms/persistence/MessageHandles.java,v
retrieving revision 1.29
diff -u -w -i -b -r1.29 MessageHandles.java
--- MessageHandles.java	28 Oct 2003 05:10:50 -0000	1.29
+++ MessageHandles.java	5 Jan 2004 08:59:18 -0000
@@ -305,6 +305,7 @@
 
         PreparedStatement delete = null;
         PreparedStatement select = null;
+		ResultSet rs = null;
 
         try {
             // first check to see that the consumer exists and only
@@ -348,7 +349,7 @@
                 // then delete the corresponding message from the message table
                 select = connection.prepareStatement(GET_MSG_HANDLE_COUNT);
                 select.setString(1, id);
-                ResultSet rs = select.executeQuery();
+                rs = select.executeQuery();
                 if (rs.next() && (rs.getInt(1) == 0)) {
                     delete.close();
                     delete = connection.prepareStatement(DELETE_MESSAGE);
@@ -365,13 +366,13 @@
                     }
                 }
 
-                // close the result set
-                SQLHelper.close(rs);
+            
             }
         } catch (SQLException exception) {
             throw new PersistenceException("Failed to remove message handle=" +
                 handle, exception);
         } finally {
+			SQLHelper.close(rs);
             SQLHelper.close(delete);
             SQLHelper.close(select);
         }
@@ -521,6 +522,7 @@
 
         Vector result = new Vector();
         PreparedStatement select = null;
+		ResultSet set = null;
 
         // if the consumer and/or destination cannot be mapped then
         // return an empty vector
@@ -539,7 +541,7 @@
 
             // iterate through the result set and construct the corresponding
             // PersistentMessageHandles
-            ResultSet set = select.executeQuery();
+            set = select.executeQuery();
             while (set.next()) {
                 // Attempt to retrieve the corresponding destination
                 JmsDestination dest = Destinations.instance().get(
@@ -570,12 +572,13 @@
                 result.add(handle);
             }
 
-            SQLHelper.close(set);
+            
         } catch (SQLException exception) {
             throw new PersistenceException(
                 "Failed to get message handles for destination=" +
                 destination + ", consumer=" + name, exception);
         } finally {
+			SQLHelper.close(set);
             SQLHelper.close(select);
         }
 
@@ -597,6 +600,7 @@
 
         Vector result = new Vector();
         PreparedStatement select = null;
+		ResultSet set = null;
 
         try {
             select = connection.prepareStatement(GET_MESSAGE_HANDLES_IN_RANGE);
@@ -605,16 +609,17 @@
 
             // iterate through the result set and construct the corresponding
             // PersistentMessageHandles
-            ResultSet set = select.executeQuery();
+            set = select.executeQuery();
             while (set.next()) {
                 result.add(set.getString(1));
             }
 
-            SQLHelper.close(set);
+           
         } catch (SQLException exception) {
             throw new PersistenceException("Failed to retrieve message ids",
                 exception);
         } finally {
+			SQLHelper.close(set);
             SQLHelper.close(select);
         }
 
@@ -635,21 +640,23 @@
 
         boolean result = false;
         PreparedStatement select = null;
+		ResultSet set = null;
 
         try {
             select = connection.prepareStatement(GET_MESSAGE_HANDLE_WITH_ID);
             select.setLong(1, messageId);
-            ResultSet set = select.executeQuery();
+            set = select.executeQuery();
 
             if (set.next()) {
                 result = true;
             }
-            SQLHelper.close(set);
+            
         } catch (SQLException exception) {
             throw new PersistenceException(
                 "Failed to determine if message exists, id=" + messageId,
                 exception);
         } finally {
+			SQLHelper.close(set);
             SQLHelper.close(select);
         }
         return result;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.