removed = false; }  if (usingBatchUpdates) { if (removed)
if (trace)
   public void removeReferences(long channelID, List references) throws Exception   {      if (trace) { log.trace(this + " Removing " + references.size() + " refs from channel " + channelID); }            Connection conn = null;      PreparedStatement psDeleteReference = null;        PreparedStatement psDeleteMessage = null;      PreparedStatement psUpdateMessage = null;      TransactionWrapper wrap = new TransactionWrapper();            try      {         conn = ds.getConnection();                  Iterator iter = references.iterator();                  boolean messageDeletionsInBatch = false;         boolean messageUpdatesInBatch = false;                  if (usingBatchUpdates)         {            psDeleteReference = conn.prepareStatement(deleteMessageRef);            psDeleteMessage = conn.prepareStatement(deleteMessage);            psUpdateMessage = conn.prepareStatement(updateMessageChannelCount);         }                  while (iter.hasNext())         {            MessageReference ref = (MessageReference) iter.next();                                                                         if (!usingBatchUpdates)            {               psDeleteReference = conn.prepareStatement(deleteMessageRef);            }                        removeReference(channelID, ref, psDeleteReference);                        if (usingBatchUpdates)            {               psDeleteReference.addBatch();            }            else            {               int rows = psDeleteReference.executeUpdate();                              if (trace)               {                  log.trace("Deleted " + rows + " rows");               }                              psDeleteReference.close();               psDeleteReference = null;            }                        if (!usingBatchUpdates)            {               psDeleteMessage = conn.prepareStatement(deleteMessage);               psUpdateMessage = conn.prepareStatement(updateMessageChannelCount);            }                           Message m = ref.getMessage();                                    synchronized (m)            {                                    m.decPersistentChannelCount();                                                            //Maybe we need to delete the message itself                 boolean removed;               if (m.getPersistentChannelCount() == 0)               {                  //No more refs so remove the message                  removeMessage(m, psDeleteMessage);                                    removed = true;               }               else               {                  //Update the message with the new channel count                  updateMessageChannelCount(m, psUpdateMessage);                                    removed = false;               }                              if (usingBatchUpdates)               {                  if (removed)                  {                     psDeleteMessage.addBatch();                     messageDeletionsInBatch = true;                  }                  else                  {                     psUpdateMessage.addBatch();                     messageUpdatesInBatch = true;                  }               }               else               {                  if (removed)                  {                     int rows = psDeleteMessage.executeUpdate();                                          if (trace)                     {                        log.trace("Deleted " + rows + " rows");                     }                  }                  else                  {                     int rows = psUpdateMessage.executeUpdate();                                          if (trace)                     {                        log.trace("Updated " + rows + " rows");                     }                  }                  psDeleteMessage.close();                  psDeleteMessage = null;                  psUpdateMessage.close();                  psUpdateMessage = null;               }                  }         }                  if (usingBatchUpdates)         {            int[] rowsReference = psDeleteReference.executeBatch();                        if (trace)            {               logBatchUpdate(deleteMessageRef, rowsReference, "deleted");            }                        if (messageDeletionsInBatch)            {               int[] rowsMessage = psDeleteMessage.executeBatch();                              if (trace)               {                  logBatchUpdate(deleteMessage, rowsMessage, "deleted");               }            }            if (messageUpdatesInBatch)            {               int[] rowsMessage = psUpdateMessage.executeBatch();                              if (trace)               {                  logBatchUpdate(updateMessageChannelCount, rowsMessage, "updated");               }            }                        psDeleteReference.close();            psDeleteReference = null;            psDeleteMessage.close();            psDeleteMessage = null;            psUpdateMessage.close();            psUpdateMessage = null;         }      }      catch (Exception e)      {         wrap.exceptionOccurred();         throw e;      }      finally      {         if (psDeleteReference != null)         {            try            {               psDeleteReference.close();            }            catch (Throwable t)            {            }         }         if (psDeleteMessage != null)         {            try            {               psDeleteMessage.close();            }            catch (Throwable t)            {            }         }         if (psUpdateMessage != null)         {            try            {               psUpdateMessage.close();            }            catch (Throwable t)            {            }         }         if (conn != null)         {            try            {               conn.close();            }            catch (Throwable t)            {            }         }         wrap.end();      }         }