You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ma...@apache.org on 2010/06/15 17:03:13 UTC
svn commit: r954925 -
/qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java
Author: marnie
Date: Tue Jun 15 15:03:12 2010
New Revision: 954925
URL: http://svn.apache.org/viewvc?rev=954925&view=rev
Log:
QPID-2664 More fixes for database resource clean up in exception path
Modified:
qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java
Modified: qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java
URL: http://svn.apache.org/viewvc/qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java?rev=954925&r1=954924&r2=954925&view=diff
==============================================================================
--- qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java (original)
+++ qpid/branches/0.5.x-dev/qpid/java/broker/src/main/java/org/apache/qpid/server/store/DerbyMessageStore.java Tue Jun 15 15:03:12 2010
@@ -629,49 +629,52 @@ public class DerbyMessageStore extends A
{
if (_state != State.RECOVERING)
{
+ Connection conn = null;
+ PreparedStatement stmt = null;
+
try
{
- Connection conn = null;
- PreparedStatement stmt = null;
-
- try
- {
- conn = newConnection();
-
- stmt = conn.prepareStatement(FIND_EXCHANGE);
- stmt.setString(1, exchange.getName().toString());
+ conn = newConnection();
- ResultSet rs = stmt.executeQuery();
+ stmt = conn.prepareStatement(FIND_EXCHANGE);
+ stmt.setString(1, exchange.getName().toString());
- // If we don't have any data in the result set then we can add this exchange
- if (!rs.next())
- {
- stmt = conn.prepareStatement(INSERT_INTO_EXCHANGE);
- stmt.setString(1, exchange.getName().toString());
- stmt.setString(2, exchange.getType().toString());
- stmt.setShort(3, exchange.isAutoDelete() ? (short) 1 : (short) 0);
- stmt.execute();
- stmt.close();
- conn.commit();
- }
+ ResultSet rs = stmt.executeQuery();
+ // If we don't have any data in the result set then we can add this exchange
+ if (!rs.next())
+ {
+ stmt = conn.prepareStatement(INSERT_INTO_EXCHANGE);
+ stmt.setString(1, exchange.getName().toString());
+ stmt.setString(2, exchange.getType().toString());
+ stmt.setShort(3, exchange.isAutoDelete() ? (short) 1 : (short) 0);
+ stmt.execute();
+ stmt.close();
+ conn.commit();
}
- finally
+ }
+ catch (SQLException e)
+ {
+ throw new AMQException("Error writing Exchange with name " + exchange.getName() + " to database: " + e, e);
+ }
+ finally
+ {
+ try
{
if (stmt != null)
{
- stmt.close();
+ stmt.close();
}
- if(conn != null)
+ if (conn != null)
{
- conn.close();
+ conn.close();
}
}
- }
- catch (SQLException e)
- {
- throw new AMQException("Error writing Exchange with name " + exchange.getName() + " to database: " + e, e);
+ catch(SQLException e)
+ {
+ throw new AMQException("Error closing database resources:" + e);
+ }
}
}
@@ -680,11 +683,11 @@ public class DerbyMessageStore extends A
public void removeExchange(Exchange exchange) throws AMQException
{
Connection conn = null;
-
+ PreparedStatement stmt = null;
try
{
conn = newConnection();
- PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_EXCHANGE);
+ stmt = conn.prepareStatement(DELETE_FROM_EXCHANGE);
stmt.setString(1, exchange.getName().toString());
int results = stmt.executeUpdate();
if(results == 0)
@@ -703,19 +706,24 @@ public class DerbyMessageStore extends A
}
finally
{
- if(conn != null)
+ try
{
- try
- {
- conn.close();
- }
- catch (SQLException e)
- {
- throw new AMQException("Error closing database resources:" + e);
- }
- }
+ if (stmt != null)
+ {
+ stmt.close();
+ }
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ catch(SQLException e)
+ {
+ throw new AMQException("Error closing database resources:" + e);
+ }
}
+
}
public void bindQueue(Exchange exchange, AMQShortString routingKey, AMQQueue queue, FieldTable args)
@@ -920,12 +928,12 @@ public class DerbyMessageStore extends A
AMQShortString name = queue.getName();
_logger.debug("public void removeQueue(AMQShortString name = " + name + "): called");
Connection conn = null;
-
+ PreparedStatement stmt = null;
try
{
conn = newConnection();
- PreparedStatement stmt = conn.prepareStatement(DELETE_FROM_QUEUE);
+ stmt = conn.prepareStatement(DELETE_FROM_QUEUE);
stmt.setString(1, name.toString());
int results = stmt.executeUpdate();
@@ -944,21 +952,23 @@ public class DerbyMessageStore extends A
}
finally
{
- if(conn != null)
+ try
{
- try
- {
- conn.close();
- }
- catch (SQLException e)
- {
- _logger.error(e);
- }
- }
+ if (stmt != null)
+ {
+ stmt.close();
+ }
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new AMQException("Error closing database resources:" + e);
+ }
}
-
-
}
public void enqueueMessage(StoreContext context, final AMQQueue queue, Long messageId) throws AMQException
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org