psUpdateMessage = conn.prepareStatement(getSQLStatement("UPDATE_MESSAGE_CHANNELCOUNT"));
psUpdateMessage = conn.prepareStatement(getSQLStatement("DEC_CHANNELCOUNT"));
   protected void handleBeforeRollback(List refsToAdd, Transaction tx) throws Exception   {      //remove refs marked with +      //and update rows marked with - to C                  PreparedStatement psDeleteMessage = null;      PreparedStatement psUpdateMessage = null;      Connection conn = null;      TransactionWrapper wrap = new TransactionWrapper();            List refs = new ArrayList(refsToAdd.size());            Iterator iter = refsToAdd.iterator();            while (iter.hasNext())      {         ChannelRefPair pair = (ChannelRefPair)iter.next();         refs.add(pair.ref);      }            orderReferences(refs);            List removesToReverse = new ArrayList();            try      {         this.getLocks(refs);                  conn = ds.getConnection();                  rollbackPreparedTransaction(tx, conn);                  iter = refsToAdd.iterator();                  boolean batch = usingBatchUpdates && refsToAdd.size() > 1;         boolean messageDeletionsInBatch = false;         boolean messageUpdatesInBatch = false;         if (batch)         {            psDeleteMessage = conn.prepareStatement(getSQLStatement("DELETE_MESSAGE"));            psUpdateMessage = conn.prepareStatement(getSQLStatement("UPDATE_MESSAGE_CHANNELCOUNT"));         }                                          while (iter.hasNext())         {            ChannelRefPair pair = (ChannelRefPair) iter.next();                        if (!batch)            {               psDeleteMessage = conn.prepareStatement(getSQLStatement("DELETE_MESSAGE"));               psUpdateMessage = conn.prepareStatement(getSQLStatement("UPDATE_MESSAGE_CHANNELCOUNT"));            }                        Message m = pair.ref.getMessage();                                                     //We may need to remove the message for messages added during the prepare stage                                    m.decPersistentChannelCount();            removesToReverse.add(pair.ref);                        boolean removed;            if (m.getPersistentChannelCount() == 0)            {               //remove message               removeMessage(m, psDeleteMessage);                              removed = true;                                }            else            {               //update message channel count               updateMessageChannelCount(m, psUpdateMessage);                              removed = false;            }                                          if (batch)            {               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 (batch)         {            if (messageDeletionsInBatch)            {               int[] rows = psDeleteMessage.executeBatch();                              if (trace)               {                  logBatchUpdate(getSQLStatement("DELETE_MESSAGE"), rows, "deleted");               }                              psDeleteMessage.close();               psDeleteMessage = null;            }            if (messageUpdatesInBatch)            {               int[] rows = psUpdateMessage.executeBatch();                              if (trace)               {                  logBatchUpdate(getSQLStatement("UPDATE_MESSAGE_CHANNELCOUNT"), rows, "updated");               }                              psUpdateMessage.close();               psUpdateMessage = null;            }         }      }      catch (Exception e)      {         wrap.exceptionOccurred();         throw e;      }      finally      {         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 e)            {            }         }         try         {            wrap.end();         }         finally         {            if (wrap.isFailed())            {               //reverse any removes               this.incPersistentCounts(removesToReverse);            }            //release locks            this.releaseLocks(refs);         }      }         }