Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5E9E2CE37 for ; Fri, 1 Jun 2012 16:01:40 +0000 (UTC) Received: (qmail 56466 invoked by uid 500); 1 Jun 2012 16:01:40 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 56427 invoked by uid 500); 1 Jun 2012 16:01:40 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 56420 invoked by uid 99); 1 Jun 2012 16:01:40 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jun 2012 16:01:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Jun 2012 16:01:38 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7164A2388847; Fri, 1 Jun 2012 16:01:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: ay@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120601160118.7164A2388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 seqs = new ArrayList(); + 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 seqs = new ArrayList(); + 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 getMessages(Identifier sid, boolean outbound) { Collection msgs = new ArrayList(); + 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 {