cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject svn commit: r1345262 - in /cxf/branches/2.5.x-fixes: ./ rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
Date Fri, 01 Jun 2012 16:01:18 GMT
Author: ay
Date: Fri Jun  1 16:01:17 2012
New Revision: 1345262

URL: http://svn.apache.org/viewvc?rev=1345262&view=rev
Log:
Merged revisions 1345232 via  svn merge from
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1345232 | ay | 2012-06-01 17:21:38 +0200 (Fri, 01 Jun 2012) | 1 line
  
  [CXF-4354] RMTxStore should explicitly close ResultSets objects
........

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java

Propchange: cxf/branches/2.5.x-fixes/
            ('svn:mergeinfo' removed)

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java?rev=1345262&r1=1345261&r2=1345262&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/persistence/jdbc/RMTxStore.java
Fri Jun  1 16:01:17 2012
@@ -293,10 +293,11 @@ public class RMTxStore implements RMStor
         if (LOG.isLoggable(Level.FINE)) {
             LOG.info("Getting destination sequence for id: " + sid);
         }
+        ResultSet res = null;
         try {
             synchronized (selectDestSequenceStmt) {
                 selectDestSequenceStmt.setString(1, sid.getValue());
-                ResultSet res = selectDestSequenceStmt.executeQuery();
+                res = selectDestSequenceStmt.executeQuery();
             
                 if (res.next()) {
                     EndpointReferenceType acksTo = RMUtils.createReference(res.getString(1));
 
@@ -312,6 +313,14 @@ public class RMTxStore implements RMStor
             }
         } catch (SQLException ex) {
             LOG.log(Level.WARNING, new Message("SELECT_DEST_SEQ_FAILED_MSG", LOG).toString(),
ex);
+        } finally {
+            if (res != null) {
+                try {
+                    res.close();
+                } catch (SQLException e) {
+                    // ignore
+                }
+            }
         }
         return null;
     }
@@ -320,10 +329,11 @@ public class RMTxStore implements RMStor
         if (LOG.isLoggable(Level.FINE)) {
             LOG.info("Getting source sequences for id: " + sid);
         }
+        ResultSet res = null;
         try {
             synchronized (selectSrcSequenceStmt) {
                 selectSrcSequenceStmt.setString(1, sid.getValue());
-                ResultSet res = selectSrcSequenceStmt.executeQuery();
+                res = selectSrcSequenceStmt.executeQuery();
             
                 if (res.next()) {
                     long cmn = res.getLong(1);
@@ -342,7 +352,15 @@ public class RMTxStore implements RMStor
         } catch (SQLException ex) {
             // ignore
             LOG.log(Level.WARNING, new Message("SELECT_SRC_SEQ_FAILED_MSG", LOG).toString(),
ex);
-        }
+        } finally {
+            if (res != null) {
+                try {
+                    res.close();
+                } catch (SQLException e) {
+                    // ignore
+                }
+            }
+        } 
         return null;
     }
 
@@ -383,10 +401,11 @@ public class RMTxStore implements RMStor
             LOG.info("Getting destination sequences for endpoint: " + endpointIdentifier);
         }
         Collection<DestinationSequence> seqs = new ArrayList<DestinationSequence>();
+        ResultSet res = null;
         try {
             synchronized (selectDestSequencesStmt) {
                 selectDestSequencesStmt.setString(1, endpointIdentifier);
-                ResultSet res = selectDestSequencesStmt.executeQuery(); 
+                res = selectDestSequencesStmt.executeQuery(); 
                 while (res.next()) {
                     Identifier sid = new Identifier();                
                     sid.setValue(res.getString(1));
@@ -404,7 +423,15 @@ public class RMTxStore implements RMStor
             }
         } catch (SQLException ex) {
             LOG.log(Level.WARNING, new Message("SELECT_DEST_SEQ_FAILED_MSG", LOG).toString(),
ex);
-        }
+        } finally {
+            if (res != null) {
+                try {
+                    res.close();
+                } catch (SQLException e) {
+                    // ignore
+                }
+            }
+        } 
         return seqs;
     }
     
@@ -414,10 +441,11 @@ public class RMTxStore implements RMStor
             LOG.info("Getting source sequences for endpoint: " + endpointIdentifier);
         }
         Collection<SourceSequence> seqs = new ArrayList<SourceSequence>();
+        ResultSet res = null;
         try {
             synchronized (selectSrcSequencesStmt) {
                 selectSrcSequencesStmt.setString(1, endpointIdentifier);
-                ResultSet res = selectSrcSequencesStmt.executeQuery();
+                res = selectSrcSequencesStmt.executeQuery();
                 while (res.next()) {
                     Identifier sid = new Identifier();
                     sid.setValue(res.getString(1));
@@ -438,17 +466,26 @@ public class RMTxStore implements RMStor
         } catch (SQLException ex) {
             // ignore
             LOG.log(Level.WARNING, new Message("SELECT_SRC_SEQ_FAILED_MSG", LOG).toString(),
ex);
-        }
+        } finally {
+            if (res != null) {
+                try {
+                    res.close();
+                } catch (SQLException e) {
+                    // ignore
+                }
+            }
+        } 
         return seqs;
     }
     
     public Collection<RMMessage> getMessages(Identifier sid, boolean outbound) {
         Collection<RMMessage> msgs = new ArrayList<RMMessage>();
+        ResultSet res = null;
         try {
             PreparedStatement stmt = outbound ? selectOutboundMessagesStmt : selectInboundMessagesStmt;
             synchronized (stmt) {
                 stmt.setString(1, sid.getValue());
-                ResultSet res = stmt.executeQuery();
+                res = stmt.executeQuery();
                 while (res.next()) {
                     long mn = res.getLong(1);
                     String to = res.getString(2);
@@ -463,6 +500,14 @@ public class RMTxStore implements RMStor
         } catch (Exception ex) {
             LOG.log(Level.WARNING, new Message(outbound ? "SELECT_OUTBOUND_MSGS_FAILED_MSG"
                 : "SELECT_INBOUND_MSGS_FAILED_MSG", LOG).toString(), ex);
+        } finally {
+            if (res != null) {
+                try {
+                    res.close();
+                } catch (SQLException e) {
+                    // ignore
+                }
+            }
         }
         return msgs;
     }
@@ -581,29 +626,26 @@ public class RMTxStore implements RMStor
     
     protected void updateSourceSequence(SourceSequence seq) 
         throws SQLException {
-        if (null == updateSrcSequenceStmt) {
-            updateSrcSequenceStmt = connection.prepareStatement(UPDATE_SRC_SEQUENCE_STMT_STR);
+        synchronized (updateSrcSequenceStmt) {
+            updateSrcSequenceStmt.setLong(1, seq.getCurrentMessageNr()); 
+            updateSrcSequenceStmt.setString(2, seq.isLastMessage() ? "1" : "0"); 
+            updateSrcSequenceStmt.setString(3, seq.getIdentifier().getValue());
+            updateSrcSequenceStmt.execute();
         }
-        updateSrcSequenceStmt.setLong(1, seq.getCurrentMessageNr()); 
-        updateSrcSequenceStmt.setString(2, seq.isLastMessage() ? "1" : "0"); 
-        updateSrcSequenceStmt.setString(3, seq.getIdentifier().getValue());
-        updateSrcSequenceStmt.execute();
     }
     
     protected void updateDestinationSequence(DestinationSequence seq) 
         throws SQLException, IOException {
-        if (null == updateDestSequenceStmt) {
-            updateDestSequenceStmt = connection.prepareStatement(UPDATE_DEST_SEQUENCE_STMT_STR);
+        synchronized (updateDestSequenceStmt) {
+            long lastMessageNr = seq.getLastMessageNumber();
+            updateDestSequenceStmt.setLong(1, lastMessageNr); 
+            InputStream is = PersistenceUtils.getInstance()
+                .serialiseAcknowledgment(seq.getAcknowledgment());
+            updateDestSequenceStmt.setBinaryStream(2, is, is.available()); 
+            updateDestSequenceStmt.setString(3, seq.getIdentifier() .getValue());
+            updateDestSequenceStmt.execute();
         }
-        long lastMessageNr = seq.getLastMessageNumber();
-        updateDestSequenceStmt.setLong(1, lastMessageNr); 
-        InputStream is = PersistenceUtils.getInstance()
-            .serialiseAcknowledgment(seq.getAcknowledgment());
-        updateDestSequenceStmt.setBinaryStream(2, is, is.available()); 
-        updateDestSequenceStmt.setString(3, seq.getIdentifier() .getValue());
-        updateDestSequenceStmt.execute();
     }
-    
     protected void createTables() throws SQLException {
         
         Statement stmt = null;
@@ -616,8 +658,9 @@ public class RMTxStore implements RMStor
             } else {
                 LOG.fine("Table CXF_RM_SRC_SEQUENCES already exists.");
             }
+        } finally {
+            stmt.close();
         }
-        stmt.close();
         
         stmt = connection.createStatement();
         try {
@@ -628,8 +671,9 @@ public class RMTxStore implements RMStor
             } else {
                 LOG.fine("Table CXF_RM_DEST_SEQUENCES already exists.");
             }
+        } finally {
+            stmt.close();
         }
-        stmt.close();
         
         for (String tableName : new String[] {OUTBOUND_MSGS_TABLE_NAME, INBOUND_MSGS_TABLE_NAME})
{
             stmt = connection.createStatement();
@@ -643,8 +687,9 @@ public class RMTxStore implements RMStor
                         LOG.fine("Table " + tableName + " already exists.");
                     }
                 }
+            } finally {
+                stmt.close();
             }
-            stmt.close();
         }
     }
     
@@ -660,8 +705,9 @@ public class RMTxStore implements RMStor
                                                     schemaName));
         } catch (SQLException ex) {
             // assume it is already created or no authorization is provided (create one manually)
+        } finally {
+            stmt.close();
         }
-        stmt.close();
         stmt = connection.createStatement();
         SQLException ex0 = null;
         for (int i = 0; i < SET_SCHEMA_STMT_STRS.length; i++) {
@@ -675,9 +721,13 @@ public class RMTxStore implements RMStor
                     throw ex0;
                 }
                 // continue
+            } finally {
+                // close the statement after its last use
+                if (ex0 == null || i == SET_SCHEMA_STMT_STRS.length - 1) {
+                    stmt.close();
+                }
             }
         }
-        stmt.close();
     }
 
     private void createStatements() throws SQLException {



Mime
View raw message